import selectors from '../../helpers/selectors'; import getBrowser from '../../helpers/puppeteer'; describe('RecoverPassword path', async() => { let browser; let page; beforeAll(async() => { browser = await getBrowser(); page = browser.page; }); beforeEach(async() => { await page.waitForState('login'); await page.waitToClick(selectors.recoverPassword.recoverPasswordButton); await page.waitForState('recover-password'); }); afterAll(async() => { await browser.close(); }); it('should not throw error if not exist user when select email option', async() => { await page.write(selectors.recoverPassword.email, 'fakeEmail@mydomain.com'); await page.waitToClick(selectors.recoverPassword.emailOption); await page.waitToClick(selectors.recoverPassword.sendEmailButton); const httpDataResponse = await page.waitForResponse(response => { return response.status() === 204 && response.url().includes(`VnUsers/recoverPassword`); }); const code = await httpDataResponse.ok(); expect(code).toBeTrue(); const message = await page.waitForSnackbar(); expect(message.text).toContain('Notification sent!'); }); it('should send email using email', async() => { await page.write(selectors.recoverPassword.email, 'BruceWayne@mydomain.com'); await page.waitToClick(selectors.recoverPassword.emailOption); await page.waitToClick(selectors.recoverPassword.sendEmailButton); const message = await page.waitForSnackbar(); expect(message.text).toContain('Notification sent!'); }); it('should send email using username', async() => { await page.write(selectors.recoverPassword.email, 'BruceWayne'); await page.waitToClick(selectors.recoverPassword.emailOption); await page.waitToClick(selectors.recoverPassword.sendEmailButton); const message = await page.waitForSnackbar(); expect(message.text).toContain('Notification sent!'); }); it('should send sms using username', async() => { await page.setRequestInterception(true); await page.write(selectors.recoverPassword.email, 'BruceWayne'); await page.waitToClick(selectors.recoverPassword.smsOption); page.on('request', request => { if (request.url().includes('recoverPasswordSMS')) { const body = JSON.parse(request.postData()); const isVerificationCode = Object.keys(body).includes('verificationCode'); if (!isVerificationCode) { request.respond({ content: 'application/json', headers: {'Access-Control-Allow-Origin': '*'}, body: JSON.stringify({code: '123456'}) }); } else { request.respond({ content: 'application/json', headers: {'Access-Control-Allow-Origin': '*'}, body: JSON.stringify({token: { 'id': 'A7al0KNofU7RFL5XPNubKsVjOAj80eoydXhm9i6rF4gj5kom6nEx4BG2bubzLocm', 'ttl': 1209600, 'created': '2024-05-30T10:43:36.014Z', 'userId': 9 }}) }); } } else request.continue(); }); await page.waitToClick(selectors.recoverPassword.sendEmailButton); const httpDataResponse = await page.waitForResponse(response => { return response.status() === 200 && response.url().includes(`VnUsers/recoverPasswordSMS`); }); const {code} = await httpDataResponse.json(); await page.write(selectors.recoverPassword.code, code); await page.waitToClick(selectors.recoverPassword.sendEmailButton); await page.waitForState('reset-password'); expect(await page.getState()).toContain('reset-password'); }); });