This commit is contained in:
parent
e557540d70
commit
1f5965ae79
4 changed files with 238 additions and 7 deletions
|
@ -0,0 +1,69 @@
|
||||||
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||||
|
|
||||||
|
exports[`constructor EXPECT CommandBuilder to be defined correctly 1`] = `
|
||||||
|
{
|
||||||
|
"contexts": undefined,
|
||||||
|
"default_member_permissions": undefined,
|
||||||
|
"default_permission": undefined,
|
||||||
|
"description": "View and create moons",
|
||||||
|
"description_localizations": undefined,
|
||||||
|
"dm_permission": undefined,
|
||||||
|
"integration_types": undefined,
|
||||||
|
"name": "moons",
|
||||||
|
"name_localizations": undefined,
|
||||||
|
"nsfw": undefined,
|
||||||
|
"options": [
|
||||||
|
{
|
||||||
|
"description": "List moons you have obtained",
|
||||||
|
"description_localizations": undefined,
|
||||||
|
"name": "list",
|
||||||
|
"name_localizations": undefined,
|
||||||
|
"options": [
|
||||||
|
{
|
||||||
|
"description": "The user to view (Defaults to yourself)",
|
||||||
|
"description_localizations": undefined,
|
||||||
|
"name": "user",
|
||||||
|
"name_localizations": undefined,
|
||||||
|
"required": false,
|
||||||
|
"type": 6,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"autocomplete": undefined,
|
||||||
|
"choices": undefined,
|
||||||
|
"description": "The page to start with",
|
||||||
|
"description_localizations": undefined,
|
||||||
|
"max_value": undefined,
|
||||||
|
"min_value": undefined,
|
||||||
|
"name": "page",
|
||||||
|
"name_localizations": undefined,
|
||||||
|
"required": false,
|
||||||
|
"type": 10,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
"type": 1,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"description": "Add a moon to your count!",
|
||||||
|
"description_localizations": undefined,
|
||||||
|
"name": "add",
|
||||||
|
"name_localizations": undefined,
|
||||||
|
"options": [
|
||||||
|
{
|
||||||
|
"autocomplete": undefined,
|
||||||
|
"choices": undefined,
|
||||||
|
"description": "What deserved a moon?",
|
||||||
|
"description_localizations": undefined,
|
||||||
|
"max_length": undefined,
|
||||||
|
"min_length": undefined,
|
||||||
|
"name": "description",
|
||||||
|
"name_localizations": undefined,
|
||||||
|
"required": true,
|
||||||
|
"type": 3,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
"type": 1,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
"type": 1,
|
||||||
|
}
|
||||||
|
`;
|
|
@ -1,17 +1,113 @@
|
||||||
|
import { ChatInputCommandInteraction, CommandInteraction } from "discord.js";
|
||||||
|
import Moons from "../../../src/commands/304276391837302787/moons";
|
||||||
|
import * as AddMoon from "../../../src/commands/304276391837302787/moons/add";
|
||||||
|
import * as ListMoons from "../../../src/commands/304276391837302787/moons/list";
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
jest.resetAllMocks();
|
||||||
|
});
|
||||||
|
|
||||||
describe("constructor", () => {
|
describe("constructor", () => {
|
||||||
test.todo("EXPECT CommandBuilder to be defined correctly");
|
let moons: Moons;
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
moons = new Moons();
|
||||||
|
});
|
||||||
|
|
||||||
|
test("EXPECT CommandBuilder to be defined correctly", () => {
|
||||||
|
expect(moons.CommandBuilder).toMatchSnapshot();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("execute", () => {
|
describe("execute", () => {
|
||||||
describe("GIVEN interaction is not a chat input command", () => {
|
describe("GIVEN interaction is not a chat input command", () => {
|
||||||
test.todo("EXPECT nothing to happen");
|
const moons = new Moons();
|
||||||
|
|
||||||
|
let interaction: CommandInteraction;
|
||||||
|
|
||||||
|
let listMoonsSpy: jest.SpyInstance;
|
||||||
|
let addMoonSpy: jest.SpyInstance;
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
listMoonsSpy = jest.spyOn(ListMoons, "default");
|
||||||
|
addMoonSpy = jest.spyOn(AddMoon, "default");
|
||||||
|
|
||||||
|
interaction = {
|
||||||
|
isChatInputCommand: jest.fn().mockReturnValue(false),
|
||||||
|
} as unknown as CommandInteraction;
|
||||||
|
|
||||||
|
await moons.execute(interaction);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("EXPECT interaction.isChatInputCommand to have been called", () => {
|
||||||
|
expect(interaction.isChatInputCommand).toHaveBeenCalledTimes(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("EXPECT nothing to happen", () => {
|
||||||
|
expect(listMoonsSpy).not.toHaveBeenCalled();
|
||||||
|
expect(addMoonSpy).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("GIVEN interaction subcommand is list", () => {
|
describe("GIVEN interaction subcommand is list", () => {
|
||||||
test.todo("EXPECT ListMoons to be called");
|
const moons = new Moons();
|
||||||
|
|
||||||
|
let interaction: ChatInputCommandInteraction;
|
||||||
|
|
||||||
|
let listMoonsSpy: jest.SpyInstance;
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
listMoonsSpy = jest.spyOn(ListMoons, "default")
|
||||||
|
.mockImplementation();
|
||||||
|
|
||||||
|
interaction = {
|
||||||
|
isChatInputCommand: jest.fn().mockReturnValue(true),
|
||||||
|
options: {
|
||||||
|
getSubcommand: jest.fn().mockReturnValue("list"),
|
||||||
|
},
|
||||||
|
} as unknown as ChatInputCommandInteraction;
|
||||||
|
|
||||||
|
await moons.execute(interaction);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("EXPECT interaction.options.getSubcommand to have been called", () => {
|
||||||
|
expect(interaction.options.getSubcommand).toHaveBeenCalledTimes(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("EXPECT ListMoons to be called", () => {
|
||||||
|
expect(listMoonsSpy).toHaveBeenCalledTimes(1);
|
||||||
|
expect(listMoonsSpy).toHaveBeenCalledWith(interaction);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("GIVEN interaction subcommand is add", () => {
|
describe("GIVEN interaction subcommand is add", () => {
|
||||||
test.todo("EXPECT AddMoon to be called");
|
const moons = new Moons();
|
||||||
|
|
||||||
|
let interaction: ChatInputCommandInteraction;
|
||||||
|
|
||||||
|
let addMoonSpy: jest.SpyInstance;
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
addMoonSpy = jest.spyOn(AddMoon, "default")
|
||||||
|
.mockImplementation();
|
||||||
|
|
||||||
|
interaction = {
|
||||||
|
isChatInputCommand: jest.fn().mockReturnValue(true),
|
||||||
|
options: {
|
||||||
|
getSubcommand: jest.fn().mockReturnValue("add"),
|
||||||
|
},
|
||||||
|
} as unknown as ChatInputCommandInteraction;
|
||||||
|
|
||||||
|
await moons.execute(interaction);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("EXPECT interaction.options.getSubcommand to have been called", () => {
|
||||||
|
expect(interaction.options.getSubcommand).toHaveBeenCalledTimes(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("EXPECT AddMoon to be called", () => {
|
||||||
|
expect(addMoonSpy).toHaveBeenCalledTimes(1);
|
||||||
|
expect(addMoonSpy).toHaveBeenCalledWith(interaction);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
|
@ -1,11 +1,65 @@
|
||||||
|
import AppDataSource from "../../../src/database/dataSources/appDataSource";
|
||||||
|
import UserSetting from "../../../src/database/entities/UserSetting";
|
||||||
|
|
||||||
describe("constructor", () => {
|
describe("constructor", () => {
|
||||||
test.todo("EXPECT settings to be configured");
|
let userSetting: UserSetting;
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
userSetting = new UserSetting("userId", "key", "value");
|
||||||
|
});
|
||||||
|
|
||||||
|
test("EXPECT settings to be configured", () => {
|
||||||
|
expect(userSetting).toMatchSnapshot({
|
||||||
|
Id: expect.any(String),
|
||||||
|
WhenCreated: expect.any(Date),
|
||||||
|
WhenUpdated: expect.any(Date),
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("UpdateValue", () => {
|
describe("UpdateValue", () => {
|
||||||
test.todo("EXPECT value to be updated");
|
let userSetting: UserSetting;
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
userSetting = new UserSetting("userId", "key", "value");
|
||||||
|
|
||||||
|
userSetting.UpdateValue("newValue");
|
||||||
|
});
|
||||||
|
|
||||||
|
test("EXPECT value to be updated", () => {
|
||||||
|
expect(userSetting.Value).toBe("newValue");
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("FetchOneByKey", () => {
|
describe("FetchOneByKey", () => {
|
||||||
test.todo("EXPECT single entity returned");
|
let result: UserSetting | null;
|
||||||
|
let userSetting: UserSetting;
|
||||||
|
|
||||||
|
let findOneMock: jest.Mock;
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
userSetting = new UserSetting("userId", "key", "value");
|
||||||
|
|
||||||
|
findOneMock = jest.fn().mockResolvedValue(userSetting);
|
||||||
|
|
||||||
|
AppDataSource.getRepository = jest.fn().mockReturnValue({
|
||||||
|
findOne: findOneMock,
|
||||||
|
});
|
||||||
|
|
||||||
|
result = await UserSetting.FetchOneByKey("userId", "key");
|
||||||
|
});
|
||||||
|
|
||||||
|
test("EXPECT getRepository to have been called", () => {
|
||||||
|
expect(AppDataSource.getRepository).toHaveBeenCalledTimes(1);
|
||||||
|
expect(AppDataSource.getRepository).toHaveBeenCalledWith(UserSetting);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("EXPECT repository.findOne to have been called", () => {
|
||||||
|
expect(findOneMock).toHaveBeenCalledTimes(1);
|
||||||
|
expect(findOneMock).toHaveBeenCalledWith({ where: { UserId: "userId", Key: "key" }, relations: {}});
|
||||||
|
})
|
||||||
|
|
||||||
|
test("EXPECT single entity returned", () => {
|
||||||
|
expect(result).toBe(userSetting);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -0,0 +1,12 @@
|
||||||
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||||
|
|
||||||
|
exports[`constructor EXPECT settings to be configured 1`] = `
|
||||||
|
{
|
||||||
|
"Id": Any<String>,
|
||||||
|
"Key": "key",
|
||||||
|
"UserId": "userId",
|
||||||
|
"Value": "value",
|
||||||
|
"WhenCreated": Any<Date>,
|
||||||
|
"WhenUpdated": Any<Date>,
|
||||||
|
}
|
||||||
|
`;
|
Loading…
Reference in a new issue