Repository: TheOdinProject/odin-bot-v2
Pull request #135 (2021-03-22 02:04:55)

add /faq command.  Includes ESLint fixes
<!-- 
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:

Adds faq.js faq.test.js and fixes linting errors in simpleCommands.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. 

![image](https://user-images.githubusercontent.com/67610130/111931304-540d9780-8a91-11eb-97f7-f543afa8efea.png)




#### 3. If this PR is related to an open issue please reference it with the `#` operator and the issue number below:

#132 #116 



Patch:
diff --git a/botCommands/faq.js b/botCommands/faq.js
new file mode 100644
index 0000000..b812260
--- /dev/null
+++ b/botCommands/faq.js
@@ -0,0 +1,33 @@
+const { registerBotCommand } = require('../botEngine.js');
+
+const command = {
+  regex: /(?<!\S)\/faq(?!\S)/,
+  cb: async ({ mentions }) => {
+    let users = '';
+    const mentionedUsers = mentions.users.array();
+    if (mentionedUsers.length >= 3) {
+      mentionedUsers.forEach((user, index) => {
+        if (index < mentionedUsers.length - 1) {
+          users += ` ${user},`;
+        } else {
+          users += ` and ${user}`;
+        }
+      });
+    } else if (mentionedUsers.length === 2) {
+      mentionedUsers.forEach((user, index) => {
+        if (index < mentionedUsers.length - 1) {
+          users += ` ${user}`;
+        } else {
+          users += ` and ${user}`;
+        }
+      });
+    } else if (mentionedUsers.length === 1) {
+      users = `, ${mentionedUsers[0]}`;
+    }
+    return !users ? '**The definition of insanity is answering the same question over and over again when we have an FAQ!  Help us stay sane by giving this a read: https://discord.com/channels/505093832157691914/823266307293839401/823266549912829992**' : `${users} **The definition of insanity is answering the same question over and over again when we have an FAQ!  Help us stay sane by giving this a read: https://discord.com/channels/505093832157691914/823266307293839401/823266549912829992**`;
+  },
+};
+
+registerBotCommand(command.regex, command.cb);
+
+module.exports = command;
diff --git a/botCommands/top.js b/botCommands/top.js
deleted file mode 100644
index bae52f7..0000000
--- a/botCommands/top.js
+++ /dev/null
@@ -1,11 +0,0 @@
-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__/faq.test.js.snap b/botCommands/__snapshots__/faq.test.js.snap
new file mode 100644
index 0000000..9ba668b
--- /dev/null
+++ b/botCommands/__snapshots__/faq.test.js.snap
@@ -0,0 +1,9 @@
+// Jest Snapshot v1, https://goo.gl/fbAQLP
+
+exports[`callback should return the correct output 1`] = `"**The definition of insanity is answering the same question over and over again when we have an FAQ!  Help us stay sane by giving this a read: https://discord.com/channels/505093832157691914/823266307293839401/823266549912829992**"`;
+
+exports[`callback should return the correct output 2`] = `", <@1> **The definition of insanity is answering the same question over and over again when we have an FAQ!  Help us stay sane by giving this a read: https://discord.com/channels/505093832157691914/823266307293839401/823266549912829992**"`;
+
+exports[`callback should return the correct output 3`] = `" <@1> and <@2> **The definition of insanity is answering the same question over and over again when we have an FAQ!  Help us stay sane by giving this a read: https://discord.com/channels/505093832157691914/823266307293839401/823266549912829992**"`;
+
+exports[`callback should return the correct output 4`] = `" <@1>, <@2>, and <@3> **The definition of insanity is answering the same question over and over again when we have an FAQ!  Help us stay sane by giving this a read: https://discord.com/channels/505093832157691914/823266307293839401/823266549912829992**"`;
diff --git a/botCommands/__snapshots__/top.test.js.snap b/botCommands/__snapshots__/top.test.js.snap
deleted file mode 100644
index 063adaa..0000000
--- a/botCommands/__snapshots__/top.test.js.snap
+++ /dev/null
@@ -1,3 +0,0 @@
-// 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/faq.test.js b/botCommands/faq.test.js
new file mode 100644
index 0000000..8998a3a
--- /dev/null
+++ b/botCommands/faq.test.js
@@ -0,0 +1,62 @@
+const command = require('./faq');
+const { generateMentions } = require('./mockData');
+
+describe('/faq', () => {
+  it.each([
+    ['/faq'],
+    [' /faq'],
+    ['/faq @odin-bot'],
+    [' /faq @odin-bot'],
+  ])("'%s' triggers the callback", (string) => {
+    expect(command.regex.test(string)).toBeTruthy();
+  });
+
+  it.each([
+    ['/fEhq'],
+    ['fye'],
+    ['/f'],
+    ['/fq'],
+    ['/f a q'],
+    ['```function("/faq", () => {}```'],
+    ['/FAQ'],
+    [''],
+    [' '],
+    ['/ '],
+    ['@odin-bot / faq'],
+    ['/fafaq'],
+  ])("'%s' does not trigger the callback", (string) => {
+    expect(command.regex.test(string)).toBeFalsy();
+  });
+
+  it.each([
+    ['thats a /faq'],
+    ['that gets asked a lot /faq give this a read'],
+    ['hey @odin-bot, /faq'],
+    ['/@odin-bot ^ /me /faq /test$*'],
+  ])("'%s' - the command can be anywhere in the string", (string) => {
+    expect(command.regex.test(string)).toBeTruthy();
+  });
+
+  it.each([
+    ['@user/faq'],
+    ['watchaknowabout/faq'],
+    ['/faqsgrealkdmsfalnd'],
+    ['/faq/'],
+    ['/faq*'],
+    ['/faq...'],
+  ])(
+    "'%s' - command should be its own word/group - no leading or trailing characters",
+    (string) => {
+      expect(command.regex.test(string)).toBeFalsy();
+    },
+  );
+});
+
+describe('callback', () => {
+  it('should return the correct output', async () => {
+    expect(await command.cb(generateMentions(0))).toMatchSnapshot();
+    expect(await command.cb(generateMentions(1))).toMatchSnapshot();
+    expect(await command.cb(generateMentions(2))).toMatchSnapshot();
+    expect(await command.cb(generateMentions(3))).toMatchSnapshot();
+  });
+});
diff --git a/botCommands/simpleCommands.test.js b/botCommands/simpleCommands.test.js
index a1c1900..d707112 100644
--- a/botCommands/simpleCommands.test.js
+++ b/botCommands/simpleCommands.test.js
@@ -840,9 +840,9 @@ describe('/xy', () => {
       ['/xy @odin-bot'],
       ['@odin-bot /xy'],
     ])('correct strings trigger the callback', (string) => {
-      expect(commands.xy.regex.test(string)).toBeTruthy()
-    })
-    
+      expect(commands.xy.regex.test(string)).toBeTruthy();
+    });
+
     it.each([
       ['/yx'],
       ['xy'],
@@ -860,17 +860,17 @@ describe('/xy', () => {
       ['@odin-bot/ xy'],
       ['https://xy.com'],
     ])("'%s' does not trigger the callback", (string) => {
-      expect(commands.xy.regex.test(string)).toBeFalsy()
-    })
+      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$*']
+      ['/@odin-bot ^ /me /xy /tests$*'],
     ])("'%s' - command can be anywhere in the string", (string) => {
-      expect(commands.xy.regex.test(string)).toBeTruthy()
-    })
+      expect(commands.xy.regex.test(string)).toBeTruthy();
+    });
 
     it.each([
       ['@user/xy'],
@@ -878,15 +878,15 @@ describe('/xy', () => {
       ['/xyisanillusion'],
       ['/xy/'],
       ['/xy*'],
-      ['/xy...']
+      ['/xy...'],
     ])("'%s' - command should be its own word/group - no leading or trailing characters", (string) => {
-      expect(commands.xy.regex.test(string)).toBeFalsy()
-    })
-  })
+      expect(commands.xy.regex.test(string)).toBeFalsy();
+    });
+  });
 
   describe('callback', () => {
     it('returns correct output', () => {
-      expect(commands.xy.cb()).toMatchSnapshot()
-    })
-  })
-})
+      expect(commands.xy.cb()).toMatchSnapshot();
+    });
+  });
+});
diff --git a/botCommands/top.test.js b/botCommands/top.test.js
deleted file mode 100644
index 6727907..0000000
--- a/botCommands/top.test.js
+++ /dev/null
@@ -1,48 +0,0 @@
-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();
-    });
-  });
-});