Skip to content

Commit c6dcafb

Browse files
committed
test: tests written for photo verification flow
1 parent 62f63ff commit c6dcafb

File tree

4 files changed

+427
-7
lines changed

4 files changed

+427
-7
lines changed
Lines changed: 269 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,269 @@
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+
});
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
const photoVerificationRequestsListPending = {
2+
message: 'User image verification record fetched successfully!',
3+
data: [
4+
{
5+
id: 'BEtG17kv0H27lWOGwTZX',
6+
discordId: '238947756238758',
7+
userId: '8o7f87h3u4h98fh9843hf834',
8+
discord: {
9+
date: {
10+
_seconds: 1712788779,
11+
_nanoseconds: 192000000,
12+
},
13+
url: 'https://cdn.discordapp.com/avatars/238947756238758/b0a2691fd3e05c28858f435f11f02e41.png',
14+
approved: false,
15+
},
16+
profile: {
17+
date: {
18+
_seconds: 1712788779,
19+
_nanoseconds: 192000000,
20+
},
21+
url: 'https://res.cloudinary.com/profile/8o7f87h3u4h98fh9843hf834/umgnk8o7ujrzbmybnwzf.jpg',
22+
publicId: 'profile/8o7f87h3u4h98fh9843hf834/umgnk8o7ujrzbmybnwzf',
23+
approved: false,
24+
},
25+
status: 'PENDING',
26+
user: {
27+
username: 'vinayak-g',
28+
picture:
29+
'https://res.cloudinary.com/profile/8o7f87h3u4h98fh9843hf834/umgnk8o7ujrzbmybnwzf.jpg',
30+
},
31+
},
32+
{
33+
id: 'X1Kua1HeUqtlX5Z6xwSq',
34+
discordId: '238947756238758',
35+
userId: '8o7f87h3u4h98fh9843hf834',
36+
status: 'PENDING',
37+
discord: {
38+
date: {
39+
_seconds: 1712835230,
40+
_nanoseconds: 7000000,
41+
},
42+
approved: false,
43+
url: 'https://cdn.discordapp.com/avatars/238947756238758/b0a2691fd3e05c28858f435f11f02e41.png',
44+
},
45+
profile: {
46+
date: {
47+
_seconds: 1712835230,
48+
_nanoseconds: 7000000,
49+
},
50+
approved: false,
51+
},
52+
user: {
53+
username: 'vinayak-g',
54+
picture:
55+
'https://res.cloudinary.com/profile/8o7f87h3u4h98fh9843hf834/umgnk8o7ujrzbmybnwzf.jpg',
56+
},
57+
},
58+
],
59+
};
60+
61+
const photoVerificationRequestsListUserSearch = {
62+
message: 'User image verification record fetched successfully!',
63+
data: [
64+
{
65+
discordId: '238947756238758',
66+
userId: '8o7f87h3u4h98fh9843hf834',
67+
discord: {
68+
date: {
69+
_seconds: 1712788779,
70+
_nanoseconds: 192000000,
71+
},
72+
url: 'https://cdn.discordapp.com/avatars/238947756238758/b0a2691fd3e05c28858f435f11f02e41.png',
73+
approved: true,
74+
},
75+
profile: {
76+
date: {
77+
_seconds: 1712788779,
78+
_nanoseconds: 192000000,
79+
},
80+
url: 'https://res.cloudinary.com/profile/8o7f87h3u4h98fh9843hf834/umgnk8o7ujrzbmybnwzf.jpg',
81+
publicId: 'profile/8o7f87h3u4h98fh9843hf834/umgnk8o7ujrzbmybnwzf',
82+
approved: false,
83+
},
84+
status: 'PENDING',
85+
user: {
86+
username: 'vinayak-g',
87+
picture:
88+
'https://res.cloudinary.com/profile/8o7f87h3u4h98fh9843hf834/umgnk8o7ujrzbmybnwzf.jpg',
89+
},
90+
},
91+
],
92+
};
93+
94+
const photoVerificationRequestApprovedResponse = {
95+
message: 'User image data verified successfully',
96+
};
97+
98+
const photoVerificationRequestRejectedResponse = {
99+
message: 'User photo verification request rejected successfully',
100+
};
101+
102+
const photoVerificationRequestDiscordUpdateResponse = {
103+
message: 'Discord avatar URL updated successfully!',
104+
discordAvatarUrl:
105+
'https://cdn.discordapp.com/avatars/238947756238758/b0a2691fd3e05c28858f435f11f02e41_new.png',
106+
};
107+
108+
module.exports = {
109+
photoVerificationRequestApprovedResponse,
110+
photoVerificationRequestRejectedResponse,
111+
photoVerificationRequestsListPending,
112+
photoVerificationRequestsListUserSearch,
113+
photoVerificationRequestDiscordUpdateResponse,
114+
};

0 commit comments

Comments
 (0)