This commit is contained in:
parent
90bda9d9df
commit
e28fafea69
7 changed files with 0 additions and 885 deletions
|
@ -1,127 +0,0 @@
|
|||
import {ButtonInteraction} from "discord.js";
|
||||
import Effects from "../../src/buttonEvents/Effects";
|
||||
import EffectHelper from "../../src/helpers/EffectHelper";
|
||||
|
||||
describe("execute", () => {
|
||||
describe("GIVEN action in custom id is list", () => {
|
||||
const interaction = {
|
||||
customId: "effects list",
|
||||
} as unknown as ButtonInteraction;
|
||||
|
||||
let listSpy: jest.SpyInstance;
|
||||
|
||||
beforeAll(async () => {
|
||||
const effects = new Effects();
|
||||
|
||||
listSpy = jest.spyOn(effects as unknown as {"List": () => object}, "List")
|
||||
.mockImplementation();
|
||||
|
||||
await effects.execute(interaction);
|
||||
});
|
||||
|
||||
test("EXPECT list function to be called", () => {
|
||||
expect(listSpy).toHaveBeenCalledTimes(1);
|
||||
expect(listSpy).toHaveBeenCalledWith(interaction);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("List", () => {
|
||||
let interaction: ButtonInteraction;
|
||||
|
||||
const embed = {
|
||||
name: "Embed",
|
||||
};
|
||||
|
||||
const row = {
|
||||
name: "Row",
|
||||
};
|
||||
|
||||
beforeEach(() => {
|
||||
interaction = {
|
||||
customId: "effects list",
|
||||
user: {
|
||||
id: "userId",
|
||||
},
|
||||
update: jest.fn(),
|
||||
reply: jest.fn(),
|
||||
} as unknown as ButtonInteraction;
|
||||
});
|
||||
|
||||
describe("GIVEN page is a valid number", () => {
|
||||
beforeEach(async () => {
|
||||
interaction.customId += " 1";
|
||||
|
||||
EffectHelper.GenerateEffectEmbed = jest.fn()
|
||||
.mockResolvedValue({
|
||||
embed,
|
||||
row,
|
||||
});
|
||||
|
||||
const effects = new Effects();
|
||||
|
||||
await effects.execute(interaction);
|
||||
});
|
||||
|
||||
test("EXPECT EffectHelper.GenerateEffectEmbed to be called", () => {
|
||||
expect(EffectHelper.GenerateEffectEmbed).toHaveBeenCalledTimes(1);
|
||||
expect(EffectHelper.GenerateEffectEmbed).toHaveBeenCalledWith("userId", 1);
|
||||
});
|
||||
|
||||
test("EXPECT interaction to be updated", () => {
|
||||
expect(interaction.update).toHaveBeenCalledTimes(1);
|
||||
expect(interaction.update).toHaveBeenCalledWith({
|
||||
embeds: [ embed ],
|
||||
components: [ row ],
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("GIVEN page in custom id is not supplied", () => {
|
||||
beforeEach(async () => {
|
||||
EffectHelper.GenerateEffectEmbed = jest.fn()
|
||||
.mockResolvedValue({
|
||||
embed,
|
||||
row,
|
||||
});
|
||||
|
||||
const effects = new Effects();
|
||||
|
||||
await effects.execute(interaction);
|
||||
});
|
||||
|
||||
test("EXPECT interaction to be replied with error", () => {
|
||||
expect(interaction.reply).toHaveBeenCalledTimes(1);
|
||||
expect(interaction.reply).toHaveBeenCalledWith("Page option is not a valid number");
|
||||
});
|
||||
|
||||
test("EXPECT interaction to not be updated", () => {
|
||||
expect(interaction.update).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
describe("GIVEN page in custom id is not a number", () => {
|
||||
beforeEach(async () => {
|
||||
interaction.customId += " test";
|
||||
|
||||
EffectHelper.GenerateEffectEmbed = jest.fn()
|
||||
.mockResolvedValue({
|
||||
embed,
|
||||
row,
|
||||
});
|
||||
|
||||
const effects = new Effects();
|
||||
|
||||
await effects.execute(interaction);
|
||||
});
|
||||
|
||||
test("EXPECT interaction to be replied with error", () => {
|
||||
expect(interaction.reply).toHaveBeenCalledTimes(1);
|
||||
expect(interaction.reply).toHaveBeenCalledWith("Page option is not a valid number");
|
||||
});
|
||||
|
||||
test("EXPECT interaction to not be updated", () => {
|
||||
expect(interaction.update).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
});
|
|
@ -1,40 +0,0 @@
|
|||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`constructor EXPECT CommandBuilder to be defined 1`] = `
|
||||
{
|
||||
"contexts": undefined,
|
||||
"default_member_permissions": undefined,
|
||||
"default_permission": undefined,
|
||||
"description": "Effects",
|
||||
"description_localizations": undefined,
|
||||
"dm_permission": undefined,
|
||||
"integration_types": undefined,
|
||||
"name": "effects",
|
||||
"name_localizations": undefined,
|
||||
"nsfw": undefined,
|
||||
"options": [
|
||||
{
|
||||
"description": "List all effects I have",
|
||||
"description_localizations": undefined,
|
||||
"name": "list",
|
||||
"name_localizations": undefined,
|
||||
"options": [
|
||||
{
|
||||
"autocomplete": undefined,
|
||||
"choices": undefined,
|
||||
"description": "The page number",
|
||||
"description_localizations": undefined,
|
||||
"max_value": undefined,
|
||||
"min_value": 1,
|
||||
"name": "page",
|
||||
"name_localizations": undefined,
|
||||
"required": false,
|
||||
"type": 10,
|
||||
},
|
||||
],
|
||||
"type": 1,
|
||||
},
|
||||
],
|
||||
"type": 1,
|
||||
}
|
||||
`;
|
|
@ -1,164 +0,0 @@
|
|||
import {ChatInputCommandInteraction} from "discord.js";
|
||||
import Effects from "../../src/commands/effects";
|
||||
import EffectHelper from "../../src/helpers/EffectHelper";
|
||||
|
||||
describe("constructor", () => {
|
||||
let effects: Effects;
|
||||
|
||||
beforeEach(() => {
|
||||
effects = new Effects();
|
||||
});
|
||||
|
||||
test("EXPECT CommandBuilder to be defined", () => {
|
||||
expect(effects.CommandBuilder).toMatchSnapshot();
|
||||
});
|
||||
});
|
||||
|
||||
describe("execute", () => {
|
||||
describe("GIVEN interaction is not a chat input command", () => {
|
||||
let interaction: ChatInputCommandInteraction;
|
||||
|
||||
let listSpy: jest.SpyInstance;
|
||||
|
||||
beforeEach(async () => {
|
||||
interaction = {
|
||||
isChatInputCommand: jest.fn().mockReturnValue(false),
|
||||
} as unknown as ChatInputCommandInteraction;
|
||||
|
||||
const effects = new Effects();
|
||||
|
||||
listSpy = jest.spyOn(effects as unknown as {"List": () => object}, "List")
|
||||
.mockImplementation();
|
||||
|
||||
await effects.execute(interaction);
|
||||
});
|
||||
|
||||
test("EXPECT isChatInputCommand to have been called", () => {
|
||||
expect(interaction.isChatInputCommand).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
test("EXPECT nothing to happen", () => {
|
||||
expect(listSpy).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
describe("GIVEN subcommand is list", () => {
|
||||
let interaction: ChatInputCommandInteraction;
|
||||
|
||||
let listSpy: jest.SpyInstance;
|
||||
|
||||
beforeEach(async () => {
|
||||
interaction = {
|
||||
isChatInputCommand: jest.fn().mockReturnValue(true),
|
||||
options: {
|
||||
getSubcommand: jest.fn().mockReturnValue("list"),
|
||||
},
|
||||
} as unknown as ChatInputCommandInteraction;
|
||||
|
||||
const effects = new Effects();
|
||||
|
||||
listSpy = jest.spyOn(effects as unknown as {"List": () => object}, "List")
|
||||
.mockImplementation();
|
||||
|
||||
await effects.execute(interaction);
|
||||
});
|
||||
|
||||
test("EXPECT subcommand function to be called", () => {
|
||||
expect(interaction.options.getSubcommand).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
test("EXPECT list function to be called", () => {
|
||||
expect(listSpy).toHaveBeenCalledTimes(1);
|
||||
expect(listSpy).toHaveBeenCalledWith(interaction);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("List", () => {
|
||||
const effects: Effects = new Effects();
|
||||
let interaction: ChatInputCommandInteraction;
|
||||
|
||||
const embed = {
|
||||
name: "embed",
|
||||
};
|
||||
|
||||
const row = {
|
||||
name: "row",
|
||||
};
|
||||
|
||||
beforeEach(async () => {
|
||||
interaction = {
|
||||
isChatInputCommand: jest.fn().mockReturnValue(true),
|
||||
options: {
|
||||
getSubcommand: jest.fn().mockReturnValue("list"),
|
||||
},
|
||||
reply: jest.fn(),
|
||||
user: {
|
||||
id: "userId",
|
||||
},
|
||||
} as unknown as ChatInputCommandInteraction;
|
||||
|
||||
const effects = new Effects();
|
||||
|
||||
EffectHelper.GenerateEffectEmbed = jest.fn().mockReturnValue({
|
||||
embed,
|
||||
row,
|
||||
});
|
||||
|
||||
jest.spyOn(effects as unknown as {"List": () => object}, "List")
|
||||
.mockImplementation();
|
||||
});
|
||||
|
||||
describe("GIVEN page option is supplied", () => {
|
||||
describe("AND page is a valid number", () => {
|
||||
beforeEach(async () => {
|
||||
interaction.options.get = jest.fn().mockReturnValueOnce({
|
||||
value: "2",
|
||||
});
|
||||
|
||||
await effects.execute(interaction);
|
||||
});
|
||||
|
||||
test("EXPECT EffectHelper.GenerateEffectEmbed to have been called with page", () => {
|
||||
expect(EffectHelper.GenerateEffectEmbed).toHaveBeenCalledTimes(1);
|
||||
expect(EffectHelper.GenerateEffectEmbed).toHaveBeenCalledWith("userId", 2);
|
||||
});
|
||||
|
||||
test("EXPECT interaction to have been replied", () => {
|
||||
expect(interaction.reply).toHaveBeenCalledTimes(1);
|
||||
expect(interaction.reply).toHaveBeenCalledWith({
|
||||
embeds: [ embed ],
|
||||
components: [ row ],
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("AND page is not a valid number", () => {
|
||||
beforeEach(async () => {
|
||||
interaction.options.get = jest.fn().mockReturnValueOnce({
|
||||
value: "test",
|
||||
});
|
||||
|
||||
await effects.execute(interaction);
|
||||
});
|
||||
|
||||
test("EXPECT EffectHelper.GenerateEffectEmbed to have been called with page of 1", () => {
|
||||
expect(EffectHelper.GenerateEffectEmbed).toHaveBeenCalledTimes(1);
|
||||
expect(EffectHelper.GenerateEffectEmbed).toHaveBeenCalledWith("userId", 1);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("GIVEN page option is not supplied", () => {
|
||||
beforeEach(async () => {
|
||||
interaction.options.get = jest.fn().mockReturnValueOnce(undefined);
|
||||
|
||||
await effects.execute(interaction);
|
||||
});
|
||||
|
||||
test("EXPECT EffectHelper.GenerateEffectEmbed to have been called with page of 1", () => {
|
||||
expect(EffectHelper.GenerateEffectEmbed).toHaveBeenCalledTimes(1);
|
||||
expect(EffectHelper.GenerateEffectEmbed).toHaveBeenCalledWith("userId", 1);
|
||||
});
|
||||
});
|
||||
});
|
|
@ -1,103 +0,0 @@
|
|||
import UserEffect from "../../../../src/database/entities/app/UserEffect";
|
||||
|
||||
let userEffect: UserEffect;
|
||||
const now = new Date();
|
||||
|
||||
beforeEach(() => {
|
||||
userEffect = new UserEffect("name", "userId", 1);
|
||||
});
|
||||
|
||||
describe("AddUnused", () => {
|
||||
beforeEach(() => {
|
||||
userEffect.AddUnused(1);
|
||||
});
|
||||
|
||||
test("EXPECT unused to be the amount more", () => {
|
||||
expect(userEffect.Unused).toBe(2);
|
||||
});
|
||||
});
|
||||
|
||||
describe("UseEffect", () => {
|
||||
describe("GIVEN Unused is 0", () => {
|
||||
let result: boolean;
|
||||
|
||||
beforeEach(() => {
|
||||
userEffect.Unused = 0;
|
||||
|
||||
result = userEffect.UseEffect(now);
|
||||
});
|
||||
|
||||
test("EXPECT false returned", () => {
|
||||
expect(result).toBe(false);
|
||||
});
|
||||
|
||||
test("EXPECT details not to be changed", () => {
|
||||
expect(userEffect.Unused).toBe(0);
|
||||
expect(userEffect.WhenExpires).toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
||||
describe("GIVEN Unused is greater than 0", () => {
|
||||
let result: boolean;
|
||||
|
||||
beforeEach(() => {
|
||||
result = userEffect.UseEffect(now);
|
||||
});
|
||||
|
||||
test("EXPECT true returned", () => {
|
||||
expect(result).toBe(true);
|
||||
});
|
||||
|
||||
test("EXPECT Unused to be subtracted by 1", () => {
|
||||
expect(userEffect.Unused).toBe(0);
|
||||
});
|
||||
|
||||
test("EXPECT WhenExpires to be set", () => {
|
||||
expect(userEffect.WhenExpires).toBe(now);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("IsEffectActive", () => {
|
||||
describe("GIVEN WhenExpires is null", () => {
|
||||
let result: boolean;
|
||||
|
||||
beforeEach(() => {
|
||||
result = userEffect.IsEffectActive();
|
||||
});
|
||||
|
||||
test("EXPECT false returned", () => {
|
||||
expect(result).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe("GIVEN WhenExpires is defined", () => {
|
||||
describe("AND WhenExpires is in the past", () => {
|
||||
let result: boolean;
|
||||
|
||||
beforeEach(() => {
|
||||
userEffect.WhenExpires = new Date(now.getTime() - 100);
|
||||
|
||||
result = userEffect.IsEffectActive();
|
||||
});
|
||||
|
||||
test("EXPECT false returned", () => {
|
||||
expect(result).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe("AND WhenExpires is in the future", () => {
|
||||
let result: boolean;
|
||||
|
||||
beforeEach(() => {
|
||||
userEffect.WhenExpires = new Date(now.getTime() + 100);
|
||||
|
||||
result = userEffect.IsEffectActive();
|
||||
});
|
||||
|
||||
test("EXPECT true returned", () => {
|
||||
expect(result).toBe(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
|
@ -1,380 +0,0 @@
|
|||
import {ActionRowBuilder, ButtonBuilder, EmbedBuilder} from "discord.js";
|
||||
import UserEffect from "../../src/database/entities/app/UserEffect";
|
||||
import EffectHelper from "../../src/helpers/EffectHelper";
|
||||
|
||||
describe("AddEffectToUserInventory", () => {
|
||||
describe("GIVEN effect is in database", () => {
|
||||
const effectMock = {
|
||||
AddUnused: jest.fn(),
|
||||
Save: jest.fn(),
|
||||
};
|
||||
|
||||
beforeAll(async () => {
|
||||
UserEffect.FetchOneByUserIdAndName = jest.fn().mockResolvedValue(effectMock);
|
||||
|
||||
await EffectHelper.AddEffectToUserInventory("userId", "name", 1);
|
||||
});
|
||||
|
||||
test("EXPECT database to be fetched", () => {
|
||||
expect(UserEffect.FetchOneByUserIdAndName).toHaveBeenCalledTimes(1);
|
||||
expect(UserEffect.FetchOneByUserIdAndName).toHaveBeenCalledWith("userId", "name");
|
||||
});
|
||||
|
||||
test("EXPECT effect to be updated", () => {
|
||||
expect(effectMock.AddUnused).toHaveBeenCalledTimes(1);
|
||||
expect(effectMock.AddUnused).toHaveBeenCalledWith(1);
|
||||
});
|
||||
|
||||
test("EXPECT effect to be saved", () => {
|
||||
expect(effectMock.Save).toHaveBeenCalledTimes(1);
|
||||
expect(effectMock.Save).toHaveBeenCalledWith(UserEffect, effectMock);
|
||||
});
|
||||
});
|
||||
|
||||
describe("GIVEN effect is not in database", () => {
|
||||
beforeAll(async () => {
|
||||
UserEffect.FetchOneByUserIdAndName = jest.fn().mockResolvedValue(null);
|
||||
UserEffect.prototype.Save = jest.fn();
|
||||
|
||||
await EffectHelper.AddEffectToUserInventory("userId", "name", 1);
|
||||
});
|
||||
|
||||
test("EXPECT effect to be saved", () => {
|
||||
expect(UserEffect.prototype.Save).toHaveBeenCalledTimes(1);
|
||||
expect(UserEffect.prototype.Save).toHaveBeenCalledWith(UserEffect, expect.any(UserEffect));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("UseEffect", () => {
|
||||
describe("GIVEN effect is in database", () => {
|
||||
describe("GIVEN now is before effect.WhenExpires", () => {
|
||||
let result: boolean | undefined;
|
||||
|
||||
// nowMock < whenExpires
|
||||
const nowMock = new Date(2024, 11, 3, 13, 30);
|
||||
const whenExpires = new Date(2024, 11, 3, 14, 0);
|
||||
|
||||
const userEffect = {
|
||||
Unused: 1,
|
||||
WhenExpires: whenExpires,
|
||||
};
|
||||
|
||||
beforeAll(async () => {
|
||||
jest.setSystemTime(nowMock);
|
||||
|
||||
UserEffect.FetchOneByUserIdAndName = jest.fn().mockResolvedValue(userEffect);
|
||||
|
||||
result = await EffectHelper.UseEffect("userId", "name", new Date());
|
||||
});
|
||||
|
||||
test("EXPECT false returned", () => {
|
||||
expect(result).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe("GIVEN currently used effect is inactive", () => {
|
||||
let result: boolean | undefined;
|
||||
|
||||
// nowMock > whenExpires
|
||||
const nowMock = new Date(2024, 11, 3, 13, 30);
|
||||
const whenExpires = new Date(2024, 11, 3, 13, 0);
|
||||
const whenExpiresNew = new Date(2024, 11, 3, 15, 0);
|
||||
|
||||
const userEffect = {
|
||||
Unused: 1,
|
||||
WhenExpires: whenExpires,
|
||||
UseEffect: jest.fn(),
|
||||
Save: jest.fn(),
|
||||
};
|
||||
|
||||
beforeAll(async () => {
|
||||
jest.setSystemTime(nowMock);
|
||||
|
||||
UserEffect.FetchOneByUserIdAndName = jest.fn().mockResolvedValue(userEffect);
|
||||
|
||||
result = await EffectHelper.UseEffect("userId", "name", whenExpiresNew);
|
||||
});
|
||||
|
||||
test("EXPECT UseEffect to be called", () => {
|
||||
expect(userEffect.UseEffect).toHaveReturnedTimes(1);
|
||||
expect(userEffect.UseEffect).toHaveBeenCalledWith(whenExpiresNew);
|
||||
});
|
||||
|
||||
test("EXPECT effect to be saved", () => {
|
||||
expect(userEffect.Save).toHaveBeenCalledTimes(1);
|
||||
expect(userEffect.Save).toHaveBeenCalledWith(UserEffect, userEffect);
|
||||
});
|
||||
|
||||
test("EXPECT true returned", () => {
|
||||
expect(result).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe("GIVEN effect.WhenExpires is null", () => {
|
||||
let result: boolean | undefined;
|
||||
|
||||
// nowMock > whenExpires
|
||||
const nowMock = new Date(2024, 11, 3, 13, 30);
|
||||
const whenExpiresNew = new Date(2024, 11, 3, 15, 0);
|
||||
|
||||
const userEffect = {
|
||||
Unused: 1,
|
||||
WhenExpires: null,
|
||||
UseEffect: jest.fn(),
|
||||
Save: jest.fn(),
|
||||
};
|
||||
|
||||
beforeAll(async () => {
|
||||
jest.setSystemTime(nowMock);
|
||||
|
||||
UserEffect.FetchOneByUserIdAndName = jest.fn().mockResolvedValue(userEffect);
|
||||
|
||||
result = await EffectHelper.UseEffect("userId", "name", whenExpiresNew);
|
||||
});
|
||||
|
||||
test("EXPECT UseEffect to be called", () => {
|
||||
expect(userEffect.UseEffect).toHaveBeenCalledTimes(1);
|
||||
expect(userEffect.UseEffect).toHaveBeenCalledWith(whenExpiresNew);
|
||||
});
|
||||
|
||||
test("EXPECT effect to be saved", () => {
|
||||
expect(userEffect.Save).toHaveBeenCalledTimes(1);
|
||||
expect(userEffect.Save).toHaveBeenCalledWith(UserEffect, userEffect);
|
||||
});
|
||||
|
||||
test("EXPECT true returned", () => {
|
||||
expect(result).toBe(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("GIVEN effect is not in database", () => {
|
||||
let result: boolean | undefined;
|
||||
|
||||
// nowMock > whenExpires
|
||||
const nowMock = new Date(2024, 11, 3, 13, 30);
|
||||
const whenExpiresNew = new Date(2024, 11, 3, 15, 0);
|
||||
|
||||
beforeAll(async () => {
|
||||
jest.setSystemTime(nowMock);
|
||||
|
||||
UserEffect.FetchOneByUserIdAndName = jest.fn().mockResolvedValue(null);
|
||||
|
||||
result = await EffectHelper.UseEffect("userId", "name", whenExpiresNew);
|
||||
});
|
||||
|
||||
test("EXPECT false returned", () => {
|
||||
expect(result).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe("GIVEN effect.Unused is 0", () => {
|
||||
let result: boolean | undefined;
|
||||
|
||||
// nowMock > whenExpires
|
||||
const nowMock = new Date(2024, 11, 3, 13, 30);
|
||||
const whenExpiresNew = new Date(2024, 11, 3, 15, 0);
|
||||
|
||||
const userEffect = {
|
||||
Unused: 0,
|
||||
WhenExpires: null,
|
||||
UseEffect: jest.fn(),
|
||||
Save: jest.fn(),
|
||||
};
|
||||
|
||||
beforeAll(async () => {
|
||||
jest.setSystemTime(nowMock);
|
||||
|
||||
UserEffect.FetchOneByUserIdAndName = jest.fn().mockResolvedValue(userEffect);
|
||||
|
||||
result = await EffectHelper.UseEffect("userId", "name", whenExpiresNew);
|
||||
});
|
||||
|
||||
test("EXPECT false returned", () => {
|
||||
expect(result).toBe(false);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("HasEffect", () => {
|
||||
describe("GIVEN effect is in database", () => {
|
||||
describe("GIVEN effect.WhenExpires is defined", () => {
|
||||
describe("GIVEN now is before effect.WhenExpires", () => {
|
||||
let result: boolean | undefined;
|
||||
|
||||
const nowMock = new Date(2024, 11, 3, 13, 30);
|
||||
const whenExpires = new Date(2024, 11, 3, 15, 0);
|
||||
|
||||
const userEffect = {
|
||||
WhenExpires: whenExpires,
|
||||
};
|
||||
|
||||
beforeAll(async () => {
|
||||
jest.setSystemTime(nowMock);
|
||||
|
||||
UserEffect.FetchOneByUserIdAndName = jest.fn().mockResolvedValue(userEffect);
|
||||
|
||||
result = await EffectHelper.HasEffect("userId", "name");
|
||||
});
|
||||
|
||||
test("EXPECT true returned", () => {
|
||||
expect(result).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe("GIVEN now is after effect.WhenExpires", () => {
|
||||
let result: boolean | undefined;
|
||||
|
||||
const nowMock = new Date(2024, 11, 3, 16, 30);
|
||||
const whenExpires = new Date(2024, 11, 3, 15, 0);
|
||||
|
||||
const userEffect = {
|
||||
WhenExpires: whenExpires,
|
||||
};
|
||||
|
||||
beforeAll(async () => {
|
||||
jest.setSystemTime(nowMock);
|
||||
|
||||
UserEffect.FetchOneByUserIdAndName = jest.fn().mockResolvedValue(userEffect);
|
||||
|
||||
result = await EffectHelper.HasEffect("userId", "name");
|
||||
});
|
||||
|
||||
test("EXPECT false returned", () => {
|
||||
expect(result).toBe(false);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("GIVEN effect.WhenExpires is undefined", () => {
|
||||
let result: boolean | undefined;
|
||||
|
||||
const userEffect = {
|
||||
WhenExpires: undefined,
|
||||
};
|
||||
|
||||
beforeAll(async () => {
|
||||
UserEffect.FetchOneByUserIdAndName = jest.fn().mockResolvedValue(userEffect);
|
||||
|
||||
result = await EffectHelper.HasEffect("userId", "name");
|
||||
});
|
||||
|
||||
test("EXPECT false returned", () => {
|
||||
expect(result).toBe(false);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("GIVEN effect is not in database", () => {
|
||||
let result: boolean | undefined;
|
||||
|
||||
beforeAll(async () => {
|
||||
UserEffect.FetchOneByUserIdAndName = jest.fn().mockResolvedValue(null);
|
||||
|
||||
result = await EffectHelper.HasEffect("userId", "name");
|
||||
});
|
||||
|
||||
test("EXPECT false returned", () => {
|
||||
expect(result).toBe(false);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("GenerateEffectEmbed", () => {
|
||||
beforeEach(async () => {
|
||||
UserEffect.FetchAllByUserIdPaginated = jest.fn()
|
||||
.mockResolvedValue([
|
||||
[],
|
||||
0,
|
||||
]);
|
||||
|
||||
await EffectHelper.GenerateEffectEmbed("userId", 1);
|
||||
});
|
||||
|
||||
test("EXPECT UserEffect.FetchAllByUserIdPaginated to be called", () => {
|
||||
expect(UserEffect.FetchAllByUserIdPaginated).toHaveBeenCalledTimes(1);
|
||||
expect(UserEffect.FetchAllByUserIdPaginated).toHaveBeenCalledWith("userId", 0, 10);
|
||||
});
|
||||
|
||||
describe("GIVEN there are no effects returned", () => {
|
||||
let result: {
|
||||
embed: EmbedBuilder,
|
||||
row: ActionRowBuilder<ButtonBuilder>,
|
||||
};
|
||||
|
||||
beforeEach(async () => {
|
||||
UserEffect.FetchAllByUserIdPaginated = jest.fn()
|
||||
.mockResolvedValue([
|
||||
[],
|
||||
0,
|
||||
]);
|
||||
|
||||
result = await EffectHelper.GenerateEffectEmbed("userId", 1);
|
||||
});
|
||||
|
||||
test("EXPECT result returned", () => {
|
||||
expect(result).toMatchSnapshot();
|
||||
});
|
||||
});
|
||||
|
||||
describe("GIVEN there are effects returned", () => {
|
||||
let result: {
|
||||
embed: EmbedBuilder,
|
||||
row: ActionRowBuilder<ButtonBuilder>,
|
||||
};
|
||||
|
||||
beforeEach(async () => {
|
||||
UserEffect.FetchAllByUserIdPaginated = jest.fn()
|
||||
.mockResolvedValue([
|
||||
[
|
||||
{
|
||||
Name: "name",
|
||||
Unused: 1,
|
||||
},
|
||||
],
|
||||
1,
|
||||
]);
|
||||
|
||||
result = await EffectHelper.GenerateEffectEmbed("userId", 1);
|
||||
});
|
||||
|
||||
test("EXPECT result returned", () => {
|
||||
expect(result).toMatchSnapshot();
|
||||
});
|
||||
|
||||
describe("AND it is the first page", () => {
|
||||
beforeEach(async () => {
|
||||
result = await EffectHelper.GenerateEffectEmbed("userId", 1)
|
||||
});
|
||||
|
||||
test("EXPECT Previous button to be disabled", () => {
|
||||
const button = result.row.components[0].data as unknown as {
|
||||
label: string,
|
||||
disabled: boolean
|
||||
};
|
||||
|
||||
expect(button).toBeDefined();
|
||||
expect(button.label).toBe("Previous");
|
||||
expect(button.disabled).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe("AND it is the last page", () => {
|
||||
beforeEach(async () => {
|
||||
result = await EffectHelper.GenerateEffectEmbed("userId", 1)
|
||||
});
|
||||
|
||||
test("EXPECT Next button to be disabled", () => {
|
||||
const button = result.row.components[1].data as unknown as {
|
||||
label: string,
|
||||
disabled: boolean
|
||||
};
|
||||
|
||||
expect(button).toBeDefined();
|
||||
expect(button.label).toBe("Next");
|
||||
expect(button.disabled).toBe(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
|
@ -1,71 +0,0 @@
|
|||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`GenerateEffectEmbed GIVEN there are effects returned EXPECT result returned 1`] = `
|
||||
{
|
||||
"embed": {
|
||||
"color": 3166394,
|
||||
"description": "name x1",
|
||||
"footer": {
|
||||
"icon_url": undefined,
|
||||
"text": "Page 1 of 1",
|
||||
},
|
||||
"title": "Effects",
|
||||
},
|
||||
"row": {
|
||||
"components": [
|
||||
{
|
||||
"custom_id": "effects list 0",
|
||||
"disabled": true,
|
||||
"emoji": undefined,
|
||||
"label": "Previous",
|
||||
"style": 1,
|
||||
"type": 2,
|
||||
},
|
||||
{
|
||||
"custom_id": "effects list 2",
|
||||
"disabled": true,
|
||||
"emoji": undefined,
|
||||
"label": "Next",
|
||||
"style": 1,
|
||||
"type": 2,
|
||||
},
|
||||
],
|
||||
"type": 1,
|
||||
},
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`GenerateEffectEmbed GIVEN there are no effects returned EXPECT result returned 1`] = `
|
||||
{
|
||||
"embed": {
|
||||
"color": 3166394,
|
||||
"description": "*none*",
|
||||
"footer": {
|
||||
"icon_url": undefined,
|
||||
"text": "Page 1 of 1",
|
||||
},
|
||||
"title": "Effects",
|
||||
},
|
||||
"row": {
|
||||
"components": [
|
||||
{
|
||||
"custom_id": "effects list 0",
|
||||
"disabled": true,
|
||||
"emoji": undefined,
|
||||
"label": "Previous",
|
||||
"style": 1,
|
||||
"type": 2,
|
||||
},
|
||||
{
|
||||
"custom_id": "effects list 2",
|
||||
"disabled": true,
|
||||
"emoji": undefined,
|
||||
"label": "Next",
|
||||
"style": 1,
|
||||
"type": 2,
|
||||
},
|
||||
],
|
||||
"type": 1,
|
||||
},
|
||||
}
|
||||
`;
|
Loading…
Reference in a new issue