|
| 1 | +const puppeteer = require('puppeteer'); |
| 2 | +const { |
| 3 | + photoVerificationRequestApprovedResponse, |
| 4 | + photoVerificationRequestRejectedResponse, |
| 5 | + photoVerificationRequestsListPending, |
| 6 | + photoVerificationRequestsListUserSearch, |
| 7 | + photoVerificationRequestDiscordUpdateResponse, |
| 8 | +} = require('../../mock-data/photo-verification'); |
| 9 | +// const { |
| 10 | +// extensionRequestLogs, |
| 11 | +// extensionRequestLogsInSentence, |
| 12 | +// } = require('../../mock-data/logs'); |
| 13 | +// const { |
| 14 | +// userSunny, |
| 15 | +// userRandhir, |
| 16 | +// allUsersData, |
| 17 | +// superUserForAudiLogs, |
| 18 | +// searchedUserForAuditLogs, |
| 19 | +// } = require('../../mock-data/users'); |
| 20 | +// const { usersStatus } = require('../../mock-data/users-status'); |
| 21 | +const baseUrl = 'http://localhost:8000/photo-verification-requests'; |
| 22 | + |
| 23 | +describe('Tests the Photo Verification Screen', () => { |
| 24 | + let browser; |
| 25 | + let page; |
| 26 | + let title; |
| 27 | + let searchBar; |
| 28 | + let photoVerificationRequestsElement; |
| 29 | + jest.setTimeout(60000); |
| 30 | + |
| 31 | + beforeAll(async () => { |
| 32 | + browser = await puppeteer.launch({ |
| 33 | + headless: 'new', |
| 34 | + ignoreHTTPSErrors: true, |
| 35 | + args: ['--incognito', '--disable-web-security'], |
| 36 | + devtools: false, |
| 37 | + }); |
| 38 | + |
| 39 | + page = await browser.newPage(); |
| 40 | + |
| 41 | + await page.setRequestInterception(true); |
| 42 | + |
| 43 | + page.on('request', (interceptedRequest) => { |
| 44 | + const url = interceptedRequest.url(); |
| 45 | + if (url === 'https://api.realdevsquad.com/users/picture/all/') { |
| 46 | + interceptedRequest.respond({ |
| 47 | + status: 200, |
| 48 | + contentType: 'application/json', |
| 49 | + headers: { |
| 50 | + 'Access-Control-Allow-Origin': '*', |
| 51 | + 'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE, OPTIONS', |
| 52 | + 'Access-Control-Allow-Headers': 'Content-Type, Authorization', |
| 53 | + }, |
| 54 | + body: JSON.stringify(photoVerificationRequestsListPending), |
| 55 | + }); |
| 56 | + } else if ( |
| 57 | + url === |
| 58 | + 'https://api.realdevsquad.com/users/picture/all/?username=vinayak-g' |
| 59 | + ) { |
| 60 | + interceptedRequest.respond({ |
| 61 | + status: 200, |
| 62 | + contentType: 'application/json', |
| 63 | + headers: { |
| 64 | + 'Access-Control-Allow-Origin': '*', |
| 65 | + 'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE, OPTIONS', |
| 66 | + 'Access-Control-Allow-Headers': 'Content-Type, Authorization', |
| 67 | + }, |
| 68 | + body: JSON.stringify(photoVerificationRequestsListUserSearch), |
| 69 | + }); |
| 70 | + } else if ( |
| 71 | + url === |
| 72 | + `https://api.realdevsquad.com/users/picture/verify/${photoVerificationRequestsListPending.data[0].userId}/?status=APPROVED&type=both` |
| 73 | + ) { |
| 74 | + interceptedRequest.respond({ |
| 75 | + status: 200, |
| 76 | + contentType: 'application/json', |
| 77 | + headers: { |
| 78 | + 'Access-Control-Allow-Origin': '*', |
| 79 | + 'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE, OPTIONS', |
| 80 | + 'Access-Control-Allow-Headers': 'Content-Type, Authorization', |
| 81 | + }, |
| 82 | + body: JSON.stringify(photoVerificationRequestApprovedResponse), |
| 83 | + }); |
| 84 | + } else if ( |
| 85 | + url === |
| 86 | + `https://api.realdevsquad.com/users/picture/verify/${photoVerificationRequestsListPending.data[0].userId}/?status=REJECTED&type=both` |
| 87 | + ) { |
| 88 | + interceptedRequest.respond({ |
| 89 | + status: 200, |
| 90 | + contentType: 'application/json', |
| 91 | + headers: { |
| 92 | + 'Access-Control-Allow-Origin': '*', |
| 93 | + 'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE, OPTIONS', |
| 94 | + 'Access-Control-Allow-Headers': 'Content-Type, Authorization', |
| 95 | + }, |
| 96 | + body: JSON.stringify(photoVerificationRequestRejectedResponse), |
| 97 | + }); |
| 98 | + } else if ( |
| 99 | + url === |
| 100 | + `https://api.realdevsquad.com/discord-actions/avatar/update/${photoVerificationRequestsListPending.data[0].discordId}` |
| 101 | + ) { |
| 102 | + interceptedRequest.respond({ |
| 103 | + status: 200, |
| 104 | + contentType: 'application/json', |
| 105 | + headers: { |
| 106 | + 'Access-Control-Allow-Origin': '*', |
| 107 | + 'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE, OPTIONS', |
| 108 | + 'Access-Control-Allow-Headers': 'Content-Type, Authorization', |
| 109 | + }, |
| 110 | + body: JSON.stringify(photoVerificationRequestDiscordUpdateResponse), |
| 111 | + }); |
| 112 | + } else { |
| 113 | + interceptedRequest.continue(); |
| 114 | + } |
| 115 | + }); |
| 116 | + |
| 117 | + await page.goto(baseUrl); |
| 118 | + |
| 119 | + await page.waitForNetworkIdle(); |
| 120 | + |
| 121 | + title = await page.$('.header'); |
| 122 | + searchBar = await page.$('#search'); |
| 123 | + photoVerificationRequestsElement = await page.$( |
| 124 | + '.photo-verification-requests', |
| 125 | + ); |
| 126 | + }); |
| 127 | + |
| 128 | + afterEach(async () => { |
| 129 | + await page.goto('http://localhost:8000/photo-verification-requests'); |
| 130 | + await page.waitForNetworkIdle(); |
| 131 | + }); |
| 132 | + afterAll(async () => { |
| 133 | + await browser.close(); |
| 134 | + }); |
| 135 | + it('Checks the UI elements on photo verification requests listing page', async () => { |
| 136 | + title = await page.$('.header'); |
| 137 | + searchBar = await page.$('#search'); |
| 138 | + photoVerificationRequestCardList = await page.$$( |
| 139 | + '.photo-verification-card', |
| 140 | + ); |
| 141 | + photoVerificationRequestsElement = await page.$( |
| 142 | + '.photo-verification-requests', |
| 143 | + ); |
| 144 | + expect(title).toBeTruthy(); |
| 145 | + expect(searchBar).toBeTruthy(); |
| 146 | + expect(photoVerificationRequestCardList.length).toBe(2); |
| 147 | + expect(photoVerificationRequestsElement).toBeTruthy(); |
| 148 | + }); |
| 149 | + |
| 150 | + it('checks the search functionality', async () => { |
| 151 | + await page.type('#user-search', 'vinayak-g'); |
| 152 | + await page.keyboard.press('Enter'); |
| 153 | + await page.waitForNetworkIdle(); |
| 154 | + |
| 155 | + const cardsList = await page.$$('.photo-verification-card'); |
| 156 | + expect(cardsList.length).toBe(1); |
| 157 | + const cardTextContent = await page.evaluate( |
| 158 | + (element) => element.textContent, |
| 159 | + cardsList[0], |
| 160 | + ); |
| 161 | + expect(cardTextContent).toContain('vinayak-g'); |
| 162 | + }); |
| 163 | + |
| 164 | + it('checks the refresh discord avatar image functionality', async () => { |
| 165 | + const photoVerificationRequestId = |
| 166 | + photoVerificationRequestsListPending.data[0].id; |
| 167 | + |
| 168 | + photoVerificationRequestCard = await page.$( |
| 169 | + `.photo-verification-card--${photoVerificationRequestId}`, |
| 170 | + ); |
| 171 | + |
| 172 | + const refreshButton = await photoVerificationRequestCard.$( |
| 173 | + '.refresh-discord-avatar-button', |
| 174 | + ); |
| 175 | + |
| 176 | + await refreshButton.click(); |
| 177 | + // wait for 500ms for the request to complete |
| 178 | + await page.waitForTimeout(500); |
| 179 | + |
| 180 | + photoVerificationRequestCard = await page.$( |
| 181 | + `.photo-verification-card--${photoVerificationRequestId}`, |
| 182 | + ); |
| 183 | + |
| 184 | + const discordImage = await photoVerificationRequestCard.$( |
| 185 | + '.photo-verification-image-box__block--discord', |
| 186 | + ); |
| 187 | + |
| 188 | + const discordImageSrc = await page.evaluate( |
| 189 | + (element) => element.querySelector('img').src, |
| 190 | + discordImage, |
| 191 | + ); |
| 192 | + |
| 193 | + expect(discordImageSrc).toBe( |
| 194 | + photoVerificationRequestDiscordUpdateResponse.discordAvatarUrl, |
| 195 | + ); |
| 196 | + }); |
| 197 | + it('checks the reject photo verification functionality', async () => { |
| 198 | + const photoVerificationRequestId = |
| 199 | + photoVerificationRequestsListPending.data[0].id; |
| 200 | + |
| 201 | + photoVerificationRequestCard = await page.$( |
| 202 | + `.photo-verification-card--${photoVerificationRequestId}`, |
| 203 | + ); |
| 204 | + |
| 205 | + const rejectButton = await photoVerificationRequestCard.$('.reject-button'); |
| 206 | + |
| 207 | + await rejectButton.click(); |
| 208 | + // wait for 2500ms for the request to complete |
| 209 | + await page.waitForTimeout(2500); |
| 210 | + |
| 211 | + photoVerificationRequestCard = await page.$( |
| 212 | + `.photo-verification-card--${photoVerificationRequestId}`, |
| 213 | + ); |
| 214 | + |
| 215 | + expect(photoVerificationRequestCard).toBe(null); |
| 216 | + }); |
| 217 | + |
| 218 | + it('checks the reject photo verification functionality', async () => { |
| 219 | + await page.evaluate(() => { |
| 220 | + window.location.reload = () => { |
| 221 | + console.log('window.location.reload was called'); |
| 222 | + }; |
| 223 | + }); |
| 224 | + const photoVerificationRequestId = |
| 225 | + photoVerificationRequestsListPending.data[0].id; |
| 226 | + |
| 227 | + photoVerificationRequestCard = await page.$( |
| 228 | + `.photo-verification-card--${photoVerificationRequestId}`, |
| 229 | + ); |
| 230 | + |
| 231 | + const approveButton = await photoVerificationRequestCard.$( |
| 232 | + '.approve-both-button', |
| 233 | + ); |
| 234 | + |
| 235 | + await approveButton.click(); |
| 236 | + // wait for 500ms for the request to complete |
| 237 | + await page.waitForTimeout(500); |
| 238 | + |
| 239 | + photoVerificationRequestCard = await page.$( |
| 240 | + `.photo-verification-card--${photoVerificationRequestId}`, |
| 241 | + ); |
| 242 | + |
| 243 | + responseMessage = await photoVerificationRequestCard.$eval( |
| 244 | + 'p', |
| 245 | + (el) => el.textContent, |
| 246 | + ); |
| 247 | + |
| 248 | + expect(responseMessage).toBe( |
| 249 | + photoVerificationRequestApprovedResponse.message, |
| 250 | + ); |
| 251 | + }); |
| 252 | + |
| 253 | + it('Checks details of the first photo verification card', async () => { |
| 254 | + photoVerificationRequestCardList = await page.$$( |
| 255 | + '.photo-verification-card', |
| 256 | + ); |
| 257 | + |
| 258 | + const firstPhotoVerificationRequestCard = |
| 259 | + photoVerificationRequestCardList[0]; |
| 260 | + |
| 261 | + const titleText = await firstPhotoVerificationRequestCard.$eval( |
| 262 | + 'h3', |
| 263 | + (el) => el.textContent, |
| 264 | + ); |
| 265 | + expect(titleText).toBe( |
| 266 | + `Photo Verifcation for ${photoVerificationRequestsListPending.data[0].user.username}`, |
| 267 | + ); |
| 268 | + }); |
| 269 | +}); |
0 commit comments