|
| 1 | +import { mentionEachUser } from "../../../src/controllers/mentionEachUser"; |
| 2 | +import { filterUserByRoles } from "../../../src/utils/filterUsersByRole"; |
| 3 | +import { checkDisplayType } from "../../../src/utils/checkDisplayType"; |
| 4 | + |
| 5 | +describe("Test mention each function", () => { |
| 6 | + it("Should be an instance of JSONResponse", () => { |
| 7 | + const env = { |
| 8 | + BOT_PUBLIC_KEY: "xyz", |
| 9 | + DISCORD_GUILD_ID: "123", |
| 10 | + DISCORD_TOKEN: "abc", |
| 11 | + }; |
| 12 | + const optionsArray = [ |
| 13 | + { |
| 14 | + name: "user", |
| 15 | + type: 9, |
| 16 | + value: "860900892193456149", |
| 17 | + }, |
| 18 | + { |
| 19 | + name: "message", |
| 20 | + type: 3, |
| 21 | + value: "hello", |
| 22 | + }, |
| 23 | + ]; |
| 24 | + |
| 25 | + const response = mentionEachUser( |
| 26 | + { displayType: "series", options: optionsArray }, |
| 27 | + env |
| 28 | + ); |
| 29 | + expect(response).toBeInstanceOf(Promise); |
| 30 | + }); |
| 31 | + |
| 32 | + it("should filter users based on role", () => { |
| 33 | + const roleId = "860900892193456149"; |
| 34 | + const optionsArray = [ |
| 35 | + { |
| 36 | + roles: [ |
| 37 | + "890520255934377985", |
| 38 | + "860900892193456149", |
| 39 | + "845302148878565406", |
| 40 | + ], |
| 41 | + user: { |
| 42 | + id: "282859044593598464", |
| 43 | + }, |
| 44 | + }, |
| 45 | + { |
| 46 | + roles: ["851059823779905548"], |
| 47 | + user: { |
| 48 | + id: "559426966151757824", |
| 49 | + }, |
| 50 | + }, |
| 51 | + { |
| 52 | + roles: ["860900892193456149"], |
| 53 | + user: { |
| 54 | + id: "725745030706364447", |
| 55 | + }, |
| 56 | + }, |
| 57 | + ]; |
| 58 | + const response = filterUserByRoles(optionsArray, roleId); |
| 59 | + const expectedResponse = ["<@282859044593598464>", "<@725745030706364447>"]; |
| 60 | + expect(response).toStrictEqual(expectedResponse); |
| 61 | + }); |
| 62 | + |
| 63 | + it("should return a message if users are not found (usersWithMatchingRole array is empty)", () => { |
| 64 | + const msgToBeSent = "hello"; |
| 65 | + |
| 66 | + const response = checkDisplayType({ |
| 67 | + displayType: "series", |
| 68 | + msgToBeSent, |
| 69 | + usersWithMatchingRole: [], |
| 70 | + }); |
| 71 | + const expectedResponse = `Sorry no user found under this role.`; |
| 72 | + |
| 73 | + expect(response).toBe(expectedResponse); |
| 74 | + }); |
| 75 | + |
| 76 | + it("should return message if displayType is list", () => { |
| 77 | + const msgToBeSent = "hello"; |
| 78 | + |
| 79 | + const response = checkDisplayType({ |
| 80 | + displayType: "list", |
| 81 | + msgToBeSent, |
| 82 | + usersWithMatchingRole: [], |
| 83 | + }); |
| 84 | + const expectedResponse = `Coming soon. We are working on this feature. We feel sorry for not serving you what you expect this command to do for now.(T_T)`; |
| 85 | + |
| 86 | + expect(response).toBe(expectedResponse); |
| 87 | + }); |
| 88 | + |
| 89 | + it("should return a message if users are found (usersWithMatchingRole array is not empty)", () => { |
| 90 | + const msgToBeSent = "hello"; |
| 91 | + |
| 92 | + const response = checkDisplayType({ |
| 93 | + displayType: "series", |
| 94 | + msgToBeSent, |
| 95 | + usersWithMatchingRole: ["<@282859044593598464>", "<@725745030706364447>"], |
| 96 | + }); |
| 97 | + const expectedResponse = |
| 98 | + "hello <@282859044593598464>,<@725745030706364447>"; |
| 99 | + |
| 100 | + expect(response).toBe(expectedResponse); |
| 101 | + }); |
| 102 | +}); |
0 commit comments