generated from Real-Dev-Squad/website-template
-
Notifications
You must be signed in to change notification settings - Fork 154
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: photo verification dashboard #746
Open
ivinayakg
wants to merge
8
commits into
develop
Choose a base branch
from
feat/photo-verification-dashboard
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
a56cf19
feat: photo verification dashboard done
ivinayakg 48f28a4
test: tests written for photo verification flow
ivinayakg 62f63ff
feat: photo verification dashboard done
ivinayakg c6dcafb
test: tests written for photo verification flow
ivinayakg d9aeee2
Merge branch 'feat/photo-verification-dashboard' of https://github.co…
ivinayakg bc87252
refact: photo-verification refresh discord image link
ivinayakg 8318110
Merge branch 'develop' into feat/photo-verification-dashboard
ivinayakg c94bbad
Merge branch 'develop' into feat/photo-verification-dashboard
Achintya-Chatterjee File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
269 changes: 269 additions & 0 deletions
269
__tests__/photo-verification/photo-verification.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,269 @@ | ||
const puppeteer = require('puppeteer'); | ||
const { | ||
photoVerificationRequestApprovedResponse, | ||
photoVerificationRequestRejectedResponse, | ||
photoVerificationRequestsListPending, | ||
photoVerificationRequestsListUserSearch, | ||
photoVerificationRequestDiscordUpdateResponse, | ||
} = require('../../mock-data/photo-verification'); | ||
// const { | ||
// extensionRequestLogs, | ||
// extensionRequestLogsInSentence, | ||
// } = require('../../mock-data/logs'); | ||
// const { | ||
// userSunny, | ||
// userRandhir, | ||
// allUsersData, | ||
// superUserForAudiLogs, | ||
// searchedUserForAuditLogs, | ||
// } = require('../../mock-data/users'); | ||
// const { usersStatus } = require('../../mock-data/users-status'); | ||
const baseUrl = 'http://localhost:8000/photo-verification-requests'; | ||
|
||
describe('Tests the Photo Verification Screen', () => { | ||
let browser; | ||
let page; | ||
let title; | ||
let searchBar; | ||
let photoVerificationRequestsElement; | ||
jest.setTimeout(60000); | ||
|
||
beforeAll(async () => { | ||
browser = await puppeteer.launch({ | ||
headless: 'new', | ||
ignoreHTTPSErrors: true, | ||
args: ['--incognito', '--disable-web-security'], | ||
devtools: false, | ||
}); | ||
|
||
page = await browser.newPage(); | ||
|
||
await page.setRequestInterception(true); | ||
|
||
page.on('request', (interceptedRequest) => { | ||
const url = interceptedRequest.url(); | ||
if (url === 'https://api.realdevsquad.com/users/picture/all/') { | ||
interceptedRequest.respond({ | ||
status: 200, | ||
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(photoVerificationRequestsListPending), | ||
}); | ||
} else if ( | ||
url === | ||
'https://api.realdevsquad.com/users/picture/all/?username=vinayak-g' | ||
) { | ||
interceptedRequest.respond({ | ||
status: 200, | ||
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(photoVerificationRequestsListUserSearch), | ||
}); | ||
} else if ( | ||
url === | ||
`https://api.realdevsquad.com/users/picture/verify/${photoVerificationRequestsListPending.data[0].userId}/?status=APPROVED&type=both` | ||
) { | ||
interceptedRequest.respond({ | ||
status: 200, | ||
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(photoVerificationRequestApprovedResponse), | ||
}); | ||
} else if ( | ||
url === | ||
`https://api.realdevsquad.com/users/picture/verify/${photoVerificationRequestsListPending.data[0].userId}/?status=REJECTED&type=both` | ||
) { | ||
interceptedRequest.respond({ | ||
status: 200, | ||
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(photoVerificationRequestRejectedResponse), | ||
}); | ||
} else if ( | ||
url === | ||
`https://api.realdevsquad.com/discord-actions/avatar/photo-verification-update/${photoVerificationRequestsListPending.data[0].discordId}` | ||
) { | ||
interceptedRequest.respond({ | ||
status: 200, | ||
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(photoVerificationRequestDiscordUpdateResponse), | ||
}); | ||
} else { | ||
interceptedRequest.continue(); | ||
} | ||
}); | ||
|
||
await page.goto(baseUrl); | ||
|
||
await page.waitForNetworkIdle(); | ||
|
||
title = await page.$('.header'); | ||
searchBar = await page.$('#search'); | ||
photoVerificationRequestsElement = await page.$( | ||
'.photo-verification-requests', | ||
); | ||
}); | ||
|
||
afterEach(async () => { | ||
await page.goto('http://localhost:8000/photo-verification-requests'); | ||
await page.waitForNetworkIdle(); | ||
}); | ||
afterAll(async () => { | ||
await browser.close(); | ||
}); | ||
it('Checks the UI elements on photo verification requests listing page', async () => { | ||
title = await page.$('.header'); | ||
searchBar = await page.$('#search'); | ||
photoVerificationRequestCardList = await page.$$( | ||
'.photo-verification-card', | ||
); | ||
photoVerificationRequestsElement = await page.$( | ||
'.photo-verification-requests', | ||
); | ||
expect(title).toBeTruthy(); | ||
expect(searchBar).toBeTruthy(); | ||
expect(photoVerificationRequestCardList.length).toBe(2); | ||
expect(photoVerificationRequestsElement).toBeTruthy(); | ||
}); | ||
|
||
it('checks the search functionality', async () => { | ||
await page.type('#user-search', 'vinayak-g'); | ||
await page.keyboard.press('Enter'); | ||
await page.waitForNetworkIdle(); | ||
|
||
const cardsList = await page.$$('.photo-verification-card'); | ||
expect(cardsList.length).toBe(1); | ||
const cardTextContent = await page.evaluate( | ||
(element) => element.textContent, | ||
cardsList[0], | ||
); | ||
expect(cardTextContent).toContain('vinayak-g'); | ||
}); | ||
|
||
it('checks the refresh discord avatar image functionality', async () => { | ||
const photoVerificationRequestId = | ||
photoVerificationRequestsListPending.data[0].id; | ||
|
||
photoVerificationRequestCard = await page.$( | ||
`.photo-verification-card--${photoVerificationRequestId}`, | ||
); | ||
|
||
const refreshButton = await photoVerificationRequestCard.$( | ||
'.refresh-discord-avatar-button', | ||
); | ||
|
||
await refreshButton.click(); | ||
// wait for 500ms for the request to complete | ||
await page.waitForTimeout(500); | ||
|
||
photoVerificationRequestCard = await page.$( | ||
`.photo-verification-card--${photoVerificationRequestId}`, | ||
); | ||
|
||
const discordImage = await photoVerificationRequestCard.$( | ||
'.photo-verification-image-box__block--discord', | ||
); | ||
|
||
const discordImageSrc = await page.evaluate( | ||
(element) => element.querySelector('img').src, | ||
discordImage, | ||
); | ||
|
||
expect(discordImageSrc).toBe( | ||
photoVerificationRequestDiscordUpdateResponse.discordAvatarUrl, | ||
); | ||
}); | ||
it('checks the reject photo verification functionality', async () => { | ||
const photoVerificationRequestId = | ||
photoVerificationRequestsListPending.data[0].id; | ||
|
||
photoVerificationRequestCard = await page.$( | ||
`.photo-verification-card--${photoVerificationRequestId}`, | ||
); | ||
|
||
const rejectButton = await photoVerificationRequestCard.$('.reject-button'); | ||
|
||
await rejectButton.click(); | ||
// wait for 2500ms for the request to complete | ||
await page.waitForTimeout(2500); | ||
|
||
photoVerificationRequestCard = await page.$( | ||
`.photo-verification-card--${photoVerificationRequestId}`, | ||
); | ||
|
||
expect(photoVerificationRequestCard).toBe(null); | ||
}); | ||
|
||
it('checks the reject photo verification functionality', async () => { | ||
await page.evaluate(() => { | ||
window.location.reload = () => { | ||
console.log('window.location.reload was called'); | ||
}; | ||
}); | ||
const photoVerificationRequestId = | ||
photoVerificationRequestsListPending.data[0].id; | ||
|
||
photoVerificationRequestCard = await page.$( | ||
`.photo-verification-card--${photoVerificationRequestId}`, | ||
); | ||
|
||
const approveButton = await photoVerificationRequestCard.$( | ||
'.approve-both-button', | ||
); | ||
|
||
await approveButton.click(); | ||
// wait for 500ms for the request to complete | ||
await page.waitForTimeout(500); | ||
|
||
photoVerificationRequestCard = await page.$( | ||
`.photo-verification-card--${photoVerificationRequestId}`, | ||
); | ||
|
||
responseMessage = await photoVerificationRequestCard.$eval( | ||
'p', | ||
(el) => el.textContent, | ||
); | ||
|
||
expect(responseMessage).toBe( | ||
photoVerificationRequestApprovedResponse.message, | ||
); | ||
}); | ||
|
||
it('Checks details of the first photo verification card', async () => { | ||
photoVerificationRequestCardList = await page.$$( | ||
'.photo-verification-card', | ||
); | ||
|
||
const firstPhotoVerificationRequestCard = | ||
photoVerificationRequestCardList[0]; | ||
|
||
const titleText = await firstPhotoVerificationRequestCard.$eval( | ||
'h3', | ||
(el) => el.textContent, | ||
); | ||
expect(titleText).toBe( | ||
`Photo Verifcation for ${photoVerificationRequestsListPending.data[0].user.username}`, | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we remove this?