|
| 1 | +const puppeteer = require('puppeteer'); |
| 2 | +const { |
| 3 | + pendingRequest, |
| 4 | + requestActionResponse, |
| 5 | + approvedRequest, |
| 6 | +} = require('../../mock-data/requests'); |
| 7 | +const { allUsersData } = require('../../mock-data/users'); |
| 8 | + |
| 9 | +const API_BASE_URL = 'https://api.realdevsquad.com'; |
| 10 | +const SITE_URL = 'http://localhost:8000'; |
| 11 | + |
| 12 | +describe('Tests the request card', () => { |
| 13 | + let browser; |
| 14 | + let page; |
| 15 | + jest.setTimeout(60000); |
| 16 | + |
| 17 | + beforeAll(async () => { |
| 18 | + browser = await puppeteer.launch({ |
| 19 | + headless: 'new', |
| 20 | + ignoreHTTPSErrors: true, |
| 21 | + args: ['--incognito', '--disable-web-security'], |
| 22 | + devtools: false, |
| 23 | + }); |
| 24 | + page = await browser.newPage(); |
| 25 | + |
| 26 | + await page.setRequestInterception(true); |
| 27 | + |
| 28 | + page.on('request', (interceptedRequest) => { |
| 29 | + const url = interceptedRequest.url(); |
| 30 | + |
| 31 | + if (url === `${API_BASE_URL}/users/search?role=in_discord`) { |
| 32 | + interceptedRequest.respond({ |
| 33 | + status: 200, |
| 34 | + contentType: 'application/json', |
| 35 | + headers: { |
| 36 | + 'Access-Control-Allow-Origin': '*', |
| 37 | + 'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE, OPTIONS', |
| 38 | + 'Access-Control-Allow-Headers': 'Content-Type, Authorization', |
| 39 | + }, |
| 40 | + body: JSON.stringify(allUsersData), |
| 41 | + }); |
| 42 | + } else if (url === `${API_BASE_URL}/requests?dev=true&type=OOO&size=12`) { |
| 43 | + interceptedRequest.respond({ |
| 44 | + status: 200, |
| 45 | + contentType: 'application/json', |
| 46 | + headers: { |
| 47 | + 'Access-Control-Allow-Origin': '*', |
| 48 | + 'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE, OPTIONS', |
| 49 | + 'Access-Control-Allow-Headers': 'Content-Type, Authorization', |
| 50 | + }, |
| 51 | + body: JSON.stringify(pendingRequest), |
| 52 | + }); |
| 53 | + } else if ( |
| 54 | + url === `${API_BASE_URL}/requests/Wl4TTbpSrQDIjs6KLJwD?dev=true` |
| 55 | + ) { |
| 56 | + interceptedRequest.respond({ |
| 57 | + status: 200, |
| 58 | + contentType: 'application/json', |
| 59 | + headers: { |
| 60 | + 'Access-Control-Allow-Origin': '*', |
| 61 | + 'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE, OPTIONS', |
| 62 | + 'Access-Control-Allow-Headers': 'Content-Type, Authorization', |
| 63 | + }, |
| 64 | + body: JSON.stringify(requestActionResponse), |
| 65 | + }); |
| 66 | + } else if ( |
| 67 | + url === `${API_BASE_URL}/requests?dev=true&id=Wl4TTbpSrQDIjs6KLJwD` |
| 68 | + ) { |
| 69 | + interceptedRequest.respond({ |
| 70 | + status: 200, |
| 71 | + contentType: 'application/json', |
| 72 | + headers: { |
| 73 | + 'Access-Control-Allow-Origin': '*', |
| 74 | + 'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE, OPTIONS', |
| 75 | + 'Access-Control-Allow-Headers': 'Content-Type, Authorization', |
| 76 | + }, |
| 77 | + body: JSON.stringify(approvedRequest), |
| 78 | + }); |
| 79 | + } else { |
| 80 | + interceptedRequest.continue(); |
| 81 | + } |
| 82 | + }); |
| 83 | + await page.goto(`${SITE_URL}/requests`); |
| 84 | + await page.waitForNetworkIdle(); |
| 85 | + }); |
| 86 | + |
| 87 | + afterAll(async () => { |
| 88 | + await browser.close(); |
| 89 | + }); |
| 90 | + |
| 91 | + it('should update the card when the accept or reject button is clicked', async () => { |
| 92 | + await page.waitForSelector('.request__status'); |
| 93 | + const statusButtonText = await page.$eval( |
| 94 | + '.request__status', |
| 95 | + (el) => el.textContent, |
| 96 | + ); |
| 97 | + expect(statusButtonText).toBe('Pending'); |
| 98 | + |
| 99 | + await page.click('.request__action__btn.accept__btn'); |
| 100 | + |
| 101 | + await page.waitForSelector('.request__status'); |
| 102 | + const updatedStatusButtonText = await page.$eval( |
| 103 | + '.request__status', |
| 104 | + (el) => el.textContent, |
| 105 | + ); |
| 106 | + expect(updatedStatusButtonText).toBe('Approved'); |
| 107 | + }); |
| 108 | +}); |
0 commit comments