Compare commits
No commits in common. "1106585f581342eb87f34a7dcde90133838e3c0c" and "6e6ad3331ab44f9ae11c644a25e2097710a790da" have entirely different histories.
1106585f58
...
6e6ad3331a
19 changed files with 172 additions and 177 deletions
|
@ -7,7 +7,7 @@
|
||||||
# any secret values.
|
# any secret values.
|
||||||
|
|
||||||
BOT_TOKEN=
|
BOT_TOKEN=
|
||||||
BOT_VER=0.8.3
|
BOT_VER=0.8.2
|
||||||
BOT_AUTHOR=Vylpes
|
BOT_AUTHOR=Vylpes
|
||||||
BOT_OWNERID=147392775707426816
|
BOT_OWNERID=147392775707426816
|
||||||
BOT_CLIENTID=682942374040961060
|
BOT_CLIENTID=682942374040961060
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "card-drop",
|
"name": "card-drop",
|
||||||
"version": "0.8.3",
|
"version": "0.8.2",
|
||||||
"main": "./dist/bot.js",
|
"main": "./dist/bot.js",
|
||||||
"typings": "./dist",
|
"typings": "./dist",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|
|
@ -2,7 +2,6 @@ import { ButtonInteraction } from "discord.js";
|
||||||
import { ButtonEvent } from "../type/buttonEvent";
|
import { ButtonEvent } from "../type/buttonEvent";
|
||||||
import List from "./Effects/List";
|
import List from "./Effects/List";
|
||||||
import Use from "./Effects/Use";
|
import Use from "./Effects/Use";
|
||||||
import AppLogger from "../client/appLogger";
|
|
||||||
|
|
||||||
export default class Effects extends ButtonEvent {
|
export default class Effects extends ButtonEvent {
|
||||||
public override async execute(interaction: ButtonInteraction) {
|
public override async execute(interaction: ButtonInteraction) {
|
||||||
|
@ -15,8 +14,6 @@ export default class Effects extends ButtonEvent {
|
||||||
case "use":
|
case "use":
|
||||||
await Use.Execute(interaction);
|
await Use.Execute(interaction);
|
||||||
break;
|
break;
|
||||||
default:
|
|
||||||
AppLogger.LogError("Buttons/Effects", `Unknown action, ${action}`);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,18 +52,11 @@ export default class Reroll extends ButtonEvent {
|
||||||
try {
|
try {
|
||||||
AppLogger.LogVerbose("Button/Reroll", `Sending next drop: ${randomCard.card.id} (${randomCard.card.name})`);
|
AppLogger.LogVerbose("Button/Reroll", `Sending next drop: ${randomCard.card.id} (${randomCard.card.name})`);
|
||||||
|
|
||||||
const files = [];
|
|
||||||
let imageFileName = "";
|
|
||||||
|
|
||||||
if (!(randomCard.card.path.startsWith("http://") || randomCard.card.path.startsWith("https://"))) {
|
|
||||||
const image = readFileSync(path.join(process.env.DATA_DIR!, "cards", randomCard.card.path));
|
const image = readFileSync(path.join(process.env.DATA_DIR!, "cards", randomCard.card.path));
|
||||||
imageFileName = randomCard.card.path.split("/").pop()!;
|
const imageFileName = randomCard.card.path.split("/").pop()!;
|
||||||
|
|
||||||
const attachment = new AttachmentBuilder(image, { name: imageFileName });
|
const attachment = new AttachmentBuilder(image, { name: imageFileName });
|
||||||
|
|
||||||
files.push(attachment);
|
|
||||||
}
|
|
||||||
|
|
||||||
const inventory = await Inventory.FetchOneByCardNumberAndUserId(interaction.user.id, randomCard.card.id);
|
const inventory = await Inventory.FetchOneByCardNumberAndUserId(interaction.user.id, randomCard.card.id);
|
||||||
const quantityClaimed = inventory ? inventory.Quantity : 0;
|
const quantityClaimed = inventory ? inventory.Quantity : 0;
|
||||||
|
|
||||||
|
@ -75,7 +68,7 @@ export default class Reroll extends ButtonEvent {
|
||||||
|
|
||||||
await interaction.editReply({
|
await interaction.editReply({
|
||||||
embeds: [ embed ],
|
embeds: [ embed ],
|
||||||
files: files,
|
files: [ attachment ],
|
||||||
components: [ row ],
|
components: [ row ],
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,7 @@ export default class View extends ButtonEvent {
|
||||||
await interaction.editReply({
|
await interaction.editReply({
|
||||||
embeds: [ searchResult.embed ],
|
embeds: [ searchResult.embed ],
|
||||||
components: [ searchResult.row ],
|
components: [ searchResult.row ],
|
||||||
files: searchResult.attachments,
|
files: [ searchResult.attachment ],
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -70,18 +70,11 @@ export default class Drop extends Command {
|
||||||
await interaction.deferReply();
|
await interaction.deferReply();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const files = [];
|
|
||||||
let imageFileName = "";
|
|
||||||
|
|
||||||
if (!(randomCard.card.path.startsWith("http://") || randomCard.card.path.startsWith("https://"))) {
|
|
||||||
const image = readFileSync(path.join(process.env.DATA_DIR!, "cards", randomCard.card.path));
|
const image = readFileSync(path.join(process.env.DATA_DIR!, "cards", randomCard.card.path));
|
||||||
imageFileName = randomCard.card.path.split("/").pop()!;
|
const imageFileName = randomCard.card.path.split("/").pop()!;
|
||||||
|
|
||||||
const attachment = new AttachmentBuilder(image, { name: imageFileName });
|
const attachment = new AttachmentBuilder(image, { name: imageFileName });
|
||||||
|
|
||||||
files.push(attachment);
|
|
||||||
}
|
|
||||||
|
|
||||||
const inventory = await Inventory.FetchOneByCardNumberAndUserId(interaction.user.id, randomCard.card.id);
|
const inventory = await Inventory.FetchOneByCardNumberAndUserId(interaction.user.id, randomCard.card.id);
|
||||||
const quantityClaimed = inventory ? inventory.Quantity : 0;
|
const quantityClaimed = inventory ? inventory.Quantity : 0;
|
||||||
|
|
||||||
|
@ -93,7 +86,7 @@ export default class Drop extends Command {
|
||||||
|
|
||||||
await interaction.editReply({
|
await interaction.editReply({
|
||||||
embeds: [ embed ],
|
embeds: [ embed ],
|
||||||
files: files,
|
files: [ attachment ],
|
||||||
components: [ row ],
|
components: [ row ],
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -43,20 +43,22 @@ export default class Id extends Command {
|
||||||
const series = CoreClient.Cards
|
const series = CoreClient.Cards
|
||||||
.find(x => x.cards.includes(card))!;
|
.find(x => x.cards.includes(card))!;
|
||||||
|
|
||||||
const files = [];
|
let image: Buffer;
|
||||||
let imageFileName = "";
|
const imageFileName = card.path.split("/").pop()!;
|
||||||
|
|
||||||
if (!(card.path.startsWith("http://") || card.path.startsWith("https://"))) {
|
try {
|
||||||
const image = readFileSync(path.join(process.env.DATA_DIR!, "cards", card.path));
|
image = readFileSync(path.join(process.env.DATA_DIR!, "cards", card.path));
|
||||||
imageFileName = card.path.split("/").pop()!;
|
} catch {
|
||||||
|
AppLogger.LogError("Commands/View", `Unable to fetch image for card ${card.id}.`);
|
||||||
|
|
||||||
const attachment = new AttachmentBuilder(image, { name: imageFileName });
|
await interaction.reply(`Unable to fetch image for card ${card.id}.`);
|
||||||
|
return;
|
||||||
files.push(attachment);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
await interaction.deferReply();
|
await interaction.deferReply();
|
||||||
|
|
||||||
|
const attachment = new AttachmentBuilder(image, { name: imageFileName });
|
||||||
|
|
||||||
const inventory = await Inventory.FetchOneByCardNumberAndUserId(interaction.user.id, card.id);
|
const inventory = await Inventory.FetchOneByCardNumberAndUserId(interaction.user.id, card.id);
|
||||||
const quantityClaimed = inventory ? inventory.Quantity : 0;
|
const quantityClaimed = inventory ? inventory.Quantity : 0;
|
||||||
|
|
||||||
|
@ -65,7 +67,7 @@ export default class Id extends Command {
|
||||||
try {
|
try {
|
||||||
await interaction.editReply({
|
await interaction.editReply({
|
||||||
embeds: [ embed ],
|
embeds: [ embed ],
|
||||||
files: files,
|
files: [ attachment ],
|
||||||
});
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
AppLogger.LogError("Commands/View", `Error sending view for card ${card.id}: ${e}`);
|
AppLogger.LogError("Commands/View", `Error sending view for card ${card.id}: ${e}`);
|
||||||
|
|
|
@ -43,20 +43,20 @@ export default class Dropnumber extends Command {
|
||||||
const series = CoreClient.Cards
|
const series = CoreClient.Cards
|
||||||
.find(x => x.cards.includes(card))!;
|
.find(x => x.cards.includes(card))!;
|
||||||
|
|
||||||
const files = [];
|
let image: Buffer;
|
||||||
let imageFileName = "";
|
const imageFileName = card.path.split("/").pop()!;
|
||||||
|
|
||||||
if (!(card.path.startsWith("http://") || card.path.startsWith("https://"))) {
|
try {
|
||||||
const image = readFileSync(path.join(process.env.DATA_DIR!, "cards", card.path));
|
image = readFileSync(path.join(process.env.DATA_DIR!, "cards", card.path));
|
||||||
imageFileName = card.path.split("/").pop()!;
|
} catch {
|
||||||
|
await interaction.reply(`Unable to fetch image for card ${card.id}`);
|
||||||
const attachment = new AttachmentBuilder(image, { name: imageFileName });
|
return;
|
||||||
|
|
||||||
files.push(attachment);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
await interaction.deferReply();
|
await interaction.deferReply();
|
||||||
|
|
||||||
|
const attachment = new AttachmentBuilder(image, { name: imageFileName });
|
||||||
|
|
||||||
const inventory = await Inventory.FetchOneByCardNumberAndUserId(interaction.user.id, card.id);
|
const inventory = await Inventory.FetchOneByCardNumberAndUserId(interaction.user.id, card.id);
|
||||||
const quantityClaimed = inventory ? inventory.Quantity : 0;
|
const quantityClaimed = inventory ? inventory.Quantity : 0;
|
||||||
|
|
||||||
|
@ -69,7 +69,7 @@ export default class Dropnumber extends Command {
|
||||||
try {
|
try {
|
||||||
await interaction.editReply({
|
await interaction.editReply({
|
||||||
embeds: [ embed ],
|
embeds: [ embed ],
|
||||||
files: files,
|
files: [ attachment ],
|
||||||
components: [ row ],
|
components: [ row ],
|
||||||
});
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|
|
@ -47,18 +47,20 @@ export default class Droprarity extends Command {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const files = [];
|
let image: Buffer;
|
||||||
let imageFileName = "";
|
const imageFileName = card.card.path.split("/").pop()!;
|
||||||
|
|
||||||
if (!(card.card.path.startsWith("http://") || card.card.path.startsWith("https://"))) {
|
try {
|
||||||
const image = readFileSync(path.join(process.env.DATA_DIR!, "cards", card.card.path));
|
image = readFileSync(path.join(process.env.DATA_DIR!, "cards", card.card.path));
|
||||||
imageFileName = card.card.path.split("/").pop()!;
|
} catch {
|
||||||
|
await interaction.reply(`Unable to fetch image for card ${card.card.id}`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
await interaction.deferReply();
|
||||||
|
|
||||||
const attachment = new AttachmentBuilder(image, { name: imageFileName });
|
const attachment = new AttachmentBuilder(image, { name: imageFileName });
|
||||||
|
|
||||||
files.push(attachment);
|
|
||||||
}
|
|
||||||
|
|
||||||
const inventory = await Inventory.FetchOneByCardNumberAndUserId(interaction.user.id, card.card.id);
|
const inventory = await Inventory.FetchOneByCardNumberAndUserId(interaction.user.id, card.card.id);
|
||||||
const quantityClaimed = inventory ? inventory.Quantity : 0;
|
const quantityClaimed = inventory ? inventory.Quantity : 0;
|
||||||
|
|
||||||
|
@ -71,7 +73,7 @@ export default class Droprarity extends Command {
|
||||||
try {
|
try {
|
||||||
await interaction.editReply({
|
await interaction.editReply({
|
||||||
embeds: [ embed ],
|
embeds: [ embed ],
|
||||||
files: files,
|
files: [ attachment ],
|
||||||
components: [ row ],
|
components: [ row ],
|
||||||
});
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|
|
@ -34,7 +34,7 @@ export default class View extends Command {
|
||||||
await interaction.editReply({
|
await interaction.editReply({
|
||||||
embeds: [ searchResult.embed ],
|
embeds: [ searchResult.embed ],
|
||||||
components: [ searchResult.row ],
|
components: [ searchResult.row ],
|
||||||
files: searchResult.attachments,
|
files: [ searchResult.attachment ],
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -11,7 +11,7 @@ import DropEmbedHelper from "./DropHelpers/DropEmbedHelper.js";
|
||||||
interface ReturnedPage {
|
interface ReturnedPage {
|
||||||
embed: EmbedBuilder,
|
embed: EmbedBuilder,
|
||||||
row: ActionRowBuilder<ButtonBuilder>,
|
row: ActionRowBuilder<ButtonBuilder>,
|
||||||
attachments: AttachmentBuilder[],
|
attachment: AttachmentBuilder,
|
||||||
results: string[],
|
results: string[],
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,18 +37,19 @@ export default class CardSearchHelper {
|
||||||
|
|
||||||
if (!card) return undefined;
|
if (!card) return undefined;
|
||||||
|
|
||||||
const attachments = [];
|
let image: Buffer;
|
||||||
let imageFileName = "";
|
const imageFileName = card.card.path.split("/").pop()!;
|
||||||
|
|
||||||
if (!(card.card.path.startsWith("http://") || card.card.path.startsWith("https://"))) {
|
try {
|
||||||
const image = readFileSync(path.join(process.env.DATA_DIR!, "cards", card.card.path));
|
image = readFileSync(path.join(process.env.DATA_DIR!, "cards", card.card.path));
|
||||||
imageFileName = card.card.path.split("/").pop()!;
|
} catch {
|
||||||
|
AppLogger.LogError("CardSearchHelper/GenerateSearchQuery", `Unable to fetch image for card ${card.card.id}.`);
|
||||||
|
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
const attachment = new AttachmentBuilder(image, { name: imageFileName });
|
const attachment = new AttachmentBuilder(image, { name: imageFileName });
|
||||||
|
|
||||||
attachments.push(attachment);
|
|
||||||
}
|
|
||||||
|
|
||||||
const inventory = await Inventory.FetchOneByCardNumberAndUserId(userid, card.card.id);
|
const inventory = await Inventory.FetchOneByCardNumberAndUserId(userid, card.card.id);
|
||||||
const quantityClaimed = inventory?.Quantity ?? 0;
|
const quantityClaimed = inventory?.Quantity ?? 0;
|
||||||
|
|
||||||
|
@ -67,7 +68,7 @@ export default class CardSearchHelper {
|
||||||
.setStyle(ButtonStyle.Primary)
|
.setStyle(ButtonStyle.Primary)
|
||||||
.setDisabled(pages == 1));
|
.setDisabled(pages == 1));
|
||||||
|
|
||||||
return { embed, row, attachments, results };
|
return { embed, row, attachment, results };
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async GenerateSearchPageFromQuery(results: string[], userid: string, page: number): Promise<ReturnedPage | undefined> {
|
public static async GenerateSearchPageFromQuery(results: string[], userid: string, page: number): Promise<ReturnedPage | undefined> {
|
||||||
|
@ -81,18 +82,19 @@ export default class CardSearchHelper {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
const attachments = [];
|
let image: Buffer;
|
||||||
let imageFileName = "";
|
const imageFileName = card.card.path.split("/").pop()!;
|
||||||
|
|
||||||
if (!(card.card.path.startsWith("http://") || card.card.path.startsWith("https://"))) {
|
try {
|
||||||
const image = readFileSync(path.join(process.env.DATA_DIR!, "cards", card.card.path));
|
image = readFileSync(path.join(process.env.DATA_DIR!, "cards", card.card.path));
|
||||||
imageFileName = card.card.path.split("/").pop()!;
|
} catch {
|
||||||
|
AppLogger.LogError("CardSearchHelper/GenerateSearchPageFromQuery", `Unable to fetch image for card ${card.card.id}.`);
|
||||||
|
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
const attachment = new AttachmentBuilder(image, { name: imageFileName });
|
const attachment = new AttachmentBuilder(image, { name: imageFileName });
|
||||||
|
|
||||||
attachments.push(attachment);
|
|
||||||
}
|
|
||||||
|
|
||||||
const inventory = await Inventory.FetchOneByCardNumberAndUserId(userid, card.card.id);
|
const inventory = await Inventory.FetchOneByCardNumberAndUserId(userid, card.card.id);
|
||||||
const quantityClaimed = inventory?.Quantity ?? 0;
|
const quantityClaimed = inventory?.Quantity ?? 0;
|
||||||
|
|
||||||
|
@ -111,6 +113,6 @@ export default class CardSearchHelper {
|
||||||
.setStyle(ButtonStyle.Primary)
|
.setStyle(ButtonStyle.Primary)
|
||||||
.setDisabled(page == results.length));
|
.setDisabled(page == results.length));
|
||||||
|
|
||||||
return { embed, row, attachments, results };
|
return { embed, row, attachment, results };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,18 +24,12 @@ export default class DropEmbedHelper {
|
||||||
AppLogger.LogWarn("CardDropHelperMetadata/GenerateDropEmbed", `Card's colour override is invalid: ${drop.card.id}, ${drop.card.colour}`);
|
AppLogger.LogWarn("CardDropHelperMetadata/GenerateDropEmbed", `Card's colour override is invalid: ${drop.card.id}, ${drop.card.colour}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
let imageUrl = `attachment://${imageFileName}`;
|
|
||||||
|
|
||||||
if (drop.card.path.startsWith("http://") || drop.card.path.startsWith("https://")) {
|
|
||||||
imageUrl = drop.card.path;
|
|
||||||
}
|
|
||||||
|
|
||||||
const embed = new EmbedBuilder()
|
const embed = new EmbedBuilder()
|
||||||
.setTitle(drop.card.name)
|
.setTitle(drop.card.name)
|
||||||
.setDescription(description)
|
.setDescription(description)
|
||||||
.setFooter({ text: `${CardRarityToString(drop.card.type)} · ${drop.card.id}` })
|
.setFooter({ text: `${CardRarityToString(drop.card.type)} · ${drop.card.id}` })
|
||||||
.setColor(colour)
|
.setColor(colour)
|
||||||
.setImage(imageUrl)
|
.setImage(`attachment://${imageFileName}`)
|
||||||
.addFields([
|
.addFields([
|
||||||
{
|
{
|
||||||
name: "Claimed",
|
name: "Claimed",
|
||||||
|
|
|
@ -1,21 +0,0 @@
|
||||||
import { ButtonInteraction } from "../../__types__/discord.js";
|
|
||||||
|
|
||||||
export default function GenerateButtonInteractionMock(): ButtonInteraction {
|
|
||||||
return {
|
|
||||||
guild: {},
|
|
||||||
guildId: "guildId",
|
|
||||||
channel: {
|
|
||||||
isSendable: jest.fn().mockReturnValue(true),
|
|
||||||
send: jest.fn(),
|
|
||||||
},
|
|
||||||
deferUpdate: jest.fn(),
|
|
||||||
editReply: jest.fn(),
|
|
||||||
message: {
|
|
||||||
createdAt: new Date(1000 * 60 * 27),
|
|
||||||
},
|
|
||||||
user: {
|
|
||||||
id: "userId",
|
|
||||||
},
|
|
||||||
customId: "customId",
|
|
||||||
};
|
|
||||||
}
|
|
|
@ -1,5 +1,5 @@
|
||||||
export type ButtonInteraction = {
|
export type ButtonInteraction = {
|
||||||
guild: object | null,
|
guild: {} | null,
|
||||||
guildId: string | null,
|
guildId: string | null,
|
||||||
channel: {
|
channel: {
|
||||||
isSendable: jest.Func,
|
isSendable: jest.Func,
|
||||||
|
|
|
@ -2,7 +2,6 @@ import { ButtonInteraction, TextChannel } from "discord.js";
|
||||||
import Claim from "../../src/buttonEvents/Claim";
|
import Claim from "../../src/buttonEvents/Claim";
|
||||||
import { ButtonInteraction as ButtonInteractionType } from "../__types__/discord.js";
|
import { ButtonInteraction as ButtonInteractionType } from "../__types__/discord.js";
|
||||||
import User from "../../src/database/entities/app/User";
|
import User from "../../src/database/entities/app/User";
|
||||||
import GenerateButtonInteractionMock from "../__functions__/discord.js/GenerateButtonInteractionMock";
|
|
||||||
|
|
||||||
jest.mock("../../src/client/appLogger");
|
jest.mock("../../src/client/appLogger");
|
||||||
|
|
||||||
|
@ -12,8 +11,23 @@ beforeEach(() => {
|
||||||
jest.useFakeTimers();
|
jest.useFakeTimers();
|
||||||
jest.setSystemTime(1000 * 60 * 30);
|
jest.setSystemTime(1000 * 60 * 30);
|
||||||
|
|
||||||
interaction = GenerateButtonInteractionMock();
|
interaction = {
|
||||||
interaction.customId = "claim cardNumber claimId droppedBy userId";
|
guild: {},
|
||||||
|
guildId: "guildId",
|
||||||
|
channel: {
|
||||||
|
isSendable: jest.fn().mockReturnValue(true),
|
||||||
|
send: jest.fn(),
|
||||||
|
},
|
||||||
|
deferUpdate: jest.fn(),
|
||||||
|
editReply: jest.fn(),
|
||||||
|
message: {
|
||||||
|
createdAt: new Date(1000 * 60 * 27),
|
||||||
|
},
|
||||||
|
user: {
|
||||||
|
id: "userId",
|
||||||
|
},
|
||||||
|
customId: "claim cardNumber claimId droppedBy userId",
|
||||||
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
afterAll(() => {
|
afterAll(() => {
|
||||||
|
@ -107,3 +121,15 @@ test("GIVEN user.RemoveCurrency fails, EXPECT error", async () => {
|
||||||
|
|
||||||
expect(interaction.editReply).not.toHaveBeenCalled();
|
expect(interaction.editReply).not.toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test.todo("GIVEN the card has already been claimed, EXPECT error");
|
||||||
|
|
||||||
|
test.todo("GIVEN the current drop is the latest AND the current user is NOT the one who dropped it, EXPECT error");
|
||||||
|
|
||||||
|
test.todo("GIVEN the user already has the card in their inventory, EXPECT the entity quantity to be +1");
|
||||||
|
|
||||||
|
test.todo("GIVEN user does NOT have the card in their inventory, EXPECT a new entity to be created");
|
||||||
|
|
||||||
|
test.todo("GIVEN card can not be found in the bot, EXPECT error logged");
|
||||||
|
|
||||||
|
test.todo("EXPECT message to be edited");
|
|
@ -1,66 +1,5 @@
|
||||||
import { ButtonInteraction } from "discord.js";
|
test.todo("GIVEN action is list, EXPECT list function to be called");
|
||||||
import Effects from "../../src/buttonEvents/Effects";
|
|
||||||
import GenerateButtonInteractionMock from "../__functions__/discord.js/GenerateButtonInteractionMock";
|
|
||||||
import { ButtonInteraction as ButtonInteractionType } from "../__types__/discord.js";
|
|
||||||
import List from "../../src/buttonEvents/Effects/List";
|
|
||||||
import Use from "../../src/buttonEvents/Effects/Use";
|
|
||||||
import AppLogger from "../../src/client/appLogger";
|
|
||||||
|
|
||||||
jest.mock("../../src/client/appLogger");
|
test.todo("GIVEN action is use, EXPECT use function to be called");
|
||||||
jest.mock("../../src/buttonEvents/Effects/List");
|
|
||||||
jest.mock("../../src/buttonEvents/Effects/Use");
|
|
||||||
|
|
||||||
let interaction: ButtonInteractionType;
|
test.todo("GIVEN action is unknown, EXPECT nothing to be called");
|
||||||
|
|
||||||
beforeEach(() => {
|
|
||||||
jest.resetAllMocks();
|
|
||||||
|
|
||||||
interaction = GenerateButtonInteractionMock();
|
|
||||||
interaction.customId = "effects";
|
|
||||||
});
|
|
||||||
|
|
||||||
test("GIVEN action is list, EXPECT list function to be called", async () => {
|
|
||||||
// Arrange
|
|
||||||
interaction.customId = "effects list";
|
|
||||||
|
|
||||||
// Act
|
|
||||||
const effects = new Effects();
|
|
||||||
await effects.execute(interaction as unknown as ButtonInteraction);
|
|
||||||
|
|
||||||
// Assert
|
|
||||||
expect(List).toHaveBeenCalledTimes(1);
|
|
||||||
expect(List).toHaveBeenCalledWith(interaction);
|
|
||||||
|
|
||||||
expect(Use.Execute).not.toHaveBeenCalled();
|
|
||||||
});
|
|
||||||
|
|
||||||
test("GIVEN action is use, EXPECT use function to be called", async () => {
|
|
||||||
// Arrange
|
|
||||||
interaction.customId = "effects use";
|
|
||||||
|
|
||||||
// Act
|
|
||||||
const effects = new Effects();
|
|
||||||
await effects.execute(interaction as unknown as ButtonInteraction);
|
|
||||||
|
|
||||||
// Assert
|
|
||||||
expect(Use.Execute).toHaveBeenCalledTimes(1);
|
|
||||||
expect(Use.Execute).toHaveBeenCalledWith(interaction);
|
|
||||||
|
|
||||||
expect(List).not.toHaveBeenCalled();
|
|
||||||
});
|
|
||||||
|
|
||||||
test("GIVEN action is invalid, EXPECT nothing to be called", async () => {
|
|
||||||
// Arrange
|
|
||||||
interaction.customId = "effects invalid";
|
|
||||||
|
|
||||||
// Act
|
|
||||||
const effects = new Effects();
|
|
||||||
await effects.execute(interaction as unknown as ButtonInteraction);
|
|
||||||
|
|
||||||
// Assert
|
|
||||||
expect(List).not.toHaveBeenCalled();
|
|
||||||
expect(Use.Execute).not.toHaveBeenCalled();
|
|
||||||
|
|
||||||
expect(AppLogger.LogError).toHaveBeenCalledTimes(1);
|
|
||||||
expect(AppLogger.LogError).toHaveBeenCalledWith("Buttons/Effects", "Unknown action, invalid");
|
|
||||||
});
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { ButtonInteraction, InteractionResponse, InteractionUpdateOptions, MessagePayload } from "discord.js";
|
import { ButtonInteraction, EmbedBuilder, InteractionResponse } from "discord.js";
|
||||||
import Use from "../../../src/buttonEvents/Effects/Use";
|
import Use from "../../../src/buttonEvents/Effects/Use";
|
||||||
import { mock } from "jest-mock-extended";
|
import { mock } from "jest-mock-extended";
|
||||||
import AppLogger from "../../../src/client/appLogger";
|
import AppLogger from "../../../src/client/appLogger";
|
||||||
|
@ -82,7 +82,7 @@ describe("UseConfirm", () => {
|
||||||
// Arrange
|
// Arrange
|
||||||
interaction.customId += " unclaimed";
|
interaction.customId += " unclaimed";
|
||||||
interaction.user.id = "userId";
|
interaction.user.id = "userId";
|
||||||
interaction.update.mockImplementation(async (opts: string | MessagePayload | InteractionUpdateOptions) => {
|
interaction.update.mockImplementation(async (opts: any) => {
|
||||||
updatedWith = opts;
|
updatedWith = opts;
|
||||||
|
|
||||||
return mock<InteractionResponse<boolean>>();
|
return mock<InteractionResponse<boolean>>();
|
||||||
|
@ -133,7 +133,7 @@ describe("UseCancel", () => {
|
||||||
// Arrange
|
// Arrange
|
||||||
interaction.customId += " unclaimed";
|
interaction.customId += " unclaimed";
|
||||||
interaction.user.id = "userId";
|
interaction.user.id = "userId";
|
||||||
interaction.update.mockImplementation(async (opts: string | MessagePayload | InteractionUpdateOptions) => {
|
interaction.update.mockImplementation(async (opts: any) => {
|
||||||
updatedWith = opts;
|
updatedWith = opts;
|
||||||
|
|
||||||
return mock<InteractionResponse<boolean>>();
|
return mock<InteractionResponse<boolean>>();
|
||||||
|
|
27
tests/commands/effects.test.ts
Normal file
27
tests/commands/effects.test.ts
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
describe("constructor", () => {
|
||||||
|
test.todo("EXPECT CommandBuilder to be defined");
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("execute", () => {
|
||||||
|
test.todo("GIVEN interaction is NOT a ChatInputCommand, EXPECT nothing to happen");
|
||||||
|
|
||||||
|
test.todo("GIVEN subcommand is list, EXPECT list function to be called");
|
||||||
|
|
||||||
|
test.todo("GIVEN subcommand is use, EXPECT use function to be called");
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("List", () => {
|
||||||
|
test.todo("GIVEN pageOption is null, EXPECT page to default to 0");
|
||||||
|
|
||||||
|
test.todo("GIVEN pageOption.value is undefined, EXPECT page to default to 0");
|
||||||
|
|
||||||
|
test.todo("EXPECT interaction to be replied");
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("Use", () => {
|
||||||
|
test.todo("GIVEN effectDetail is not found, EXPECT error");
|
||||||
|
|
||||||
|
test.todo("GIVEN user can not use effect, EXPECT error");
|
||||||
|
|
||||||
|
test.todo("EXPECT interaction to be replied");
|
||||||
|
});
|
41
tests/helpers/EffectHelper.test.ts
Normal file
41
tests/helpers/EffectHelper.test.ts
Normal file
|
@ -0,0 +1,41 @@
|
||||||
|
describe("AddEffectToUserInventory", () => {
|
||||||
|
test.todo("GIVEN effect is found in database, EXPECT effect unused to be incremented");
|
||||||
|
|
||||||
|
test.todo("GIVEN effect is NOT found in database, EXPECT new effect to be created");
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("UseEffect", () => {
|
||||||
|
test.todo("GIVEN user can not use effect, EXPECT false returned");
|
||||||
|
|
||||||
|
test.todo("GIVEN user has effect, EXPECT entity to be updated AND true returned");
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("CanUseEffect", () => {
|
||||||
|
test.todo("GIVEN effect is not in database, EXPECT false returned");
|
||||||
|
|
||||||
|
test.todo("GIVEN user does not have any of the effect unused, EXPECT false returned");
|
||||||
|
|
||||||
|
test.todo("GIVEN effectDetail can not be found, EXPECT false returned");
|
||||||
|
|
||||||
|
test.todo("GIVEN effect has NOT passed the cooldown, EXPECT false returned");
|
||||||
|
|
||||||
|
test.todo("GIVEN effect has passed the cooldown, EXPECT true returned");
|
||||||
|
|
||||||
|
test.todo("GIVEN effect does not have a WhenExpires date supplied, EXPECT true returned");
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("HasEffect", () => {
|
||||||
|
test.todo("GIVEN effect is NOT found in database, EXPECT false returned");
|
||||||
|
|
||||||
|
test.todo("GIVEN effect does NOT have an expiry date, EXPECT false returned");
|
||||||
|
|
||||||
|
test.todo("GIVEN effect.WhenExpires is in the future, EXPECT false returned");
|
||||||
|
|
||||||
|
test.todo("GIVEN effect.WhenExpires is in the past, EXPECT true returned");
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("GenerateEffectEmbed", () => {
|
||||||
|
test.todo("GIVEN user has no effects, EXPECT embed to be generated");
|
||||||
|
|
||||||
|
test.todo("GIVEN user has some effects, EXPECT embed to be generated");
|
||||||
|
});
|
Loading…
Add table
Reference in a new issue