Skip to content

Commit 44df325

Browse files
Restrict approve and reject buttons on the Task Request detail page to super_user only (#896)
* Restrict approve and reject buttons on the Task Request detail page to super users only * fixes naming convention, button render logic * fix: reject button should not be part of the dom if condition not met * changed the superUser data, make the task-request/script.js type module * added tests how buttons should render for non-super user * Update task-requestDetails.test.js removed unused variable * using data-testid for the tests * importing the superuser data * removing reject button from dom after successful task update * put the changes behind the feature flag --------- Co-authored-by: Achintya Chatterjee <[email protected]>
1 parent 6994284 commit 44df325

File tree

6 files changed

+224
-54
lines changed

6 files changed

+224
-54
lines changed

__tests__/task-requests/task-requestDetails.test.js

Lines changed: 73 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,67 @@ const {
33
urlMappings,
44
defaultMockResponseHeaders,
55
} = require('../../mock-data/taskRequests');
6+
const { user } = require('../../mock-data/users/index.js');
7+
8+
describe('Request container for non-super users', () => {
9+
let browser;
10+
let page;
11+
jest.setTimeout(60000);
12+
13+
beforeAll(async () => {
14+
browser = await puppeteer.launch({
15+
headless: 'new',
16+
ignoreHTTPSErrors: true,
17+
args: ['--incognito', '--disable-web-security'],
18+
devtools: false,
19+
});
20+
page = await browser.newPage();
21+
await page.setRequestInterception(true);
22+
page.on('request', (interceptedRequest) => {
23+
const url = interceptedRequest.url();
24+
if (url == 'https://staging-api.realdevsquad.com/users/self') {
25+
interceptedRequest.respond({
26+
...defaultMockResponseHeaders,
27+
body: JSON.stringify(user),
28+
});
29+
} else if (urlMappings.hasOwnProperty(url)) {
30+
interceptedRequest.respond({
31+
...defaultMockResponseHeaders,
32+
body: JSON.stringify(urlMappings[url]),
33+
});
34+
} else {
35+
interceptedRequest.continue();
36+
}
37+
});
38+
await page.goto(
39+
'http://localhost:8000/task-requests/details/?id=dM5wwD9QsiTzi7eG7Oq5',
40+
);
41+
});
42+
43+
afterAll(async () => {
44+
await browser.close();
45+
});
46+
47+
it('Approve and Reject buttons should not render for non-super users', async function () {
48+
await page.goto(
49+
'http://localhost:8000/task-requests/details/?id=dM5wwD9QsiTzi7eG7Oq5&&dev=true',
50+
);
51+
const approveButton = await page.$('[data-testid="task-approve-button"]');
52+
const rejectButton = await page.$('[data-testid="task-reject-button"]');
53+
expect(approveButton).toBeNull();
54+
expect(rejectButton).toBeNull();
55+
});
56+
57+
it('Should render task status for non-super users', async function () {
58+
await page.goto(
59+
'http://localhost:8000/task-requests/details/?id=dM5wwD9QsiTzi7eG7Oq5&&dev=true',
60+
);
61+
const taskRequestStatus = await page.$(
62+
'[data-testid="requestors-task-status"]',
63+
);
64+
expect(taskRequestStatus).toBeTruthy();
65+
});
66+
});
667

768
describe('Task request details page', () => {
869
let browser;
@@ -89,9 +150,12 @@ describe('Task request details page', () => {
89150
);
90151
});
91152

92-
it('Should contain Approve and Reject buttons', async function () {
93-
const approveButton = await page.$('.requestors__conatainer__list__button');
94-
const rejectButton = await page.$('.request-details__reject__button');
153+
it('Should render Approve and Reject buttons for super users', async function () {
154+
await page.goto(
155+
'http://localhost:8000/task-requests/details/?id=dM5wwD9QsiTzi7eG7Oq5&&dev=true',
156+
);
157+
const approveButton = await page.$('[data-testid="task-approve-button"]');
158+
const rejectButton = await page.$('[data-testid="task-reject-button"]');
95159
expect(approveButton).toBeTruthy();
96160
expect(rejectButton).toBeTruthy();
97161
});
@@ -180,9 +244,12 @@ describe('Task request details page with markdown support in description', () =>
180244
expect(descriptionHtmlValue).toContain('<h3 id="heading">Heading</h3>');
181245
});
182246

183-
it('Should contain Approve and Reject buttons', async function () {
184-
const approveButton = await page.$('.requestors__conatainer__list__button');
185-
const rejectButton = await page.$('.request-details__reject__button');
247+
it('Should render Approve and Reject buttons for super users', async function () {
248+
await page.goto(
249+
'http://localhost:8000/task-requests/details/?id=dM5wwD9QsiTzi7eG7Oq5&&dev=true',
250+
);
251+
const approveButton = await page.$('[data-testid="task-approve-button"]');
252+
const rejectButton = await page.$('[data-testid="task-reject-button"]');
186253
expect(approveButton).toBeTruthy();
187254
expect(rejectButton).toBeTruthy();
188255
});

mock-data/taskRequests/index.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
const { superUserDetails } = require('../users/mockdata.js');
2+
13
const fetchedTaskRequests = [
24
{
35
id: '123CCXSDF123',
@@ -260,7 +262,6 @@ const githubIssue = {
260262
performed_via_github_app: null,
261263
state_reason: 'completed',
262264
};
263-
264265
const individualTaskDetail = {
265266
message: 'task returned successfully',
266267
taskData: {
@@ -306,7 +307,6 @@ const userInformationTaskCreation = {
306307
},
307308
},
308309
};
309-
310310
const userInformation = {
311311
message: 'User returned successfully!',
312312
user: {
@@ -351,6 +351,7 @@ const defaultMockResponseHeaders = {
351351
};
352352

353353
const urlMappings = {
354+
'https://staging-api.realdevsquad.com/users/self': superUserDetails.user,
354355
'https://api.realdevsquad.com/taskRequests/dM5wwD9QsiTzi7eG7Oq5':
355356
individualTaskReqDetail,
356357
'https://api.realdevsquad.com/taskRequests/dM5wwD9QsiTzi7eG7Oq6':

task-requests/details/index.html

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@
2424
crossorigin="anonymous"
2525
referrerpolicy="no-referrer"
2626
></script>
27-
<script src="/task-requests/details/script.js" defer></script>
2827
<script
2928
src="https://cdnjs.cloudflare.com/ajax/libs/showdown/2.1.0/showdown.min.js"
3029
integrity="sha512-LhccdVNGe2QMEfI3x4DVV3ckMRe36TfydKss6mJpdHjNFiV07dFpS2xzeZedptKZrwxfICJpez09iNioiSZ3hA=="
3130
crossorigin="anonymous"
3231
referrerpolicy="no-referrer"
3332
></script>
33+
<script type="module" src="/task-requests/details/script.js" defer></script>
3434
</head>
3535
<body>
3636
<div class="header">
@@ -85,11 +85,6 @@ <h4 class="requestors__container__title">Requestors</h4>
8585
</ul>
8686
</div>
8787
</div>
88-
<div class="reject__container">
89-
<button id="reject-button" class="request-details__reject__button">
90-
Reject
91-
</button>
92-
</div>
9388
</div>
9489
</div>
9590
<div id="toast_task_details" class="hidden">

0 commit comments

Comments
 (0)