From c39f9c6ee14b6700274ac60bf863afc8db2eb8c9 Mon Sep 17 00:00:00 2001 From: mightypanders Date: Sat, 24 Jun 2023 19:56:30 +0200 Subject: [PATCH] add first passing test --- tests/helpers/memberRoles.test.ts | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 tests/helpers/memberRoles.test.ts diff --git a/tests/helpers/memberRoles.test.ts b/tests/helpers/memberRoles.test.ts new file mode 100644 index 0000000..6ff3a9c --- /dev/null +++ b/tests/helpers/memberRoles.test.ts @@ -0,0 +1,28 @@ +import { Collection, GuildMember, Role } from "discord.js" +import { filterRolesFromMemberUpdate } from "../../server/helper/roleFilter" + +function buildFakeRole(id: string, name: string): Role { + return { id, name } + +} +test('filterRolesFromMemberUpdate', () => { + const oldMemberRoles: Collection = new Collection() + oldMemberRoles.set('1', buildFakeRole('01', 'Role01')) + oldMemberRoles.set('2', buildFakeRole('02', 'Role02')) + + const newMemberRoles: Collection = new Collection() + newMemberRoles.set('1', buildFakeRole('01', 'Role01')) + newMemberRoles.set('2', buildFakeRole('02', 'Role02')) + newMemberRoles.set('3', buildFakeRole('03', 'Role03')) + + const oldMember: GuildMember = { roles: { cache: oldMemberRoles }, guild: { id: "guildid" } } + const newMember: GuildMember = { roles: { cache: newMemberRoles }, guild: { id: "guildid" } } + const output = filterRolesFromMemberUpdate(oldMember, newMember) + + const expectedAddedRoles: Collection = new Collection() + expectedAddedRoles.set('3', buildFakeRole('03', 'Role03')) + const expectedRemovedRoles: Collection = new Collection() + + expect(output.addedRoles).toEqual(expectedAddedRoles) + expect(output.removedRoles).toEqual(expectedRemovedRoles) +})