Repository: TheOdinProject/odin-bot-v2
Pull request #104 (2021-02-04 15:59:54)

Add /debug command
<!-- 
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:

Add `/debug` command and fix one import error in `mockData.test.js`


#### 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. 

![Screenshot_2021-02-04_21 28 55](https://user-images.githubusercontent.com/54525741/106919284-041c8080-6730-11eb-985d-92acb57aa135.png)

#### 3. If this PR is related to an open issue please reference it with the `#` operator and the issue number below:

#69 



Patch:
diff --git a/botCommands/debug.js b/botCommands/debug.js
new file mode 100644
index 0000000..6a305ea
--- /dev/null
+++ b/botCommands/debug.js
@@ -0,0 +1,11 @@
+const { registerBotCommand } = require("../botEngine.js");
+
+const command = {
+  regex: /(?<!\S)\/debug(?!\S)/,
+  cb: () =>
+    `Looks like this problem can be solved using a debugger: <https://developers.google.com/web/tools/chrome-devtools/javascript>`,
+};
+
+registerBotCommand(command.regex, command.cb);
+
+module.exports = command;


Test patch:
diff --git a/botCommands/__snapshots__/debug.test.js.snap b/botCommands/__snapshots__/debug.test.js.snap
new file mode 100644
index 0000000..22c2a00
--- /dev/null
+++ b/botCommands/__snapshots__/debug.test.js.snap
@@ -0,0 +1,3 @@
+// Jest Snapshot v1, https://goo.gl/fbAQLP
+
+exports[`/debug callback should return the correct output 1`] = `"Looks like this problem can be solved using a debugger: <https://developers.google.com/web/tools/chrome-devtools/javascript>"`;
diff --git a/botCommands/debug.test.js b/botCommands/debug.test.js
new file mode 100644
index 0000000..d4b9af5
--- /dev/null
+++ b/botCommands/debug.test.js
@@ -0,0 +1,60 @@
+const command = require("./debug");
+
+describe("/debug", () => {
+  it.each([
+    ["/debug"],
+    [" /debug"],
+    ["/debug @odin-bot"],
+    [" /debug @odin-bot"],
+  ])("'%s' triggers the callback", (string) => {
+    expect(command.regex.test(string)).toBeTruthy();
+  });
+
+  it.each([
+    ["/debog"],
+    ["debugs"],
+    ["/dbug"],
+    ["/de bug"],
+    ["/debugging"],
+    ['```function("/de bug", () => {}```'],
+    ["/Debug"],
+    [""],
+    [" "],
+    ["/ "],
+    ["@odin-bot / debug"],
+    ["/de&b^ug"],
+    ["/d^bug"],
+    ["@odin-bot/ debug"],
+  ])("'%s' does not trigger the callback", (string) => {
+    expect(command.regex.test(string)).toBeFalsy();
+  });
+
+  it.each([
+    ["how about a flavour of /debug"],
+    ["i think /debug is great"],
+    ["hey @odin-bot, teach me to /debug"],
+    ["/@odin-bot ^ /me /debug /test$*"],
+  ])("'%s' - the command can be anywhere in the string", (string) => {
+    expect(command.regex.test(string)).toBeTruthy();
+  });
+
+  it.each([
+    ["@user/debug"],
+    ["watchaknowabout/debug"],
+    ["/debugsgrealkdmsfalnd"],
+    ["/debug/"],
+    ["/debug*"],
+    ["/debug..."],
+  ])(
+    "'%s' - command should be its own word/group - no leading or trailing characters",
+    (string) => {
+      expect(command.regex.test(string)).toBeFalsy();
+    }
+  );
+});
+
+describe("/debug callback", () => {
+  it("should return the correct output", () => {
+    expect(command.cb()).toMatchSnapshot();
+  });
+});
diff --git a/botCommands/mockData.test.js b/botCommands/mockData.test.js
index 8252a30..4498e0a 100644
--- a/botCommands/mockData.test.js
+++ b/botCommands/mockData.test.js
@@ -1,10 +1,10 @@
-const generateMentions = require('./mockData')
+const { generateMentions } = require("./mockData");
 
-describe('Generate Mentions', ()=>{
-  it('correct number of mentions are generated', () => {  
-    expect(generateMentions(0).mentions.users.array().length).toEqual(0)
-    expect(generateMentions(1).mentions.users.array().length).toEqual(1)
-    expect(generateMentions(2).mentions.users.array().length).toEqual(2)
-    expect(generateMentions(10).mentions.users.array().length).toEqual(10)
-  })
-})
+describe("Generate Mentions", () => {
+  it("correct number of mentions are generated", () => {
+    expect(generateMentions(0).mentions.users.array().length).toEqual(0);
+    expect(generateMentions(1).mentions.users.array().length).toEqual(1);
+    expect(generateMentions(2).mentions.users.array().length).toEqual(2);
+    expect(generateMentions(10).mentions.users.array().length).toEqual(10);
+  });
+});