This commit is contained in:
parent
783c730e0c
commit
9dff741971
2 changed files with 87 additions and 74 deletions
|
@ -1,8 +1,12 @@
|
|||
import { APIEmbed, CommandInteraction, CommandInteractionOption, Embed, EmbedBuilder, Guild, GuildChannel, GuildMember, InteractionReplyOptions, JSONEncodable, SlashCommandBuilder, TextChannel, User } from "discord.js";
|
||||
import { APIEmbed, CommandInteraction, CommandInteractionOption, DMChannel, Embed, EmbedBuilder, Guild, GuildChannel, GuildMember, InteractionReplyOptions, JSONEncodable, MessageCreateOptions, SlashCommandBuilder, TextChannel, User } from "discord.js";
|
||||
import { mock } from "jest-mock-extended";
|
||||
import Timeout from "../../src/commands/timeout";
|
||||
import SettingsHelper from "../../src/helpers/SettingsHelper";
|
||||
import Audit from "../../src/entity/Audit";
|
||||
import EmbedColours from "../../src/constants/EmbedColours";
|
||||
import { DeepPartial, EntityTarget } from "typeorm";
|
||||
import BaseEntity from "../../src/contracts/BaseEntity";
|
||||
import { AuditType } from "../../src/constants/AuditType";
|
||||
|
||||
describe('Constructor', () => {
|
||||
test('EXPECT CommandBuilder to be configured', () => {
|
||||
|
@ -29,16 +33,32 @@ describe('execute', () => {
|
|||
embeds = options.embeds as APIEmbed[];
|
||||
});
|
||||
|
||||
let savedAudit: DeepPartial<Audit> | undefined;
|
||||
|
||||
const getSetting = jest.spyOn(SettingsHelper, 'GetSetting').mockResolvedValue('mod-logs');
|
||||
const auditSave = jest.spyOn(Audit.prototype, 'Save').mockImplementation();
|
||||
const auditSave = jest.spyOn(Audit.prototype, 'Save').mockImplementation((target: EntityTarget<BaseEntity>, entity: DeepPartial<BaseEntity>): Promise<void> => {
|
||||
savedAudit = entity;
|
||||
|
||||
return Promise.resolve();
|
||||
});
|
||||
|
||||
const timeoutFunc = jest.fn();
|
||||
|
||||
let dmChannelSentEmbeds: (APIEmbed | JSONEncodable<APIEmbed>)[] | undefined;
|
||||
let logsChannelSentEmbeds: (APIEmbed | JSONEncodable<APIEmbed>)[] | undefined;
|
||||
|
||||
const dmChannel = {
|
||||
send: jest.fn().mockImplementation((options: MessageCreateOptions) => {
|
||||
dmChannelSentEmbeds = options.embeds;
|
||||
}),
|
||||
} as unknown as DMChannel;
|
||||
|
||||
const userInput = {
|
||||
user: {
|
||||
id: 'userId',
|
||||
tag: 'userTag',
|
||||
} as User,
|
||||
createDM: jest.fn().mockResolvedValue(dmChannel),
|
||||
} as unknown as User,
|
||||
member: {
|
||||
manageable: true,
|
||||
timeout: timeoutFunc,
|
||||
|
@ -55,7 +75,9 @@ describe('execute', () => {
|
|||
|
||||
const logsChannel = {
|
||||
name: 'mod-logs',
|
||||
send: jest.fn(),
|
||||
send: jest.fn().mockImplementation((options: MessageCreateOptions) => {
|
||||
logsChannelSentEmbeds = options.embeds;
|
||||
}),
|
||||
} as unknown as TextChannel;
|
||||
|
||||
const interaction = {
|
||||
|
@ -65,7 +87,8 @@ describe('execute', () => {
|
|||
find: jest.fn()
|
||||
.mockReturnValue(logsChannel),
|
||||
}
|
||||
}
|
||||
},
|
||||
name: "Test Guild",
|
||||
} as unknown as Guild,
|
||||
guildId: 'guildId',
|
||||
reply: interactionReply,
|
||||
|
@ -102,9 +125,59 @@ describe('execute', () => {
|
|||
expect(resultEmbedDMField.name).toBe("DM Sent");
|
||||
expect(resultEmbedDMField.value).toBe("true");
|
||||
|
||||
// TODO: DM Embed check
|
||||
// TODO: Log Embed check
|
||||
// TODO: Audit check
|
||||
// EXPECT user to be DM's with embed
|
||||
expect(dmChannel.send).toBeCalled();
|
||||
expect(dmChannelSentEmbeds).toBeDefined();
|
||||
expect(dmChannelSentEmbeds?.length).toBe(1);
|
||||
|
||||
const dmChannelSentEmbed = (dmChannelSentEmbeds![0] as any).data;
|
||||
|
||||
expect(dmChannelSentEmbed.color).toBe(EmbedColours.Ok);
|
||||
expect(dmChannelSentEmbed.description).toBe("You have been timed out in Test Guild");
|
||||
expect(dmChannelSentEmbed.fields?.length).toBe(3);
|
||||
|
||||
expect(dmChannelSentEmbed.fields![0].name).toBe("Reason");
|
||||
expect(dmChannelSentEmbed.fields![0].value).toBe("Test reason");
|
||||
|
||||
expect(dmChannelSentEmbed.fields![1].name).toBe("Length");
|
||||
expect(dmChannelSentEmbed.fields![1].value).toBe("1s");
|
||||
|
||||
expect(dmChannelSentEmbed.fields![2].name).toBe("Until");
|
||||
expect(dmChannelSentEmbed.fields![2].value).toBeDefined();
|
||||
|
||||
// EXPECT log embed to be sent
|
||||
expect(logsChannel.send).toBeCalled();
|
||||
expect(logsChannelSentEmbeds).toBeDefined();
|
||||
expect(logsChannelSentEmbeds?.length).toBe(1);
|
||||
|
||||
const logsChannelSentEmbed = (logsChannelSentEmbeds![0] as any).data;
|
||||
|
||||
expect(logsChannelSentEmbed.color).toBe(EmbedColours.Ok);
|
||||
expect(logsChannelSentEmbed.title).toBe("Member Timed Out");
|
||||
expect(logsChannelSentEmbed.description).toBe("<@userId> `userTag`");
|
||||
expect(logsChannelSentEmbed.fields?.length).toBe(4);
|
||||
|
||||
expect(logsChannelSentEmbed.fields![0].name).toBe("Moderator");
|
||||
expect(logsChannelSentEmbed.fields![0].value).toBe("<@moderatorId>");
|
||||
|
||||
expect(logsChannelSentEmbed.fields![1].name).toBe("Reason");
|
||||
expect(logsChannelSentEmbed.fields![1].value).toBe("Test reason");
|
||||
|
||||
expect(logsChannelSentEmbed.fields![2].name).toBe("Length");
|
||||
expect(logsChannelSentEmbed.fields![2].value).toBe("1s");
|
||||
|
||||
expect(logsChannelSentEmbed.fields![3].name).toBe("Until");
|
||||
expect(logsChannelSentEmbed.fields![3].value).toBeDefined();
|
||||
|
||||
// EXPECT Audit to be saved
|
||||
expect(auditSave).toBeCalled();
|
||||
|
||||
expect(savedAudit).toBeDefined();
|
||||
expect(savedAudit?.UserId).toBe('userId');
|
||||
expect(savedAudit?.AuditType).toBe(AuditType.Timeout);
|
||||
expect(savedAudit?.Reason).toBe("Test reason");
|
||||
expect(savedAudit?.ModeratorId).toBe('moderatorId');
|
||||
expect(savedAudit?.ServerId).toBe('guildId');
|
||||
});
|
||||
|
||||
// Null checks
|
||||
|
|
72
yarn.lock
72
yarn.lock
|
@ -124,7 +124,7 @@
|
|||
dependencies:
|
||||
"@babel/types" "^7.18.6"
|
||||
|
||||
"@babel/helper-string-parser@^7.21.5":
|
||||
"@babel/helper-string-parser@^7.19.4", "@babel/helper-string-parser@^7.21.5":
|
||||
version "7.21.5"
|
||||
resolved "https://registry.yarnpkg.com/@babel/helper-string-parser/-/helper-string-parser-7.21.5.tgz#2b3eea65443c6bdc31c22d037c65f6d323b6b2bd"
|
||||
integrity sha512-5pTUx3hAJaZIdW99sJ6ZUUgWq/Y+Hja7TowEnLNMm1VivRgZQL3vpBY3qUACVsvw+yQU6+YgfBVmcbLaZtrA1w==
|
||||
|
@ -157,12 +157,12 @@
|
|||
chalk "^2.0.0"
|
||||
js-tokens "^4.0.0"
|
||||
|
||||
"@babel/parser@^7.1.0", "@babel/parser@^7.14.7", "@babel/parser@^7.20.7", "@babel/parser@^7.21.5", "@babel/parser@^7.21.8":
|
||||
"@babel/parser@^7.1.0", "@babel/parser@^7.14.7", "@babel/parser@^7.21.5", "@babel/parser@^7.21.8":
|
||||
version "7.21.8"
|
||||
resolved "https://registry.yarnpkg.com/@babel/parser/-/parser-7.21.8.tgz#642af7d0333eab9c0ad70b14ac5e76dbde7bfdf8"
|
||||
integrity sha512-6zavDGdzG3gUqAdWvlLFfk+36RilI+Pwyuuh7HItyeScCWP3k6i8vKclAQ0bM/0y/Kz/xiwvxhMv9MgTJP5gmA==
|
||||
|
||||
"@babel/parser@^7.20.7", "@babel/parser@^7.21.3":
|
||||
"@babel/parser@^7.20.7":
|
||||
version "7.21.3"
|
||||
resolved "https://registry.yarnpkg.com/@babel/parser/-/parser-7.21.3.tgz#1d285d67a19162ff9daa358d4cb41d50c06220b3"
|
||||
integrity sha512-lobG0d7aOfQRXh8AyklEAgZGvA4FShxo6xQbUrrT/cNBPUdIDojlokwJsQyCC/eKia7ifqM0yP+2DRZ4WKw2RQ==
|
||||
|
@ -290,7 +290,7 @@
|
|||
debug "^4.1.0"
|
||||
globals "^11.1.0"
|
||||
|
||||
"@babel/types@^7.0.0", "@babel/types@^7.18.6", "@babel/types@^7.20.7", "@babel/types@^7.21.0", "@babel/types@^7.21.4", "@babel/types@^7.21.5", "@babel/types@^7.3.0", "@babel/types@^7.3.3":
|
||||
"@babel/types@^7.0.0", "@babel/types@^7.21.4", "@babel/types@^7.21.5", "@babel/types@^7.3.0", "@babel/types@^7.3.3":
|
||||
version "7.21.5"
|
||||
resolved "https://registry.yarnpkg.com/@babel/types/-/types-7.21.5.tgz#18dfbd47c39d3904d5db3d3dc2cc80bedb60e5b6"
|
||||
integrity sha512-m4AfNvVF2mVC/F7fDEdH2El3HzUg9It/XsCxZiOTTA3m3qYfcSVSbTfM6Q9xG+hYDniZssYhlXKKUMD5m8tF4Q==
|
||||
|
@ -299,7 +299,7 @@
|
|||
"@babel/helper-validator-identifier" "^7.19.1"
|
||||
to-fast-properties "^2.0.0"
|
||||
|
||||
"@babel/types@^7.18.6", "@babel/types@^7.20.2", "@babel/types@^7.20.7", "@babel/types@^7.21.0", "@babel/types@^7.21.2", "@babel/types@^7.21.3":
|
||||
"@babel/types@^7.18.6", "@babel/types@^7.20.7", "@babel/types@^7.21.0":
|
||||
version "7.21.3"
|
||||
resolved "https://registry.yarnpkg.com/@babel/types/-/types-7.21.3.tgz#4865a5357ce40f64e3400b0f3b737dc6d4f64d05"
|
||||
integrity sha512-sBGdETxC+/M4o/zKC0sl6sjWv62WFR/uzxrJ6uYyMLZOUlPnwzw0tKgVHOXxaAd5l2g8pEDM5RZ495GPQI77kg==
|
||||
|
@ -962,16 +962,6 @@ browserslist@^4.21.3:
|
|||
node-releases "^2.0.8"
|
||||
update-browserslist-db "^1.0.10"
|
||||
|
||||
browserslist@^4.21.3:
|
||||
version "4.21.5"
|
||||
resolved "https://registry.yarnpkg.com/browserslist/-/browserslist-4.21.5.tgz#75c5dae60063ee641f977e00edd3cfb2fb7af6a7"
|
||||
integrity sha512-tUkiguQGW7S3IhB7N+c2MV/HZPSCPAAiYBZXLsBhFB/PCy6ZKKsZrmBayHV9fdGV/ARIfJ14NkxKzRDjvp7L6w==
|
||||
dependencies:
|
||||
caniuse-lite "^1.0.30001449"
|
||||
electron-to-chromium "^1.4.284"
|
||||
node-releases "^2.0.8"
|
||||
update-browserslist-db "^1.0.10"
|
||||
|
||||
bs-logger@0.x:
|
||||
version "0.2.6"
|
||||
resolved "https://registry.yarnpkg.com/bs-logger/-/bs-logger-0.2.6.tgz#eb7d365307a72cf974cc6cda76b68354ad336bd8"
|
||||
|
@ -1039,11 +1029,6 @@ camelcase@^6.2.0:
|
|||
resolved "https://registry.yarnpkg.com/camelcase/-/camelcase-6.3.0.tgz#5685b95eb209ac9c0c177467778c9c84df58ba9a"
|
||||
integrity sha512-Gmy6FhYlCY7uOElZUSbxo2UCDH8owEk996gkbrpsgGtrJLM3J7jGxl9Ic7Qwwj4ivOE5AWZWRMecDdF7hqGjFA==
|
||||
|
||||
caniuse-lite@^1.0.30001449:
|
||||
version "1.0.30001486"
|
||||
resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001486.tgz#56a08885228edf62cbe1ac8980f2b5dae159997e"
|
||||
integrity sha512-uv7/gXuHi10Whlj0pp5q/tsK/32J2QSqVRKQhs2j8VsDCjgyruAh/eEXHF822VqO9yT6iZKw3nRwZRSPBE9OQg==
|
||||
|
||||
caniuse-lite@^1.0.30001449:
|
||||
version "1.0.30001469"
|
||||
resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001469.tgz#3dd505430c8522fdc9f94b4a19518e330f5c945a"
|
||||
|
@ -1167,11 +1152,6 @@ convert-source-map@^2.0.0:
|
|||
resolved "https://registry.yarnpkg.com/convert-source-map/-/convert-source-map-2.0.0.tgz#4b560f649fc4e918dd0ab75cf4961e8bc882d82a"
|
||||
integrity sha512-Kvp459HrV2FEJ1CAsi1Ku+MY3kasH19TFykTz2xWmMeq6bk2NU3XXvfJ+Q61m0xktWwt+1HSYf3JZsTms3aRJg==
|
||||
|
||||
convert-source-map@^2.0.0:
|
||||
version "2.0.0"
|
||||
resolved "https://registry.yarnpkg.com/convert-source-map/-/convert-source-map-2.0.0.tgz#4b560f649fc4e918dd0ab75cf4961e8bc882d82a"
|
||||
integrity sha512-Kvp459HrV2FEJ1CAsi1Ku+MY3kasH19TFykTz2xWmMeq6bk2NU3XXvfJ+Q61m0xktWwt+1HSYf3JZsTms3aRJg==
|
||||
|
||||
core-util-is@~1.0.0:
|
||||
version "1.0.3"
|
||||
resolved "https://registry.yarnpkg.com/core-util-is/-/core-util-is-1.0.3.tgz#a6042d3634c2b27e9328f837b965fac83808db85"
|
||||
|
@ -1632,17 +1612,6 @@ istanbul-lib-instrument@^5.0.4, istanbul-lib-instrument@^5.1.0:
|
|||
istanbul-lib-coverage "^3.2.0"
|
||||
semver "^6.3.0"
|
||||
|
||||
istanbul-lib-instrument@^5.1.0:
|
||||
version "5.2.1"
|
||||
resolved "https://registry.yarnpkg.com/istanbul-lib-instrument/-/istanbul-lib-instrument-5.2.1.tgz#d10c8885c2125574e1c231cacadf955675e1ce3d"
|
||||
integrity sha512-pzqtp31nLv/XFOzXGuvhCb8qhjmTVo5vjVk19XE4CRlSWz0KoeJ3bw9XsA7nOp9YBf4qHjwBxkDzKcME/J29Yg==
|
||||
dependencies:
|
||||
"@babel/core" "^7.12.3"
|
||||
"@babel/parser" "^7.14.7"
|
||||
"@istanbuljs/schema" "^0.1.2"
|
||||
istanbul-lib-coverage "^3.2.0"
|
||||
semver "^6.3.0"
|
||||
|
||||
istanbul-lib-report@^3.0.0:
|
||||
version "3.0.0"
|
||||
resolved "https://registry.yarnpkg.com/istanbul-lib-report/-/istanbul-lib-report-3.0.0.tgz#7518fe52ea44de372f460a76b5ecda9ffb73d8a6"
|
||||
|
@ -2070,11 +2039,6 @@ json5@^2.2.2, json5@^2.2.3:
|
|||
resolved "https://registry.yarnpkg.com/json5/-/json5-2.2.3.tgz#78cd6f1a19bdc12b73db5ad0c61efd66c1e29283"
|
||||
integrity sha512-XmOWe7eyHYH14cLdVPoyg+GOH3rYX++KpzrylJwSW98t3Nk+U8XOl8FWKOgwtzdb8lXGf6zYwDUzeHMWfxasyg==
|
||||
|
||||
json5@^2.2.2, json5@^2.2.3:
|
||||
version "2.2.3"
|
||||
resolved "https://registry.yarnpkg.com/json5/-/json5-2.2.3.tgz#78cd6f1a19bdc12b73db5ad0c61efd66c1e29283"
|
||||
integrity sha512-XmOWe7eyHYH14cLdVPoyg+GOH3rYX++KpzrylJwSW98t3Nk+U8XOl8FWKOgwtzdb8lXGf6zYwDUzeHMWfxasyg==
|
||||
|
||||
keyv@^4.0.0:
|
||||
version "4.5.2"
|
||||
resolved "https://registry.yarnpkg.com/keyv/-/keyv-4.5.2.tgz#0e310ce73bf7851ec702f2eaf46ec4e3805cce56"
|
||||
|
@ -2255,11 +2219,6 @@ node-releases@^2.0.8:
|
|||
resolved "https://registry.yarnpkg.com/node-releases/-/node-releases-2.0.10.tgz#c311ebae3b6a148c89b1813fd7c4d3c024ef537f"
|
||||
integrity sha512-5GFldHPXVG/YZmFzJvKK2zDSzPKhEp0+ZR5SVaoSag9fsL5YgHbUHDfnG5494ISANDcK4KwPXAx2xqVEydmd7w==
|
||||
|
||||
node-releases@^2.0.8:
|
||||
version "2.0.10"
|
||||
resolved "https://registry.yarnpkg.com/node-releases/-/node-releases-2.0.10.tgz#c311ebae3b6a148c89b1813fd7c4d3c024ef537f"
|
||||
integrity sha512-5GFldHPXVG/YZmFzJvKK2zDSzPKhEp0+ZR5SVaoSag9fsL5YgHbUHDfnG5494ISANDcK4KwPXAx2xqVEydmd7w==
|
||||
|
||||
normalize-path@^3.0.0:
|
||||
version "3.0.0"
|
||||
resolved "https://registry.yarnpkg.com/normalize-path/-/normalize-path-3.0.0.tgz#0dcd69ff23a1c9b11fd0978316644a0388216a65"
|
||||
|
@ -2410,15 +2369,6 @@ pretty-format@^29.0.0, pretty-format@^29.5.0:
|
|||
ansi-styles "^5.0.0"
|
||||
react-is "^18.0.0"
|
||||
|
||||
pretty-format@^29.5.0:
|
||||
version "29.5.0"
|
||||
resolved "https://registry.yarnpkg.com/pretty-format/-/pretty-format-29.5.0.tgz#283134e74f70e2e3e7229336de0e4fce94ccde5a"
|
||||
integrity sha512-V2mGkI31qdttvTFX7Mt4efOqHXqJWMu4/r66Xh3Z3BwZaPfPJgp6/gbwoujRpPUtfEF6AUUWx3Jim3GCw5g/Qw==
|
||||
dependencies:
|
||||
"@jest/schemas" "^29.4.3"
|
||||
ansi-styles "^5.0.0"
|
||||
react-is "^18.0.0"
|
||||
|
||||
process-nextick-args@~2.0.0:
|
||||
version "2.0.1"
|
||||
resolved "https://registry.yarnpkg.com/process-nextick-args/-/process-nextick-args-2.0.1.tgz#7820d9b16120cc55ca9ae7792680ae7dba6d7fe2"
|
||||
|
@ -2464,11 +2414,6 @@ react-is@^18.0.0:
|
|||
resolved "https://registry.yarnpkg.com/react-is/-/react-is-18.2.0.tgz#199431eeaaa2e09f86427efbb4f1473edb47609b"
|
||||
integrity sha512-xWGDIW6x921xtzPkhiULtthJHoJvBbF3q26fzloPCK0hsvxtPVelvftw3zjbHWSkR2km9Z+4uxbDDK/6Zw9B8w==
|
||||
|
||||
react-is@^18.0.0:
|
||||
version "18.2.0"
|
||||
resolved "https://registry.yarnpkg.com/react-is/-/react-is-18.2.0.tgz#199431eeaaa2e09f86427efbb4f1473edb47609b"
|
||||
integrity sha512-xWGDIW6x921xtzPkhiULtthJHoJvBbF3q26fzloPCK0hsvxtPVelvftw3zjbHWSkR2km9Z+4uxbDDK/6Zw9B8w==
|
||||
|
||||
readable-stream@2.3.7:
|
||||
version "2.3.7"
|
||||
resolved "https://registry.yarnpkg.com/readable-stream/-/readable-stream-2.3.7.tgz#1eca1cf711aef814c04f62252a36a62f6cb23b57"
|
||||
|
@ -2556,7 +2501,7 @@ safe-buffer@^5.0.1, safe-buffer@~5.2.0:
|
|||
resolved "https://registry.yarnpkg.com/safe-buffer/-/safe-buffer-5.2.1.tgz#1eaf9fa9bdb1fdd4ec75f58f9cdb4e6b7827eec6"
|
||||
integrity sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==
|
||||
|
||||
semver@7.x, semver@^7.3.5:
|
||||
semver@7.x:
|
||||
version "7.5.0"
|
||||
resolved "https://registry.yarnpkg.com/semver/-/semver-7.5.0.tgz#ed8c5dc8efb6c629c88b23d41dc9bf40c1d96cd0"
|
||||
integrity sha512-+XC0AD/R7Q2mPSRuy2Id0+CGTZ98+8f+KvwirxOKIEyid+XSx6HbC63p+O4IndTHuX5Z+JxQ0TghCkO5Cg/2HA==
|
||||
|
@ -2600,11 +2545,6 @@ signal-exit@^3.0.3, signal-exit@^3.0.7:
|
|||
resolved "https://registry.yarnpkg.com/signal-exit/-/signal-exit-3.0.7.tgz#a9a1767f8af84155114eaabd73f99273c8f59ad9"
|
||||
integrity sha512-wnD2ZE+l+SPC/uoS0vXeE9L1+0wuaMqKlfz9AMUo38JsyLSBWSFcHR1Rri62LZc12vLr1gb3jl7iwQhgwpAbGQ==
|
||||
|
||||
signal-exit@^3.0.7:
|
||||
version "3.0.7"
|
||||
resolved "https://registry.yarnpkg.com/signal-exit/-/signal-exit-3.0.7.tgz#a9a1767f8af84155114eaabd73f99273c8f59ad9"
|
||||
integrity sha512-wnD2ZE+l+SPC/uoS0vXeE9L1+0wuaMqKlfz9AMUo38JsyLSBWSFcHR1Rri62LZc12vLr1gb3jl7iwQhgwpAbGQ==
|
||||
|
||||
sisteransi@^1.0.5:
|
||||
version "1.0.5"
|
||||
resolved "https://registry.yarnpkg.com/sisteransi/-/sisteransi-1.0.5.tgz#134d681297756437cc05ca01370d3a7a571075ed"
|
||||
|
|
Loading…
Reference in a new issue