From 974e298214d10da8309ba99bf0494018d6ebf392 Mon Sep 17 00:00:00 2001 From: Ethan Lane Date: Wed, 30 Oct 2024 09:35:34 +0000 Subject: [PATCH] WIP: Planning list.test.ts --- package.json | 2 +- src/buttonEvents/moons/list.ts | 6 ++-- tests/buttonEvents/moons/list.test.ts | 49 +++++++++++++++++++++++++++ 3 files changed, 53 insertions(+), 4 deletions(-) create mode 100644 tests/buttonEvents/moons/list.test.ts diff --git a/package.json b/package.json index 2434d78..620c7ce 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,7 @@ "clean": "rm -rf node_modules/ dist/", "build": "tsc", "start": "node ./dist/vylbot", - "test": "jest . --passWithNoTests", + "test": "jest .", "db:up": "typeorm migration:run -d dist/database/dataSources/appDataSource.js", "db:down": "typeorm migration:revert -d dist/database/dataSources/appDataSource.js", "db:create": "typeorm migration:create ./src/database/migrations", diff --git a/src/buttonEvents/moons/list.ts b/src/buttonEvents/moons/list.ts index 8c60779..8f8e45a 100644 --- a/src/buttonEvents/moons/list.ts +++ b/src/buttonEvents/moons/list.ts @@ -13,13 +13,13 @@ export default async function List(interaction: ButtonInteraction) { const pageNumber = Number(page); - const member = interaction.guild.members.cache.find(x => x.user.id == userId); + const member = interaction.guild.members.cache.find(x => x.user.id == userId) || await interaction.guild.members.fetch(userId); const pageLength = 10; const moons = await Moon.FetchPaginatedMoonsByUserId(userId, pageLength, pageNumber); - if (!moons || moons[0].length == 0) { + if (!moons) { await interaction.reply(`${member?.user.username ?? "This user"} does not have any moons or page is invalid.`); return; } @@ -43,7 +43,7 @@ export default async function List(interaction: ButtonInteraction) { } const embed = new EmbedBuilder() - .setTitle(`${member?.user.username}'s Moons`) + .setTitle(`${member.user.username}'s Moons`) .setColor(EmbedColours.Ok) .setDescription(description.join("\n")) .setFooter({ text: `Page ${pageNumber + 1} of ${totalPages} ยท ${totalMoons} moons` }); diff --git a/tests/buttonEvents/moons/list.test.ts b/tests/buttonEvents/moons/list.test.ts new file mode 100644 index 0000000..21c740d --- /dev/null +++ b/tests/buttonEvents/moons/list.test.ts @@ -0,0 +1,49 @@ +describe("GIVEN interation.guild is null", () => { + test.todo("EXPECT nothing to happen"); +}); + +describe("GIVEN userId is not supplied", () => { + test.todo("EXPECT nothing to happen"); +}); + +describe("GIVEN page is not supplied", () => { + test.todo("EXPECT nothing to happen"); +}); + +describe("GIVEN moons entity is undefined", () => { + test.todo("EXPECT interaction replied"); +}); + +describe("GIVEN moons array is empty", () => { + test.todo("EXPECT embed description to say none"); +}); + +describe("GIVEN moons array is not empty", () => { + test.todo("EXPECT embed description to specify moon details"); +}); + +describe("GIVEN moon difference is greater than 0", () => { + describe("GIVEN it is not the last page", () => { + test.todo("EXPECT untracked moons message to not be displayed"); + }); + + describe("GIVEN it is the last page", () => { + test.todo("EXPECT untracked moons to be displayed"); + }); + + describe("GIVEN moons array is empty", () => { + test.todo("EXPECT untracked moons to be displayed"); + }); +}); + +describe("GIVEN it is the first page", () => { + test.todo("EXPECT previous button to be disabled"); +}); + +describe("GIVEN it is the last page", () => { + test.todo("EXPECT next button to be disabled"); +}); + +describe("GIVEN happy flow", () => { + test.todo("EXPECT interaction to be updated"); +}); \ No newline at end of file