Repository: TheOdinProject/odin-bot-v2
Pull request #129 (2021-03-17 01:21:11)

Created /xy command and complimentary test
<!-- 
Thanks for your interest in The Odin Project's Odin Bot. In order to get PRs closed in a reasonable amount of time, we request that you include a baseline of information about the changes you are proposing. Please answer the following triage questions:
-->

 - [x] You have read the [Odin Bot README/Contributing Guide](https://github.com/TheOdinProject/odin-bot-v2/blob/master/README.md).

#### 1.Describe the changes made:

I Created a /xy command and test to go with it under simpleCommands.js and simpleCommands.test.js. I already talked to @wise-king-sullyman in the discord under the bot playground text channel and he gave me the ok send my pr.


#### 2. If this PR modifies a command, please provide a screenshot of the passing tests below. NOTE: Your PR will not be merged if you have any failing test cases. 
![image](https://user-images.githubusercontent.com/56554110/111400088-fb0ebf80-869c-11eb-908b-ee070ceedb16.png)


#### 3. If this PR is related to an open issue please reference it with the `#` operator and the issue number below:

#128 



Patch:
diff --git a/botCommands/simpleCommands.js b/botCommands/simpleCommands.js
index 8658c23..ab5d818 100644
--- a/botCommands/simpleCommands.js
+++ b/botCommands/simpleCommands.js
@@ -110,6 +110,12 @@ const justDoIt = {
 };
 registerBotCommand(justDoIt.regex, justDoIt.cb);
 
+const xy = {
+  regex: /(?<!\S)\/xy(?!\S)/,
+  cb: () => 'What problem are you *really* trying to solve? Check out this article to help others better understand your question: <https://xyproblem.info/>',
+};
+registerBotCommand(xy.regex, xy.cb);
+
 module.exports = {
   hug,
   smart,
@@ -125,4 +131,5 @@ module.exports = {
   gandalf,
   motivate,
   justDoIt,
+  xy,
 };


Test patch:
diff --git a/botCommands/__snapshots__/simpleCommands.test.js.snap b/botCommands/__snapshots__/simpleCommands.test.js.snap
index 0d9b980..147d9e7 100644
--- a/botCommands/__snapshots__/simpleCommands.test.js.snap
+++ b/botCommands/__snapshots__/simpleCommands.test.js.snap
@@ -22,8 +22,10 @@ exports[`/motivate callback returns correct output 1`] = `"Don't give up! https:
 
 exports[`/peen callback returns correct output 1`] = `"https://media.giphy.com/media/K5IEMtDZHxQZy/giphy.gif"`;
 
-exports['/question callback returns correct output 1'] = '"**We\'d love to help you out! Check out this article to help others better understand your question: https://medium.com/@gordon_zhu/how-to-be-great-at-asking-questions-e37be04d0603**"';
+exports[`/question callback returns correct output 1`] = `"**We'd love to help you out! Check out this article to help others better understand your question: https://medium.com/@gordon_zhu/how-to-be-great-at-asking-questions-e37be04d0603**"`;
 
 exports[`/sexpresso callback returns correct output 1`] = `"https://tenor.com/view/mac-spilling-coffee-starbucks-gif-6241590"`;
 
 exports[`/smart callback returns correct output 1`] = `"f(ಠ‿↼)z"`;
+
+exports[`/xy callback returns correct output 1`] = `"What problem are you *really* trying to solve? Check out this article to help others better understand your question: <https://xyproblem.info/>"`;
diff --git a/botCommands/simpleCommands.test.js b/botCommands/simpleCommands.test.js
index 68f628c..a1c1900 100644
--- a/botCommands/simpleCommands.test.js
+++ b/botCommands/simpleCommands.test.js
@@ -831,3 +831,62 @@ describe('/justdoit', () => {
     });
   });
 });
+
+describe('/xy', () => {
+  describe('regex', () => {
+    it.each([
+      ['/xy'],
+      [' /xy'],
+      ['/xy @odin-bot'],
+      ['@odin-bot /xy'],
+    ])('correct strings trigger the callback', (string) => {
+      expect(commands.xy.regex.test(string)).toBeTruthy()
+    })
+    
+    it.each([
+      ['/yx'],
+      ['xy'],
+      ['/x'],
+      ['/xs'],
+      ['```function("/xy", () => {}```'],
+      ['/d'],
+      [''],
+      [' '],
+      [' /'],
+      ['@odin-bot / xy'],
+      ['/x&y'],
+      ['/x^y'],
+      ['/xy!'],
+      ['@odin-bot/ xy'],
+      ['https://xy.com'],
+    ])("'%s' does not trigger the callback", (string) => {
+      expect(commands.xy.regex.test(string)).toBeFalsy()
+    })
+
+    it.each([
+      ['Check this out! /xy'],
+      ['Don\'t worry about /xy'],
+      ['Hey @odin-bot, /xy'],
+      ['/@odin-bot ^ /me /xy /tests$*']
+    ])("'%s' - command can be anywhere in the string", (string) => {
+      expect(commands.xy.regex.test(string)).toBeTruthy()
+    })
+
+    it.each([
+      ['@user/xy'],
+      ['it\'s about/xy'],
+      ['/xyisanillusion'],
+      ['/xy/'],
+      ['/xy*'],
+      ['/xy...']
+    ])("'%s' - command should be its own word/group - no leading or trailing characters", (string) => {
+      expect(commands.xy.regex.test(string)).toBeFalsy()
+    })
+  })
+
+  describe('callback', () => {
+    it('returns correct output', () => {
+      expect(commands.xy.cb()).toMatchSnapshot()
+    })
+  })
+})