Skip to content

Commit 0af1ff6

Browse files
committed
Fix/improve tests
1 parent 60bd380 commit 0af1ff6

File tree

4 files changed

+12
-8
lines changed

4 files changed

+12
-8
lines changed

tests/globalSetup.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ vi.mock('@oldschoolgg/toolkit', async () => {
1616
awaitMessageComponentInteraction: vi.fn().mockImplementation(({ message }: { message: Message }) => {
1717
return Promise.resolve({
1818
customId: randArrItem(Object.values(InteractionID.Slayer)),
19-
...mockInteraction({ userId: message.author.id })
19+
...mockInteraction({ user: { id: message.author.id } as any })
2020
});
2121
})
2222
};

tests/integration/allCommandsBase.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,8 @@ test(
150150
['minion', 'daily'],
151151
['gamble', 'luckypick'],
152152
['gamble', 'duel'],
153-
['config', 'toggle']
153+
['config', 'toggle'],
154+
['gear', 'best_in_slot']
154155
];
155156

156157
const useCommandOptions: Record<string, any>[] = [];

tests/integration/trading.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ test('Trade consistency', async () => {
4646
user: other
4747
}
4848
},
49-
interaction: mockInteraction({ userId: user.id })
49+
interaction: mockInteraction({ user })
5050
};
5151

5252
switch (method) {

tests/integration/util.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,14 @@ class MockInteraction {
7171
async reply(res: any) {
7272
this.__response__ = res;
7373
}
74+
75+
mUser: MUser;
7476
user = {
7577
id: '123456789'
7678
};
77-
constructor(userId: string) {
78-
this.user.id = userId;
79+
constructor({ user }: { user: MUser }) {
80+
this.mUser = user;
81+
this.user.id = user.id;
7982
}
8083

8184
async confirmation() {
@@ -99,8 +102,8 @@ class MockInteraction {
99102
}
100103
}
101104

102-
export function mockInteraction({ userId }: { userId: string }) {
103-
return new MockInteraction(userId) as any;
105+
export function mockInteraction({ user }: { user: MUser }): MInteraction {
106+
return new MockInteraction({ user }) as any as MInteraction;
104107
}
105108

106109
export function mockChannel({ userId }: { userId: string }) {
@@ -283,7 +286,7 @@ export class TestUser extends MUserClass {
283286

284287
async runCommand(command: OSBMahojiCommand, options: object = {}, syncAfter = false) {
285288
await this.sync();
286-
const mockedInt = mockInteraction({ userId: this.user.id });
289+
const mockedInt = mockInteraction({ user: this });
287290
const result = await command.run({
288291
userID: this.user.id,
289292
guildID: '342983479501389826',

0 commit comments

Comments
 (0)