Repository: TheOdinProject/odin-bot-v2
Pull request #134 (2021-03-21 23:55:10)

/top bot 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:

Added /top bot command that links to www.theodinproject.com




#### 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. 

![toptest](https://user-images.githubusercontent.com/24649589/111925594-6b3e9a80-8b0e-11eb-8fd4-85f524b3c531.png)





#### 3. If this PR is related to an open issue please reference it with the `#` operator and the issue number below:

#XXXXX



Patch:
diff --git a/botCommands/top.js b/botCommands/top.js
new file mode 100644
index 0000000..bae52f7
--- /dev/null
+++ b/botCommands/top.js
@@ -0,0 +1,11 @@
+const { registerBotCommand } = require('../botEngine.js');
+
+const command = {
+  regex: /(?<!\S)\/top(?!\S)/,
+  cb: () =>
+    'The Odin Project. Your Career in Web Development Starts Here. <https://www.theodinproject.com> ',
+};
+
+registerBotCommand(command.regex, command.cb);
+
+module.exports = command;


Test patch:
diff --git a/botCommands/__snapshots__/top.test.js.snap b/botCommands/__snapshots__/top.test.js.snap
new file mode 100644
index 0000000..063adaa
--- /dev/null
+++ b/botCommands/__snapshots__/top.test.js.snap
@@ -0,0 +1,3 @@
+// Jest Snapshot v1, https://goo.gl/fbAQLP
+
+exports[`/top callback returns correct output 1`] = `"The Odin Project. Your Career in Web Development Starts Here. <https://www.theodinproject.com> "`;
diff --git a/botCommands/top.test.js b/botCommands/top.test.js
new file mode 100644
index 0000000..6727907
--- /dev/null
+++ b/botCommands/top.test.js
@@ -0,0 +1,48 @@
+const command = require('./top');
+
+describe('/top', () => {
+  describe('regex', () => {
+    it.each([['/top'], [' /top'], ['/top @odin-bot'], ['@odin-bot /top']])(
+      'correct strings trigger the callback',
+      (string) => {
+        expect(command.regex.test(string)).toBeTruthy();
+      }
+    );
+
+    it.each([['tp'], ['toop'], ['topp'], ['/ top'], ['/atop']])(
+      "'%s' does not trigger the callback",
+      (string) => {
+        expect(command.regex.test(string)).toBeFalsy();
+      }
+    );
+
+    it.each([
+      ['Check this out! /top'],
+      ["Don't worry about /top"],
+      ['Hey @odin-bot, /top'],
+      ['/@odin-bot ^ /me /top /tests$*'],
+    ])("'%s' - command can be anywhere in the string", (string) => {
+      expect(command.regex.test(string)).toBeTruthy();
+    });
+
+    it.each([
+      ['@user/top'],
+      ["it's about/top"],
+      ['/topanillusion'],
+      ['/top/'],
+      ['/top*'],
+      ['/top...'],
+    ])(
+      "'%s' - command should be its own word/group - no leading or trailing characters",
+      (string) => {
+        expect(command.regex.test(string)).toBeFalsy();
+      }
+    );
+  });
+
+  describe('callback', () => {
+    it('returns correct output', () => {
+      expect(command.cb()).toMatchSnapshot();
+    });
+  });
+});