Skip to content

Commit ebf214b

Browse files
committed
test: add unit tests for fetching scope data and handling out of scope requests in DiscordStrategy
1 parent 10d78e3 commit ebf214b

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

server/src/auth/strategies/discord.strategy/Strategy.spec.ts

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,12 @@ describe('DiscordStrategy', () => {
1212
clientID: 'test-client-id',
1313
clientSecret: 'test-client-secret',
1414
callbackUrl: 'http://localhost:3000/callback',
15-
scope: [DiscordPermissionScope.Email, DiscordPermissionScope.Identify],
15+
scope: [
16+
DiscordPermissionScope.Email,
17+
DiscordPermissionScope.Identify,
18+
DiscordPermissionScope.Connections,
19+
// DiscordPermissionScope.Bot, // Not allowed scope
20+
],
1621
prompt: 'consent',
1722
};
1823

@@ -114,13 +119,25 @@ describe('DiscordStrategy', () => {
114119
strategy['makeApiRequest'] = mockMakeApiRequest;
115120

116121
const result = await strategy['fetchScopeData'](
117-
'connections',
122+
DiscordPermissionScope.Connections,
118123
'test-access-token',
119124
);
120125

121126
expect(result).toEqual([{ id: '123' }]);
122127
});
123128

129+
it('should no fetch out of scope data', async () => {
130+
const mockMakeApiRequest = jest.fn().mockResolvedValue([{ id: '123' }]);
131+
strategy['makeApiRequest'] = mockMakeApiRequest;
132+
133+
const result = await strategy['fetchScopeData'](
134+
DiscordPermissionScope.Bot,
135+
'test-access-token',
136+
);
137+
138+
expect(result).toEqual(null);
139+
});
140+
124141
it('should enrich profile with scopes', async () => {
125142
const profile = {
126143
id: '123',

0 commit comments

Comments
 (0)