Compare commits

..

5 commits

Author SHA1 Message Date
ca64ede1ad WIP: Start of lobbyadd tests
All checks were successful
continuous-integration/drone/push Build is passing
2024-03-25 18:11:38 +00:00
fc975f4602 Create util tests 2024-03-25 17:59:34 +00:00
39b2a495a8 Merge branch 'develop' into feature/258-fix-tests 2024-03-25 17:35:23 +00:00
de5c744feb Update dependency np to v10 (#415)
All checks were successful
continuous-integration/drone/push Build is passing
This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [np](https://github.com/sindresorhus/np) | devDependencies | major | [`^9.0.0` -> `^10.0.0`](https://renovatebot.com/diffs/npm/np/9.2.0/10.0.2) |

---

### Release Notes

<details>
<summary>sindresorhus/np (np)</summary>

### [`v10.0.2`](https://github.com/sindresorhus/np/releases/tag/v10.0.2)

[Compare Source](https://github.com/sindresorhus/np/compare/v10.0.1...v10.0.2)

-   Use npm for tagging versions when pnpm is the chosen package manager ([#&#8203;739](https://github.com/sindresorhus/np/issues/739))  [`770418f`](https://github.com/sindresorhus/np/commit/770418f)

### [`v10.0.1`](https://github.com/sindresorhus/np/releases/tag/v10.0.1)

[Compare Source](https://github.com/sindresorhus/np/compare/v10.0.0...v10.0.1)

-   Fix compatibility with npm 10 ([#&#8203;737](https://github.com/sindresorhus/np/issues/737))  [`9fdebd5`](https://github.com/sindresorhus/np/commit/9fdebd5)

### [`v10.0.0`](https://github.com/sindresorhus/np/releases/tag/v10.0.0)

[Compare Source](https://github.com/sindresorhus/np/compare/v9.2.0...v10.0.0)

##### Breaking

-   Remove the `--yarn` flag ([#&#8203;730](https://github.com/sindresorhus/np/issues/730))  [`4b3b599`](https://github.com/sindresorhus/np/commit/4b3b599)
    -   The functionality is replaced by `--package-manager`. See below.

##### Improvements

-   Add `--package-manager` flag ([#&#8203;730](https://github.com/sindresorhus/np/issues/730))  [`4b3b599`](https://github.com/sindresorhus/np/commit/4b3b599)
    -   This acts like the [`packageManager` field](https://nodejs.org/api/packages.html#packagemanager) in package.json. `np` will default to reading package.json, and look for lockfiles to determine the best package manager as a last resort.
-   Add pnpm support ([#&#8203;730](https://github.com/sindresorhus/np/issues/730))  [`4b3b599`](https://github.com/sindresorhus/np/commit/4b3b599)

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box

---

This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy4wLjAiLCJ1cGRhdGVkSW5WZXIiOiIzNy4wLjAiLCJ0YXJnZXRCcmFuY2giOiJkZXZlbG9wIn0=-->

Reviewed-on: https://gitea.vylpes.xyz/RabbitLabs/vylbot-app/pulls/415
Co-authored-by: Renovate Bot <renovate@vylpes.com>
Co-committed-by: Renovate Bot <renovate@vylpes.com>
2024-03-25 17:32:59 +00:00
a7f8abb8d4 Update dependency @types/node to v20.11.30 (#410)
All checks were successful
continuous-integration/drone/push Build is passing
This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [@types/node](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/node) ([source](https://github.com/DefinitelyTyped/DefinitelyTyped)) | devDependencies | patch | [`20.11.10` -> `20.11.30`](https://renovatebot.com/diffs/npm/@types%2fnode/20.11.10/20.11.30) |

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box

---

This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy4wLjAiLCJ1cGRhdGVkSW5WZXIiOiIzNy4wLjAiLCJ0YXJnZXRCcmFuY2giOiJkZXZlbG9wIn0=-->

Reviewed-on: https://gitea.vylpes.xyz/RabbitLabs/vylbot-app/pulls/410
Co-authored-by: Renovate Bot <renovate@vylpes.com>
Co-committed-by: Renovate Bot <renovate@vylpes.com>
2024-03-25 17:32:16 +00:00
4 changed files with 484 additions and 464 deletions

View file

@ -47,7 +47,7 @@
},
"devDependencies": {
"@types/node": "^20.0.0",
"np": "^9.0.0",
"np": "^10.0.0",
"typescript": "^5.0.0"
}
}

View file

@ -1,27 +1,9 @@
import { Client, SlashCommandBuilder } from "discord.js";
import discordjs, { Client, REST, Routes, SlashCommandBuilder } from "discord.js";
import { Util } from "../../src/client/util";
import { CoreClient } from "../../src/client/client";
import { Command } from "../../src/type/command";
jest.mock("discord.js", () => {
return {
Client: jest.fn(),
REST: jest.fn().mockImplementation(() => {
return {
v10: {
put: jest.fn(),
},
setToken: jest.fn(),
}
}),
Routes: {
applicationCommands: jest.fn().mockReturnValue("command url"),
applicationGuildCommands: jest.fn().mockReturnValue("guild command url"),
},
}
});
import { REST, Routes } from "discord.js";
import IEventItem from "../../src/contracts/IEventItem";
import { EventType } from "../../src/constants/EventType";
beforeEach(() => {
jest.resetAllMocks();
@ -43,6 +25,15 @@ describe("loadSlashCommands", () => {
}
} as unknown as Client;
const setTokenPutMock = jest.fn();
const setTokenMock = jest.fn().mockReturnValue({
put: setTokenPutMock,
});
REST.prototype.setToken = setTokenMock;
Routes.applicationCommands = jest.fn().mockReturnValue("command url");
Routes.applicationGuildCommands = jest.fn().mockReturnValue("guild command url");
CoreClient.commandItems = [
{
Name: "global",
@ -66,12 +57,11 @@ describe("loadSlashCommands", () => {
const util = new Util();
util.loadSlashCommands(client);
expect(REST).toHaveBeenCalledWith({ version: '10' });
expect(REST.prototype.setToken).toHaveBeenCalledWith("token");
expect(setTokenMock).toHaveBeenCalledWith("token");
expect(REST.prototype.put).toHaveBeenCalledTimes(2);
expect(REST.prototype.put).toHaveBeenCalledWith("command url", { body: [ CoreClient.commandItems[0].Command.CommandBuilder ] });
expect(REST.prototype.put).toHaveBeenCalledWith("guild command url", { body: [ CoreClient.commandItems[1].Command.CommandBuilder ]});
expect(setTokenPutMock).toHaveBeenCalledTimes(2);
expect(setTokenPutMock).toHaveBeenCalledWith("command url", { body: [ CoreClient.commandItems[0].Command.CommandBuilder ] });
expect(setTokenPutMock).toHaveBeenCalledWith("guild command url", { body: [ CoreClient.commandItems[1].Command.CommandBuilder ]});
expect(client.guilds.cache.has).toHaveBeenCalledTimes(1);
expect(client.guilds.cache.has).toHaveBeenCalledWith("123");
@ -83,31 +73,261 @@ describe("loadSlashCommands", () => {
expect(Routes.applicationGuildCommands).toHaveBeenCalledWith("clientid", "123");
});
test.todo("GIVEN bot is not in a guild for a server command, EXPECT this to be ignored");
test("GIVEN bot is not in a guild for a server command, EXPECT this to be ignored", () => {
process.env.BOT_TOKEN = "token";
process.env.BOT_CLIENTID = "clientid";
const client = {
guilds: {
cache: {
has: jest.fn().mockReturnValue(false),
}
}
} as unknown as Client;
const setTokenPutMock = jest.fn();
const setTokenMock = jest.fn().mockReturnValue({
put: setTokenPutMock,
});
REST.prototype.setToken = setTokenMock;
Routes.applicationCommands = jest.fn().mockReturnValue("command url");
Routes.applicationGuildCommands = jest.fn().mockReturnValue("guild command url");
CoreClient.commandItems = [
{
Name: "server-specific",
Command: {
CommandBuilder: {
name: "server",
} as SlashCommandBuilder,
} as Command,
ServerId: "123",
}
];
const util = new Util();
util.loadSlashCommands(client);
expect(Routes.applicationGuildCommands).not.toHaveBeenCalled();
});
});
describe("loadEvents", () => {
test.todo("GIVEN event type is channelCreate, EXPECT event function to be executed");
test("GIVEN event type is channelCreate, EXPECT event function to be executed", () => {
const client = {
on: jest.fn(),
} as unknown as Client;
const events: IEventItem[] = [
{
EventType: EventType.ChannelCreate,
ExecutionFunction: jest.fn(),
}
];
test.todo("GIVEN event type is channelDelete, EXPECT event function to be executed");
const util = new Util();
util.loadEvents(client, events);
test.todo("GIVEN event type is channelUpdate, EXPECT event function to be executed");
expect(client.on).toHaveBeenCalledTimes(1);
expect(client.on).toHaveBeenCalledWith("channelCreate", expect.any(Function));
});
test.todo("GIVEN event type is guildBanAdd, EXPECT event function to be executed");
test("GIVEN event type is channelDelete, EXPECT event function to be executed", () => {
const client = {
on: jest.fn(),
} as unknown as Client;
const events: IEventItem[] = [
{
EventType: EventType.ChannelDelete,
ExecutionFunction: jest.fn(),
}
];
test.todo("GIVEN event type is guildBanRemove, EXPECT event function to be executed");
const util = new Util();
util.loadEvents(client, events);
test.todo("GIVEN event type is guildCreate, EXPECT event function to be executed");
expect(client.on).toHaveBeenCalledTimes(1);
expect(client.on).toHaveBeenCalledWith("channelDelete", expect.any(Function));
});
test.todo("GIVEN event type is guildMemberAdd, EXPECT event function to be executed");
test("GIVEN event type is channelUpdate, EXPECT event function to be executed", () => {
const client = {
on: jest.fn(),
} as unknown as Client;
const events: IEventItem[] = [
{
EventType: EventType.ChannelUpdate,
ExecutionFunction: jest.fn(),
}
];
test.todo("GIVEN event type is guildMemberRemove, EXPECT event function to be executed");
const util = new Util();
util.loadEvents(client, events);
test.todo("GIVEN event type is messageCreate, EXPECT event function to be executed");
expect(client.on).toHaveBeenCalledTimes(1);
expect(client.on).toHaveBeenCalledWith("channelUpdate", expect.any(Function));
});
test.todo("GIVEN event type is messageDelete, EXPECT event function to be executed");
test("GIVEN event type is guildBanAdd, EXPECT event function to be executed", () => {
const client = {
on: jest.fn(),
} as unknown as Client;
const events: IEventItem[] = [
{
EventType: EventType.GuildBanAdd,
ExecutionFunction: jest.fn(),
}
];
test.todo("GIVEN event type is messageUpdate, EXPECT event function to be executed");
const util = new Util();
util.loadEvents(client, events);
test.todo("GIVEN event type is not implemented, EXPECT error");
expect(client.on).toHaveBeenCalledTimes(1);
expect(client.on).toHaveBeenCalledWith("guildBanAdd", expect.any(Function));
});
test("GIVEN event type is guildBanRemove, EXPECT event function to be executed", () => {
const client = {
on: jest.fn(),
} as unknown as Client;
const events: IEventItem[] = [
{
EventType: EventType.GuildBanRemove,
ExecutionFunction: jest.fn(),
}
];
const util = new Util();
util.loadEvents(client, events);
expect(client.on).toHaveBeenCalledTimes(1);
expect(client.on).toHaveBeenCalledWith("guildBanRemove", expect.any(Function));
});
test("GIVEN event type is guildCreate, EXPECT event function to be executed", () => {
const client = {
on: jest.fn(),
} as unknown as Client;
const events: IEventItem[] = [
{
EventType: EventType.GuildCreate,
ExecutionFunction: jest.fn(),
}
];
const util = new Util();
util.loadEvents(client, events);
expect(client.on).toHaveBeenCalledTimes(1);
expect(client.on).toHaveBeenCalledWith("guildCreate", expect.any(Function));
});
test("GIVEN event type is guildMemberAdd, EXPECT event function to be executed", () => {
const client = {
on: jest.fn(),
} as unknown as Client;
const events: IEventItem[] = [
{
EventType: EventType.GuildMemberAdd,
ExecutionFunction: jest.fn(),
}
];
const util = new Util();
util.loadEvents(client, events);
expect(client.on).toHaveBeenCalledTimes(1);
expect(client.on).toHaveBeenCalledWith("guildMemberAdd", expect.any(Function));
});
test("GIVEN event type is guildMemberRemove, EXPECT event function to be executed", () => {
const client = {
on: jest.fn(),
} as unknown as Client;
const events: IEventItem[] = [
{
EventType: EventType.GuildMemberRemove,
ExecutionFunction: jest.fn(),
}
];
const util = new Util();
util.loadEvents(client, events);
expect(client.on).toHaveBeenCalledTimes(1);
expect(client.on).toHaveBeenCalledWith("guildMemberRemove", expect.any(Function));
});
test("GIVEN event type is messageCreate, EXPECT event function to be executed", () => {
const client = {
on: jest.fn(),
} as unknown as Client;
const events: IEventItem[] = [
{
EventType: EventType.MessageCreate,
ExecutionFunction: jest.fn(),
}
];
const util = new Util();
util.loadEvents(client, events);
expect(client.on).toHaveBeenCalledTimes(1);
expect(client.on).toHaveBeenCalledWith("messageCreate", expect.any(Function));
});
test("GIVEN event type is messageDelete, EXPECT event function to be executed", () => {
const client = {
on: jest.fn(),
} as unknown as Client;
const events: IEventItem[] = [
{
EventType: EventType.MessageDelete,
ExecutionFunction: jest.fn(),
}
];
const util = new Util();
util.loadEvents(client, events);
expect(client.on).toHaveBeenCalledTimes(1);
expect(client.on).toHaveBeenCalledWith("messageDelete", expect.any(Function));
});
test("GIVEN event type is messageUpdate, EXPECT event function to be executed", () => {
const client = {
on: jest.fn(),
} as unknown as Client;
const events: IEventItem[] = [
{
EventType: EventType.MessageUpdate,
ExecutionFunction: jest.fn(),
}
];
const util = new Util();
util.loadEvents(client, events);
expect(client.on).toHaveBeenCalledTimes(1);
expect(client.on).toHaveBeenCalledWith("messageUpdate", expect.any(Function));
});
test("GIVEN event type is not implemented, EXPECT error", () => {
const client = {
on: jest.fn(),
} as unknown as Client;
const events: IEventItem[] = [
{
EventType: EventType.Ready,
ExecutionFunction: jest.fn(),
}
];
console.error = jest.fn();
const util = new Util();
util.loadEvents(client, events);
expect(console.error).toHaveBeenCalledWith("Event not implemented.");
});
});

View file

@ -1,5 +1,44 @@
import { PermissionsBitField, SlashCommandBuilder, SlashCommandChannelOption, SlashCommandNumberOption, SlashCommandRoleOption, SlashCommandStringOption } from "discord.js";
import Add from "../../../../src/commands/501231711271780357/Lobby/add";
describe('constuctor', () => {
test.todo("EXPECT properties to be set");
test("EXPECT properties to be set", () => {
const add = new Add();
expect(add.CommandBuilder).toBeDefined();
const commandbuilder = add.CommandBuilder as SlashCommandBuilder;
expect(commandbuilder.name).toBe("addlobby");
expect(commandbuilder.description).toBe("Add lobby channel");
expect(commandbuilder.default_member_permissions).toBe(PermissionsBitField.Flags.ModerateMembers.toString());
expect(commandbuilder.options.length).toBe(4);
const channelOption = commandbuilder.options[0] as SlashCommandChannelOption;
expect(channelOption.name).toBe("channel");
expect(channelOption.description).toBe("The channel");
expect(channelOption.required).toBe(true);
const roleOption = commandbuilder.options[1] as SlashCommandRoleOption;
expect(roleOption.name).toBe("role");
expect(roleOption.description).toBe("The role to ping on request");
expect(roleOption.required).toBe(true);
const cooldownOption = commandbuilder.options[2] as SlashCommandNumberOption;
expect(cooldownOption.name).toBe("cooldown");
expect(cooldownOption.description).toBe("The cooldown in minutes");
expect(cooldownOption.required).toBe(true);
const nameOption = commandbuilder.options[3] as SlashCommandStringOption;
expect(nameOption.name).toBe("name");
expect(nameOption.description).toBe("The game name");
expect(nameOption.required).toBe(true);
});
});
describe('execute', () => {

607
yarn.lock

File diff suppressed because it is too large Load diff