Skip to content

Commit

Permalink
fix: updates role when there is only one user (#59)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ajeyakrishna-k authored Feb 2, 2024
1 parent fe870e5 commit 478bce1
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 2 deletions.
1 change: 1 addition & 0 deletions .github/workflows/production.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ jobs:
DISCORD_BOT_PRIVATE_KEY
DISCORD_BOT_API_URL
DISCORD_SERVICE_PRIVATE_KEY
FF_CRON_DISCORD_KEY_PAIR_FLOW
env:
CLOUDFLARE_API_TOKEN: ${{secrets.CLOUDFLARE_API_TOKEN}}
CLOUDFLARE_ACCOUNT_ID: ${{secrets.CLOUDFLARE_ACCOUNT_ID}}
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/staging.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ jobs:
DISCORD_BOT_PRIVATE_KEY
DISCORD_BOT_API_URL
DISCORD_SERVICE_PRIVATE_KEY
FF_CRON_DISCORD_KEY_PAIR_FLOW
env:
CLOUDFLARE_API_TOKEN: ${{secrets.CLOUDFLARE_API_TOKEN}}
CLOUDFLARE_ACCOUNT_ID: ${{secrets.CLOUDFLARE_ACCOUNT_ID}}
Expand All @@ -29,4 +30,4 @@ jobs:
DISCORD_BOT_PRIVATE_KEY: ${{secrets.DISCORD_BOT_PRIVATE_KEY}}
DISCORD_BOT_API_URL: ${{secrets.DISCORD_BOT_API_URL}}
DISCORD_SERVICE_PRIVATE_KEY: ${{secrets.DISCORD_SERVICE_PRIVATE_KEY}}
FF_CRON_DISCORD_KEY_PAIR_FLOW: ${{vars.FF_CRON_DISCORD_KEY_PAIR_FLOW}}
FF_CRON_DISCORD_KEY_PAIR_FLOW: ${{vars.FF_CRON_DISCORD_KEY_PAIR_FLOW}}
2 changes: 1 addition & 1 deletion src/handlers/scheduledEventHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export const addMissedUpdatesRole = async (env: env) => {

const missedUpdatesUsers = await getMissedUpdatesUsers(env, cursor);

if (!!missedUpdatesUsers && missedUpdatesUsers.usersToAddRole?.length > 1) {
if (!!missedUpdatesUsers && missedUpdatesUsers.usersToAddRole?.length >= 1) {
const discordUserIdRoleIdList: DiscordUserRole[] = missedUpdatesUsers.usersToAddRole.map((userId) => ({
userid: userId,
roleid: config(env).MISSED_UPDATES_ROLE_ID,
Expand Down
9 changes: 9 additions & 0 deletions src/tests/handlers/missedRoleHandler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,15 @@ describe('addMissedUpdatesRole', () => {
expect(updateUserRoles).toHaveBeenCalledTimes(2);
});

it('should call getMissedUpdatesUsers and updateUserRoles when theres only one user', async () => {
const usersMockData = { ...missedUpdatesUsersMockWithoutCursor };
usersMockData.usersToAddRole = usersMockData.usersToAddRole.slice(0, 1);
(getMissedUpdatesUsers as jest.Mock).mockResolvedValueOnce(usersMockData);
await addMissedUpdatesRole({});
expect(getMissedUpdatesUsers).toHaveBeenCalledTimes(1);
expect(updateUserRoles).toHaveBeenCalledTimes(1);
});

it('should not call updateUserRoles when there are no users to add role', async () => {
(getMissedUpdatesUsers as jest.Mock).mockResolvedValueOnce(missedUpdatesUsersMockWithNoUsers);

Expand Down

0 comments on commit 478bce1

Please sign in to comment.