From 38f444e88570131d5260ba36cc157bf2c8c4f4c9 Mon Sep 17 00:00:00 2001 From: Anish Pawaskar Date: Thu, 5 Oct 2023 00:44:44 +0530 Subject: [PATCH 1/3] add sync idle 7d+ users on discord button (#538) * add sync idle 7d+ users on discord button * fix test * fix typo * fix test * revert headless to false * fix failing test * revert headless to new --- __tests__/home/home.test.js | 71 +++++++++++++++++++++++++++++++++++++ constants.js | 2 ++ index.html | 8 +++++ script.js | 15 ++++++++ 4 files changed, 96 insertions(+) diff --git a/__tests__/home/home.test.js b/__tests__/home/home.test.js index 0f4cf2d5..545b19f2 100644 --- a/__tests__/home/home.test.js +++ b/__tests__/home/home.test.js @@ -31,6 +31,38 @@ describe('Home Page', () => { } else if ( url === `https://api.realdevsquad.com/discord-actions/nicknames/sync?dev=true` + ) { + interceptedRequest.respond({ + status: 200, + ok: true, + contentType: 'application/json', + headers: { + 'Access-Control-Allow-Origin': '*', + 'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE, OPTIONS', + 'Access-Control-Allow-Headers': 'Content-Type, Authorization', + }, + body: JSON.stringify({ + message: 'All Idle 7d+ Users updated successfully.', + totalArchivedUsers: 1, + totalGroupIdle7dRolesApplied: { + count: 3, + response: [ + { message: 'Role added successfully' }, + { message: 'Role added successfully' }, + { message: 'Role added successfully' }, + ], + }, + totalGroupIdle7dRolesNotApplied: { count: 0, errors: [] }, + totalGroupIdle7dRolesNotRemoved: { count: 0, errors: [] }, + totalGroupIdle7dRolesRemoved: { count: 0, response: [] }, + totalIdle7dUsers: 4, + totalUserRoleToBeAdded: 4, + totalUserRoleToBeRemoved: 0, + totalUsersHavingNoDiscordId: 0, + }), + }); + } else if ( + url === `https://api.realdevsquad.com/discord-actions/group-idle-7d` ) { interceptedRequest.respond({ status: 200, @@ -155,6 +187,45 @@ describe('Home Page', () => { expect(latestSyncStatusText).not.toBe(`Last Sync: In progress`); }); + it('should display the Sync Idle 7d+ Users On Discord button', async () => { + const syncIdle7dPlusUsersButton = await page.$('#sync-idle-7d-Plus-users'); + expect(syncIdle7dPlusUsersButton).toBeTruthy(); + + const spinnerInsideSyncIdle7dPlusUsers = await syncIdle7dPlusUsersButton.$( + '.spinner', + ); + expect(spinnerInsideSyncIdle7dPlusUsers).toBeTruthy(); + + const syncIdle7dPlusUsersUpdate = await page.$( + '#sync-idle-7d-Plus-users-update', + ); + expect(syncIdle7dPlusUsersUpdate).toBeTruthy(); + }); + + it('should display the latest sync date when a super_user clicks on the Sync Idle 7d+ Users On Discord button', async () => { + await page.evaluate(() => { + document.querySelector('#sync-idle-7d-Plus-users').click(); + }); + await page.waitForNetworkIdle(); + + const latestSyncStatusElement = await page.waitForSelector( + '#sync-idle-7d-Plus-users-update', + ); + + expect(latestSyncStatusElement).toBeTruthy(); + + const latestSyncStatusText = await page.evaluate( + (element) => element.textContent, + latestSyncStatusElement, + ); + + expect(latestSyncStatusText).not.toBe(`Last Sync: Failed`); + expect(latestSyncStatusText).not.toBe( + `Last Sync: Synced Data Not Available`, + ); + expect(latestSyncStatusText).not.toBe(`Last Sync: In progress`); + }); + it('should display the Create Goals anchor button', async () => { const createGoalsButton = await page.$('#create-goal'); expect(createGoalsButton).toBeTruthy(); diff --git a/constants.js b/constants.js index dd5b8ce0..14d3280c 100644 --- a/constants.js +++ b/constants.js @@ -14,6 +14,8 @@ const SYNC_EXTERNAL_ACCOUNTS_UPDATE = 'sync-external-accounts-update'; const SYNC_UNVERIFIED_USERS_UPDATE = 'sync-unverified-users-update'; const SYNC_NICKNAMES = 'sync-nicknames'; const SYNC_NICKNAMES_STATUS_UPDATE = 'sync-nicknames-status-update'; +const SYNC_IDLE_7D_Plus_USERS = 'sync-idle-7d-Plus-users'; +const SYNC_IDLE_7D_Plus_USERS_UPDATE = 'sync-idle-7d-Plus-users-update'; const SYNC_IN_PROGRESS = 'Last Sync: In progress'; const SYNC_SUCCESSFUL = 'Last Sync: Successful'; const SYNC_FAILED = 'Last Sync: Failed'; diff --git a/index.html b/index.html index 1c1d701f..66a47ff7 100644 --- a/index.html +++ b/index.html @@ -75,6 +75,14 @@
+
+ +
+
+
- +
+ +