Compare commits
2 commits
b2807adf4d
...
d4c75845e5
Author | SHA1 | Date | |
---|---|---|---|
d4c75845e5 | |||
38b0b8b301 |
6 changed files with 69 additions and 1 deletions
|
@ -3,6 +3,7 @@ import { ButtonEvent } from "../type/buttonEvent";
|
|||
import List from "./Effects/List";
|
||||
import Use from "./Effects/Use";
|
||||
import AppLogger from "../client/appLogger";
|
||||
import Buy from "./Effects/Buy";
|
||||
|
||||
export default class Effects extends ButtonEvent {
|
||||
public override async execute(interaction: ButtonInteraction) {
|
||||
|
@ -15,6 +16,9 @@ export default class Effects extends ButtonEvent {
|
|||
case "use":
|
||||
await Use.Execute(interaction);
|
||||
break;
|
||||
case "buy":
|
||||
await Buy.Execute(interaction);
|
||||
break;
|
||||
default:
|
||||
AppLogger.LogError("Buttons/Effects", `Unknown action, ${action}`);
|
||||
}
|
||||
|
|
25
src/buttonEvents/Effects/Buy.ts
Normal file
25
src/buttonEvents/Effects/Buy.ts
Normal file
|
@ -0,0 +1,25 @@
|
|||
import {ButtonInteraction} from "discord.js";
|
||||
import AppLogger from "../../client/appLogger";
|
||||
|
||||
export default class Buy {
|
||||
public static async Execute(interaction: ButtonInteraction) {
|
||||
const subaction = interaction.customId.split(" ")[2];
|
||||
|
||||
switch (subaction) {
|
||||
case "confirm":
|
||||
await this.Confirm(interaction);
|
||||
break;
|
||||
case "cancel":
|
||||
await this.Cancel(interaction);
|
||||
break;
|
||||
default:
|
||||
AppLogger.LogError("Buy", `Unknown subaction, effects ${subaction}`);
|
||||
}
|
||||
}
|
||||
|
||||
private static async Confirm(interaction: ButtonInteraction) {
|
||||
}
|
||||
|
||||
private static async Cancel(interaction: ButtonInteraction) {
|
||||
}
|
||||
}
|
|
@ -1,4 +1,22 @@
|
|||
import { CommandInteraction } from "discord.js";
|
||||
import EffectHelper from "../../helpers/EffectHelper";
|
||||
|
||||
export default async function Buy(interaction: CommandInteraction) {
|
||||
const id = interaction.options.get("id", true).value!;
|
||||
const quantity = interaction.options.get("quantity")?.value ?? 1;
|
||||
|
||||
const idValue = id.toString();
|
||||
const quantityValue = Number(quantity);
|
||||
|
||||
const result = await EffectHelper.GenerateEffectBuyEmbed(interaction.user.id, idValue, quantityValue, false);
|
||||
|
||||
if (typeof result == "string") {
|
||||
await interaction.reply(result);
|
||||
return;
|
||||
}
|
||||
|
||||
await interaction.reply({
|
||||
embeds: [ result.embed ],
|
||||
components: [ result.row ],
|
||||
});
|
||||
}
|
|
@ -49,6 +49,8 @@ test("GIVEN action is use, EXPECT use function to be called", async () => {
|
|||
expect(List).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
test.todo("GIVEN action is buy, EXPECT buy function to be called");
|
||||
|
||||
test("GIVEN action is invalid, EXPECT nothing to be called", async () => {
|
||||
// Arrange
|
||||
interaction.customId = "effects invalid";
|
||||
|
@ -63,4 +65,4 @@ test("GIVEN action is invalid, EXPECT nothing to be called", async () => {
|
|||
|
||||
expect(AppLogger.LogError).toHaveBeenCalledTimes(1);
|
||||
expect(AppLogger.LogError).toHaveBeenCalledWith("Buttons/Effects", "Unknown action, invalid");
|
||||
});
|
||||
});
|
||||
|
|
7
tests/buttonEvents/Effects/Buy.test.ts
Normal file
7
tests/buttonEvents/Effects/Buy.test.ts
Normal file
|
@ -0,0 +1,7 @@
|
|||
describe("Execute", () => {
|
||||
test.todo("GIVEN subaction is confirm, EXPECT confirm function executed");
|
||||
|
||||
test.todo("GIVEN subaction is cancel, EXPECT cancel function executed");
|
||||
|
||||
test.todo("GIVEN subaction is invalid, EXPECT error logged");
|
||||
});
|
12
tests/commands/effects/Buy.test.ts
Normal file
12
tests/commands/effects/Buy.test.ts
Normal file
|
@ -0,0 +1,12 @@
|
|||
import Buy from "../../../src/commands/effects/Buy";
|
||||
import EffectHelper from "../../../src/helpers/EffectHelper";
|
||||
|
||||
jest.mock("../../../src/helpers/EffectHelper");
|
||||
|
||||
describe("Buy", () => {
|
||||
test.todo("GIVEN result returns a string, EXPECT interaction replied with string");
|
||||
|
||||
test.todo("GIVEN result returns an embed, EXPECT interaction replied with embed and row");
|
||||
|
||||
test.todo("GIVEN quantity option is not supplied, EXPECT quantity to default to 1");
|
||||
});
|
Loading…
Reference in a new issue