|
| 1 | +import { InteractionResponseType } from "discord-interactions"; |
| 2 | +import { responseJson } from "../../src/typeDefinitions/default.types"; |
| 3 | +import JSONResponse from "../../src/utils/JsonResponse"; |
| 4 | +import { discordEphemeralResponse } from "../../src/utils/discordEphemeralResponse"; |
| 5 | + |
| 6 | +describe("Test discordEphemeralResponse function", () => { |
| 7 | + it("should return a JSONResponse", () => { |
| 8 | + const response = discordEphemeralResponse("Hello"); |
| 9 | + expect(response).toBeInstanceOf(JSONResponse); |
| 10 | + }); |
| 11 | + it("Should have type as channelMessageWithSource", async () => { |
| 12 | + const response: responseJson = await discordEphemeralResponse( |
| 13 | + "Hello" |
| 14 | + ).json(); |
| 15 | + expect(response?.type).toBe( |
| 16 | + InteractionResponseType.CHANNEL_MESSAGE_WITH_SOURCE |
| 17 | + ); |
| 18 | + }); |
| 19 | + it("Should contain a content property in data", async () => { |
| 20 | + const response: responseJson = await discordEphemeralResponse( |
| 21 | + "Hello" |
| 22 | + ).json(); |
| 23 | + expect(response?.data).toHaveProperty("content"); |
| 24 | + }); |
| 25 | + it("Should have content as hello", async () => { |
| 26 | + const response: responseJson = await discordEphemeralResponse( |
| 27 | + "Hello" |
| 28 | + ).json(); |
| 29 | + expect(response?.data.content).toBe("Hello"); |
| 30 | + }); |
| 31 | + it("Should contain a flag property in data", async () => { |
| 32 | + const response: responseJson = await discordEphemeralResponse( |
| 33 | + "Hello" |
| 34 | + ).json(); |
| 35 | + expect(response?.data).toHaveProperty("flags"); |
| 36 | + }); |
| 37 | + it("Should have flag as 64", async () => { |
| 38 | + const response: responseJson = await discordEphemeralResponse( |
| 39 | + "Hello" |
| 40 | + ).json(); |
| 41 | + expect(response?.data.flags).toBe(64); |
| 42 | + }); |
| 43 | +}); |
0 commit comments