UNPKG

external-services-automation

Version:

External services automation library for Playwright and Cucumber

57 lines (56 loc) 2.56 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.KindeAuthService = void 0; const ConfirmCodePage_1 = require("../pages/kinde/ConfirmCodePage"); const LoginPage_1 = require("../pages/kinde/LoginPage"); const PasswordSetupPage_1 = require("../pages/kinde/PasswordSetupPage"); const RegisterPage_1 = require("../pages/kinde/RegisterPage"); const temp_email_utils_1 = require("../utils/temp-email-utils"); class KindeAuthService { constructor(page) { this.loginPage = new LoginPage_1.LoginPage(page); this.registerPage = new RegisterPage_1.RegisterPage(page); this.confirmCodePage = new ConfirmCodePage_1.ConfirmCodePage(page); this.passwordSetupPage = new PasswordSetupPage_1.PasswordSetupPage(page); } async createAccountWithEmailVerification() { await this.loginPage.navigate(); await this.loginPage.goToRegisterPage(); await this.registerPage.isOnRegisterPage(); this.emailClient = temp_email_utils_1.GuerrillaMailClient.createIsolatedClient(); this.tempEmail = await this.emailClient.createMail(); const firstName = 'Test'; const lastName = 'User'; await this.registerPage.fillAndSubmitCreateAccountForm(firstName, lastName, this.tempEmail, false // Don't accept marketing emails ); await this.confirmCodePage.isOnConfirmCodePage(); const emailData = await this.emailClient.readMailBySubject(/Email verification code/i, 120000, // 2 minutes timeout 5000 // Check every 5 seconds ); const codeMatch = emailData.mail_body?.match(/\b\d{6}\b/); if (codeMatch) { this.verificationCode = codeMatch[0]; await this.confirmCodePage.submitConfirmationCode(this.verificationCode); } else { throw new Error('Could not extract verification code from email'); } await this.passwordSetupPage.isOnPasswordSetupPage(); const password = 'TestPassword123!'; await this.passwordSetupPage.submitPasswordForm(password); await this.passwordSetupPage.dontUseMFA(); } async deleteTemporaryEmail() { if (this.tempEmail) { try { this.tempEmail = undefined; this.verificationCode = undefined; this.emailClient = undefined; } catch (error) { console.warn("Could not clean up temporary email:", error); } } } } exports.KindeAuthService = KindeAuthService;