From 43fd1ead7e6c2bd7653322654adeba2dd0877111 Mon Sep 17 00:00:00 2001 From: DanceParty Date: Sun, 22 Aug 2021 13:00:00 -0700 Subject: [PATCH 1/5] remove clashing prettier ruules --- .eslintrc.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.eslintrc.json b/.eslintrc.json index bfe6d12..06c6d2e 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -2,5 +2,5 @@ "root": true, "parser": "@typescript-eslint/parser", "plugins": ["@typescript-eslint"], - "extends": ["prettier", "plugin:prettier/recommended"] + "extends": ["prettier"] } From 40c7d2e0bb4949c87e32210b5c174415743ea387 Mon Sep 17 00:00:00 2001 From: DanceParty Date: Sun, 22 Aug 2021 13:27:40 -0700 Subject: [PATCH 2/5] fix pipeline --- __tests__/discord-client.test.ts | 9 ++++++++- src/DiscordClient.ts | 5 ++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/__tests__/discord-client.test.ts b/__tests__/discord-client.test.ts index 33783ff..1cef088 100644 --- a/__tests__/discord-client.test.ts +++ b/__tests__/discord-client.test.ts @@ -16,6 +16,13 @@ describe("DiscordClient", () => { }); describe("sendMessage()", () => { + beforeEach(() => { + discordClient.isValidChannel = jest.fn((channelName) => { + // mocking environment variables + return true; + }); + }); + test("successfully calls channel.send when called correctly", async () => { await discordClient.sendMessage(MESSAGES.GOML, DiscordClient.CHANNELS.CHANGELOG); expect(discordClient.channels.cache.get).toHaveBeenCalledWith(DiscordClient.CHANNELS.CHANGELOG); @@ -51,7 +58,7 @@ describe("DiscordClient", () => { describe("isValidChannel", () => { test("returns true if the channel is not empty", () => { - const input = "channel name"; + const input = "123456789012345678"; const output = true; expect(discordClient.isValidChannel(input)).toEqual(output); }); diff --git a/src/DiscordClient.ts b/src/DiscordClient.ts index 243c0a3..14fc043 100644 --- a/src/DiscordClient.ts +++ b/src/DiscordClient.ts @@ -34,9 +34,8 @@ class DiscordClient extends Client { }; isValidChannel = (channelName: string): boolean => { - // since they are environment variables, we can only really check that - // they are not empty - return channelName.length > 0; + // channel ids seem to always be 18 length + return channelName.length === 18; }; } From 838c2a46542b46ea9c5f0f5446cea073ff9950b0 Mon Sep 17 00:00:00 2001 From: DanceParty Date: Sun, 22 Aug 2021 19:28:50 -0700 Subject: [PATCH 3/5] mock environment variables --- __tests__/discord-client.test.ts | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/__tests__/discord-client.test.ts b/__tests__/discord-client.test.ts index 1cef088..af65f54 100644 --- a/__tests__/discord-client.test.ts +++ b/__tests__/discord-client.test.ts @@ -17,10 +17,8 @@ describe("DiscordClient", () => { describe("sendMessage()", () => { beforeEach(() => { - discordClient.isValidChannel = jest.fn((channelName) => { - // mocking environment variables - return true; - }); + process.env.CHANGELOG_CHANNEL = "123456789012345678"; + process.env.CHANNEL = "876543210987654321"; }); test("successfully calls channel.send when called correctly", async () => { From 576c158d45d36e91d838b7d2417d83e16bdc53e4 Mon Sep 17 00:00:00 2001 From: DanceParty Date: Sun, 22 Aug 2021 19:48:42 -0700 Subject: [PATCH 4/5] fix environment variables in test --- __tests__/discord-client.test.ts | 5 ----- config/jest.setup.js | 8 ++++++++ jest.config.js | 2 +- 3 files changed, 9 insertions(+), 6 deletions(-) create mode 100644 config/jest.setup.js diff --git a/__tests__/discord-client.test.ts b/__tests__/discord-client.test.ts index af65f54..a8eade1 100644 --- a/__tests__/discord-client.test.ts +++ b/__tests__/discord-client.test.ts @@ -16,11 +16,6 @@ describe("DiscordClient", () => { }); describe("sendMessage()", () => { - beforeEach(() => { - process.env.CHANGELOG_CHANNEL = "123456789012345678"; - process.env.CHANNEL = "876543210987654321"; - }); - test("successfully calls channel.send when called correctly", async () => { await discordClient.sendMessage(MESSAGES.GOML, DiscordClient.CHANNELS.CHANGELOG); expect(discordClient.channels.cache.get).toHaveBeenCalledWith(DiscordClient.CHANNELS.CHANGELOG); diff --git a/config/jest.setup.js b/config/jest.setup.js new file mode 100644 index 0000000..81b5fe7 --- /dev/null +++ b/config/jest.setup.js @@ -0,0 +1,8 @@ +module.exports = async () => { + const CHANNEL_CHANGELOG = "123456789012345678"; + const CHANNEL_MAIN = "876543210987654321"; + process.env = Object.assign(process.env, { + CHANGELOG_CHANNEL: CHANNEL_CHANGELOG, + CHANNEL: CHANNEL_MAIN, + }); +}; diff --git a/jest.config.js b/jest.config.js index dc9d869..77005ee 100644 --- a/jest.config.js +++ b/jest.config.js @@ -1,5 +1,5 @@ module.exports = { preset: "ts-jest", testEnvironment: "node", - setupFiles: ["dotenv/config"], + globalSetup: "./config/jest.setup.js", }; From f81407c8d449ab99e43034e3117810ce471c055e Mon Sep 17 00:00:00 2001 From: DanceParty Date: Sun, 22 Aug 2021 19:48:42 -0700 Subject: [PATCH 5/5] fix environment variables in test --- __tests__/discord-client.test.ts | 5 ----- config/jest.setup.js | 8 ++++++++ jest.config.js | 2 +- 3 files changed, 9 insertions(+), 6 deletions(-) create mode 100644 config/jest.setup.js diff --git a/__tests__/discord-client.test.ts b/__tests__/discord-client.test.ts index af65f54..a8eade1 100644 --- a/__tests__/discord-client.test.ts +++ b/__tests__/discord-client.test.ts @@ -16,11 +16,6 @@ describe("DiscordClient", () => { }); describe("sendMessage()", () => { - beforeEach(() => { - process.env.CHANGELOG_CHANNEL = "123456789012345678"; - process.env.CHANNEL = "876543210987654321"; - }); - test("successfully calls channel.send when called correctly", async () => { await discordClient.sendMessage(MESSAGES.GOML, DiscordClient.CHANNELS.CHANGELOG); expect(discordClient.channels.cache.get).toHaveBeenCalledWith(DiscordClient.CHANNELS.CHANGELOG); diff --git a/config/jest.setup.js b/config/jest.setup.js new file mode 100644 index 0000000..81b5fe7 --- /dev/null +++ b/config/jest.setup.js @@ -0,0 +1,8 @@ +module.exports = async () => { + const CHANNEL_CHANGELOG = "123456789012345678"; + const CHANNEL_MAIN = "876543210987654321"; + process.env = Object.assign(process.env, { + CHANGELOG_CHANNEL: CHANNEL_CHANGELOG, + CHANNEL: CHANNEL_MAIN, + }); +}; diff --git a/jest.config.js b/jest.config.js index dc9d869..77005ee 100644 --- a/jest.config.js +++ b/jest.config.js @@ -1,5 +1,5 @@ module.exports = { preset: "ts-jest", testEnvironment: "node", - setupFiles: ["dotenv/config"], + globalSetup: "./config/jest.setup.js", };