Skip to content

Commit 2b39df5

Browse files
authored
fix: ensure tests use staging API to prevent production impact (#911)
* fix: ensure tests use staging API to prevent production impact * resolve conflict * fix: properly declare constants * API URL fix
1 parent 2629ec5 commit 2b39df5

23 files changed

+267
-275
lines changed

__tests__/applications/applications.test.js

Lines changed: 30 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ const {
55
acceptedApplications,
66
} = require('../../mock-data/applications');
77
const { superUserForAudiLogs } = require('../../mock-data/users');
8-
9-
const SITE_URL = 'http://localhost:8000';
10-
// helper/loadEnv.js file causes API_BASE_URL to be stagin-api on local env url in taskRequest/index.html
11-
const API_BASE_URL = 'https://staging-api.realdevsquad.com';
8+
const {
9+
STAGING_API_URL,
10+
LOCAL_TEST_PAGE_URL,
11+
} = require('../../mock-data/constants');
1212

1313
describe('Applications page', () => {
1414
let browser;
@@ -22,19 +22,19 @@ describe('Applications page', () => {
2222
ignoreHTTPSErrors: true,
2323
args: ['--incognito', '--disable-web-security'],
2424
});
25-
});
26-
beforeEach(async () => {
25+
2726
page = await browser.newPage();
2827

2928
await page.setRequestInterception(true);
3029

31-
page.on('request', (request) => {
30+
page.on('request', (interceptedRequest) => {
31+
const url = interceptedRequest.url();
3232
if (
33-
request.url() === `${API_BASE_URL}/applications?size=6` ||
34-
request.url() ===
35-
`${API_BASE_URL}/applications?next=YwTi6zFNI3GlDsZVjD8C&size=6`
33+
url === `${STAGING_API_URL}/applications?size=6` ||
34+
url ===
35+
`${STAGING_API_URL}/applications?next=YwTi6zFNI3GlDsZVjD8C&size=6`
3636
) {
37-
request.respond({
37+
interceptedRequest.respond({
3838
status: 200,
3939
contentType: 'application/json',
4040
body: JSON.stringify({
@@ -48,9 +48,9 @@ describe('Applications page', () => {
4848
},
4949
});
5050
} else if (
51-
request.url() === `${API_BASE_URL}/applications?size=6&status=accepted`
51+
url === `${STAGING_API_URL}/applications?size=6&status=accepted`
5252
) {
53-
request.respond({
53+
interceptedRequest.respond({
5454
status: 200,
5555
contentType: 'application/json',
5656
body: JSON.stringify({ applications: acceptedApplications }),
@@ -60,8 +60,8 @@ describe('Applications page', () => {
6060
'Access-Control-Allow-Headers': 'Content-Type, Authorization',
6161
},
6262
});
63-
} else if (request.url() === `${API_BASE_URL}/users/self`) {
64-
request.respond({
63+
} else if (url === `${STAGING_API_URL}/users/self`) {
64+
interceptedRequest.respond({
6565
status: 200,
6666
contentType: 'application/json',
6767
headers: {
@@ -72,9 +72,9 @@ describe('Applications page', () => {
7272
body: JSON.stringify(superUserForAudiLogs),
7373
});
7474
} else if (
75-
request.url() === `${API_BASE_URL}/applications/lavEduxsb2C6Bl4s289P`
75+
url === `${STAGING_API_URL}/applications/lavEduxsb2C6Bl4s289P`
7676
) {
77-
request.respond({
77+
interceptedRequest.respond({
7878
status: 200,
7979
contentType: 'application/json',
8080
body: JSON.stringify({
@@ -87,10 +87,10 @@ describe('Applications page', () => {
8787
},
8888
});
8989
} else if (
90-
request.url() ===
91-
`${API_BASE_URL}/applications?size=6&status=accepted&dev=true`
90+
url ===
91+
`${STAGING_API_URL}/applications?size=6&status=accepted&dev=true`
9292
) {
93-
request.respond({
93+
interceptedRequest.respond({
9494
status: 200,
9595
contentType: 'application/json',
9696
body: JSON.stringify({
@@ -104,10 +104,9 @@ describe('Applications page', () => {
104104
},
105105
});
106106
} else if (
107-
request.url() ===
108-
`${API_BASE_URL}/applications?size=6&status=pending&dev=true`
107+
url === `${STAGING_API_URL}/applications?size=6&status=pending&dev=true`
109108
) {
110-
request.respond({
109+
interceptedRequest.respond({
111110
status: 200,
112111
contentType: 'application/json',
113112
body: JSON.stringify({
@@ -121,10 +120,10 @@ describe('Applications page', () => {
121120
},
122121
});
123122
} else {
124-
request.continue();
123+
interceptedRequest.continue();
125124
}
126125
});
127-
await page.goto(`${SITE_URL}/applications`);
126+
await page.goto(`${LOCAL_TEST_PAGE_URL}/applications`);
128127
await page.waitForNetworkIdle();
129128
});
130129

@@ -147,13 +146,15 @@ describe('Applications page', () => {
147146
});
148147

149148
it('should render the index of pending applications under dev flag === true', async function () {
150-
await page.goto(`${SITE_URL}/applications?dev=true&status=pending`);
149+
await page.goto(
150+
`${LOCAL_TEST_PAGE_URL}/applications?dev=true&status=pending`,
151+
);
151152
const indexOfApplication = await page.$$('[data-testid="user-index"]');
152153
expect(indexOfApplication).toBeTruthy();
153154
});
154155

155156
it('should render the initial UI elements under dev flag === true', async function () {
156-
await page.goto(`${SITE_URL}/applications?dev=true`);
157+
await page.goto(`${LOCAL_TEST_PAGE_URL}/applications?dev=true`);
157158
const title = await page.$('.header h1');
158159
const filterButton = await page.$('.filter-button');
159160
const applicationCards = await page.$$('.application-card');
@@ -191,7 +192,7 @@ describe('Applications page', () => {
191192
});
192193

193194
it('should load and render the accepted application requests when accept filter is selected from filter under dev flag === true along with the total count of the accepted applications', async function () {
194-
await page.goto(`${SITE_URL}/applications?dev=true`);
195+
await page.goto(`${LOCAL_TEST_PAGE_URL}/applications?dev=true`);
195196
await page.click('.filter-button');
196197

197198
await page.$eval('input[name="status"][value="accepted"]', (radio) =>
@@ -234,7 +235,7 @@ describe('Applications page', () => {
234235
});
235236

236237
it('under feature flag should open application details modal for application, when user click on card', async function () {
237-
await page.goto(`${SITE_URL}/applications/?dev=true`);
238+
await page.goto(`${LOCAL_TEST_PAGE_URL}/applications/?dev=true`);
238239
await page.waitForNetworkIdle();
239240
const applicationDetailsModal = await page.$('.application-details');
240241
expect(

0 commit comments

Comments
 (0)