Create add lobby tests
This commit is contained in:
parent
ca64ede1ad
commit
53a084b3b1
2 changed files with 339 additions and 12 deletions
|
@ -1,5 +1,6 @@
|
|||
import { PermissionsBitField, SlashCommandBuilder, SlashCommandChannelOption, SlashCommandNumberOption, SlashCommandRoleOption, SlashCommandStringOption } from "discord.js";
|
||||
import { CommandInteraction, PermissionsBitField, SlashCommandBuilder, SlashCommandChannelOption, SlashCommandNumberOption, SlashCommandRoleOption, SlashCommandStringOption } from "discord.js";
|
||||
import Add from "../../../../src/commands/501231711271780357/Lobby/add";
|
||||
import Lobby from "../../../../src/database/entities/501231711271780357/Lobby";
|
||||
|
||||
describe('constuctor', () => {
|
||||
test("EXPECT properties to be set", () => {
|
||||
|
@ -42,23 +43,349 @@ describe('constuctor', () => {
|
|||
});
|
||||
|
||||
describe('execute', () => {
|
||||
test.todo("EXPECT channel to be added to the lobby database table");
|
||||
test("EXPECT channel to be added to the lobby database table", async () => {
|
||||
const channel = {
|
||||
channel: {
|
||||
id: "channelId",
|
||||
},
|
||||
name: "channelName",
|
||||
};
|
||||
const role = {
|
||||
role: {},
|
||||
name: "roleName",
|
||||
};
|
||||
const cooldown = {
|
||||
value: "5",
|
||||
};
|
||||
const gameName = {
|
||||
value: "test",
|
||||
};
|
||||
|
||||
test.todo("GIVEN channel is null, EXPECT error");
|
||||
const interaction = {
|
||||
options: {
|
||||
get: jest.fn()
|
||||
.mockReturnValueOnce(channel)
|
||||
.mockReturnValueOnce(role)
|
||||
.mockReturnValueOnce(cooldown)
|
||||
.mockReturnValueOnce(gameName),
|
||||
},
|
||||
reply: jest.fn(),
|
||||
} as unknown as CommandInteraction;
|
||||
|
||||
test.todo("GIVEN channel.channel is undefined, EXPECT error");
|
||||
Lobby.FetchOneByChannelId = jest.fn().mockReturnValue(null);
|
||||
Lobby.prototype.Save = jest.fn();
|
||||
|
||||
test.todo("GIVEN role is null, EXPECT error");
|
||||
const add = new Add();
|
||||
await add.execute(interaction);
|
||||
|
||||
test.todo("GIVEN role.role is undefined, EXPECT error");
|
||||
expect(interaction.options.get).toHaveBeenCalledTimes(4);
|
||||
expect(interaction.options.get).toHaveBeenCalledWith("channel");
|
||||
expect(interaction.options.get).toHaveBeenCalledWith("role");
|
||||
expect(interaction.options.get).toHaveBeenCalledWith("cooldown");
|
||||
expect(interaction.options.get).toHaveBeenCalledWith("name");
|
||||
|
||||
test.todo("GIVEN cooldown is null, EXPECT error");
|
||||
expect(Lobby.FetchOneByChannelId).toHaveBeenCalledTimes(1);
|
||||
expect(Lobby.FetchOneByChannelId).toHaveBeenCalledWith("channelId");
|
||||
|
||||
test.todo("GIVEN cooldown.value is undefined, EXPECT error");
|
||||
expect(Lobby.prototype.Save).toHaveBeenCalledTimes(1);
|
||||
|
||||
test.todo("GIVEN gameName is null, EXPECT error");
|
||||
|
||||
test.todo("GIVEN gameName.value is undefined, EXPECT error");
|
||||
|
||||
test.todo("GIVEN channel has already been set up in the database, EXPECT error");
|
||||
expect(interaction.reply).toHaveBeenCalledTimes(1);
|
||||
expect(interaction.reply).toHaveBeenCalledWith("Added `channelName` as a new lobby channel with a cooldown of `5 minutes` and will ping `roleName` on use");
|
||||
});
|
||||
|
||||
test("GIVEN channel is null, EXPECT error", async () => {
|
||||
const channel = null;
|
||||
const role = {
|
||||
role: {},
|
||||
name: "roleName",
|
||||
};
|
||||
const cooldown = {
|
||||
value: "5",
|
||||
};
|
||||
const gameName = {
|
||||
value: "test",
|
||||
};
|
||||
|
||||
const interaction = {
|
||||
options: {
|
||||
get: jest.fn()
|
||||
.mockReturnValueOnce(channel)
|
||||
.mockReturnValueOnce(role)
|
||||
.mockReturnValueOnce(cooldown)
|
||||
.mockReturnValueOnce(gameName),
|
||||
},
|
||||
reply: jest.fn(),
|
||||
} as unknown as CommandInteraction;
|
||||
|
||||
const add = new Add();
|
||||
await add.execute(interaction);
|
||||
|
||||
expect(interaction.reply).toHaveBeenCalledTimes(1);
|
||||
expect(interaction.reply).toHaveBeenCalledWith("Fields are required.");
|
||||
});
|
||||
|
||||
test("GIVEN channel.channel is undefined, EXPECT error", async () => {
|
||||
const channel = {
|
||||
channel: undefined,
|
||||
};
|
||||
const role = {
|
||||
role: {},
|
||||
name: "roleName",
|
||||
};
|
||||
const cooldown = {
|
||||
value: "5",
|
||||
};
|
||||
const gameName = {
|
||||
value: "test",
|
||||
};
|
||||
|
||||
const interaction = {
|
||||
options: {
|
||||
get: jest.fn()
|
||||
.mockReturnValueOnce(channel)
|
||||
.mockReturnValueOnce(role)
|
||||
.mockReturnValueOnce(cooldown)
|
||||
.mockReturnValueOnce(gameName),
|
||||
},
|
||||
reply: jest.fn(),
|
||||
} as unknown as CommandInteraction;
|
||||
|
||||
const add = new Add();
|
||||
await add.execute(interaction);
|
||||
|
||||
expect(interaction.reply).toHaveBeenCalledTimes(1);
|
||||
expect(interaction.reply).toHaveBeenCalledWith("Fields are required.");
|
||||
});
|
||||
|
||||
test("GIVEN role is null, EXPECT error", async () => {
|
||||
const channel = {
|
||||
channel: {},
|
||||
};
|
||||
const role = null;
|
||||
const cooldown = {
|
||||
value: "5",
|
||||
};
|
||||
const gameName = {
|
||||
value: "test",
|
||||
};
|
||||
|
||||
const interaction = {
|
||||
options: {
|
||||
get: jest.fn()
|
||||
.mockReturnValueOnce(channel)
|
||||
.mockReturnValueOnce(role)
|
||||
.mockReturnValueOnce(cooldown)
|
||||
.mockReturnValueOnce(gameName),
|
||||
},
|
||||
reply: jest.fn(),
|
||||
} as unknown as CommandInteraction;
|
||||
|
||||
const add = new Add();
|
||||
await add.execute(interaction);
|
||||
|
||||
expect(interaction.reply).toHaveBeenCalledTimes(1);
|
||||
expect(interaction.reply).toHaveBeenCalledWith("Fields are required.");
|
||||
});
|
||||
|
||||
test("GIVEN role.role is undefined, EXPECT error", async () => {
|
||||
const channel = {
|
||||
channel: {},
|
||||
};
|
||||
const role = {
|
||||
role: undefined
|
||||
};
|
||||
const cooldown = {
|
||||
value: "5",
|
||||
};
|
||||
const gameName = {
|
||||
value: "test",
|
||||
};
|
||||
|
||||
const interaction = {
|
||||
options: {
|
||||
get: jest.fn()
|
||||
.mockReturnValueOnce(channel)
|
||||
.mockReturnValueOnce(role)
|
||||
.mockReturnValueOnce(cooldown)
|
||||
.mockReturnValueOnce(gameName),
|
||||
},
|
||||
reply: jest.fn(),
|
||||
} as unknown as CommandInteraction;
|
||||
|
||||
const add = new Add();
|
||||
await add.execute(interaction);
|
||||
|
||||
expect(interaction.reply).toHaveBeenCalledTimes(1);
|
||||
expect(interaction.reply).toHaveBeenCalledWith("Fields are required.");
|
||||
});
|
||||
|
||||
test("GIVEN cooldown is null, EXPECT error", async () => {
|
||||
const channel = {
|
||||
channel: {},
|
||||
};
|
||||
const role = {
|
||||
role: {},
|
||||
name: "roleName",
|
||||
};
|
||||
const cooldown = null;
|
||||
const gameName = {
|
||||
value: "test",
|
||||
};
|
||||
|
||||
const interaction = {
|
||||
options: {
|
||||
get: jest.fn()
|
||||
.mockReturnValueOnce(channel)
|
||||
.mockReturnValueOnce(role)
|
||||
.mockReturnValueOnce(cooldown)
|
||||
.mockReturnValueOnce(gameName),
|
||||
},
|
||||
reply: jest.fn(),
|
||||
} as unknown as CommandInteraction;
|
||||
|
||||
const add = new Add();
|
||||
await add.execute(interaction);
|
||||
|
||||
expect(interaction.reply).toHaveBeenCalledTimes(1);
|
||||
expect(interaction.reply).toHaveBeenCalledWith("Fields are required.");
|
||||
});
|
||||
|
||||
test("GIVEN cooldown.value is undefined, EXPECT error", async () => {
|
||||
const channel = {
|
||||
channel: {},
|
||||
};
|
||||
const role = {
|
||||
role: {},
|
||||
name: "roleName",
|
||||
};
|
||||
const cooldown = {
|
||||
value: undefined,
|
||||
};
|
||||
const gameName = {
|
||||
value: "test",
|
||||
};
|
||||
|
||||
const interaction = {
|
||||
options: {
|
||||
get: jest.fn()
|
||||
.mockReturnValueOnce(channel)
|
||||
.mockReturnValueOnce(role)
|
||||
.mockReturnValueOnce(cooldown)
|
||||
.mockReturnValueOnce(gameName),
|
||||
},
|
||||
reply: jest.fn(),
|
||||
} as unknown as CommandInteraction;
|
||||
|
||||
const add = new Add();
|
||||
await add.execute(interaction);
|
||||
|
||||
expect(interaction.reply).toHaveBeenCalledTimes(1);
|
||||
expect(interaction.reply).toHaveBeenCalledWith("Fields are required.");
|
||||
});
|
||||
|
||||
test("GIVEN gameName is null, EXPECT error", async () => {
|
||||
const channel = {
|
||||
channel: {},
|
||||
};
|
||||
const role = {
|
||||
role: {},
|
||||
name: "roleName",
|
||||
};
|
||||
const cooldown = {
|
||||
value: "5",
|
||||
};
|
||||
const gameName = null;
|
||||
|
||||
const interaction = {
|
||||
options: {
|
||||
get: jest.fn()
|
||||
.mockReturnValueOnce(channel)
|
||||
.mockReturnValueOnce(role)
|
||||
.mockReturnValueOnce(cooldown)
|
||||
.mockReturnValueOnce(gameName),
|
||||
},
|
||||
reply: jest.fn(),
|
||||
} as unknown as CommandInteraction;
|
||||
|
||||
const add = new Add();
|
||||
await add.execute(interaction);
|
||||
|
||||
expect(interaction.reply).toHaveBeenCalledTimes(1);
|
||||
expect(interaction.reply).toHaveBeenCalledWith("Fields are required.");
|
||||
});
|
||||
|
||||
test("GIVEN gameName.value is undefined, EXPECT error", async () => {
|
||||
const channel = {
|
||||
channel: {},
|
||||
};
|
||||
const role = {
|
||||
role: {},
|
||||
name: "roleName",
|
||||
};
|
||||
const cooldown = {
|
||||
value: "5",
|
||||
};
|
||||
const gameName = {
|
||||
value: undefined,
|
||||
};
|
||||
|
||||
const interaction = {
|
||||
options: {
|
||||
get: jest.fn()
|
||||
.mockReturnValueOnce(channel)
|
||||
.mockReturnValueOnce(role)
|
||||
.mockReturnValueOnce(cooldown)
|
||||
.mockReturnValueOnce(gameName),
|
||||
},
|
||||
reply: jest.fn(),
|
||||
} as unknown as CommandInteraction;
|
||||
|
||||
const add = new Add();
|
||||
await add.execute(interaction);
|
||||
|
||||
expect(interaction.reply).toHaveBeenCalledTimes(1);
|
||||
expect(interaction.reply).toHaveBeenCalledWith("Fields are required.");
|
||||
});
|
||||
|
||||
test("GIVEN channel has already been set up in the database, EXPECT error", async () => {
|
||||
const channel = {
|
||||
channel: {
|
||||
id: "channelId",
|
||||
},
|
||||
name: "channelName",
|
||||
};
|
||||
const role = {
|
||||
role: {},
|
||||
name: "roleName",
|
||||
};
|
||||
const cooldown = {
|
||||
value: "5",
|
||||
};
|
||||
const gameName = {
|
||||
value: "test",
|
||||
};
|
||||
|
||||
const interaction = {
|
||||
options: {
|
||||
get: jest.fn()
|
||||
.mockReturnValueOnce(channel)
|
||||
.mockReturnValueOnce(role)
|
||||
.mockReturnValueOnce(cooldown)
|
||||
.mockReturnValueOnce(gameName),
|
||||
},
|
||||
reply: jest.fn(),
|
||||
} as unknown as CommandInteraction;
|
||||
|
||||
Lobby.FetchOneByChannelId = jest.fn().mockReturnValue({});
|
||||
Lobby.prototype.Save = jest.fn();
|
||||
|
||||
const add = new Add();
|
||||
await add.execute(interaction);
|
||||
|
||||
expect(interaction.reply).toHaveBeenCalledTimes(1);
|
||||
expect(interaction.reply).toHaveBeenCalledWith("This channel has already been setup.");
|
||||
|
||||
expect(Lobby.FetchOneByChannelId).toHaveBeenCalledTimes(1);
|
||||
expect(Lobby.prototype.Save).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
Loading…
Reference in a new issue