import { test, expect } from '@playwright/test'; import { userCredentials, subuserPhoneCredentials, subuserUsernameCredentials, operatorCredentials, customerRegistrationData, driverRegistrationData, invalidCredentials, loginAsUser, loginAsSubuserByPhone, loginAsSubuserByUsername, loginAsOperator, goToUserLogin, goToSubuserLogin, goToOperatorLogin, } from './fixtures'; /** User Authentication Tests */ // Customer number login tests test('[AUTH][User][Customer number] should login successfully', async ({ page }) => { await loginAsUser(page); }); test('[AUTH][User][Customer number] should fail to login using invalid password', async ({ page }) => { await goToUserLogin(page); await page.fill('input[name="customer_number"]', userCredentials.customerNumber); await page.fill('input[name="password"]', invalidCredentials.invalidPassword); await page.click('button[id="login-button"]'); await expect(page.locator('#user_auth_alert_error')).toHaveText('Invalid credentials'); }); test('[AUTH][User][Customer number] should fail to login using invalid customer number', async ({ page }) => { await goToUserLogin(page); await page.fill('input[name="customer_number"]', invalidCredentials.invalidCustomerNumber); await page.fill('input[name="password"]', userCredentials.password); await page.click('button[id="login-button"]'); await expect(page.locator('#user_auth_alert_error')).toHaveText('Invalid credentials'); }) // Password reset request tests test('[AUTH][User][Customer number] should request password reset successfully', async ({ page }) => { await goToUserLogin(page); await page.click('a[id="forgot-password-button"]'); await expect(page).toHaveURL('/auth/password-reset'); await page.fill('input[name="customer_number"]', userCredentials.customerNumber); await page.click('button[id="password-reset-button"]'); await expect(page.locator('#password_reset_alert_success')).toHaveText('If the customer exists, a password reset email has been sent.'); }) test('[AUTH][User][Customer number] should not show failure to request password reset using invalid customer number', async ({ page }) => { await goToUserLogin(page); await page.click('a[id="forgot-password-button"]'); await expect(page).toHaveURL('/auth/password-reset'); await page.fill('input[name="customer_number"]', invalidCredentials.invalidCustomerNumber); await page.click('button[id="password-reset-button"]'); await expect(page.locator('#password_reset_alert_success')).toHaveText('If the customer exists, a password reset email has been sent.'); }) // Password reset tests test('[AUTH][User][Customer number] should fail to reset password using invalid token', async ({ page }) => { await page.goto(`/auth/password-reset/${invalidCredentials.invalidToken}`); await expect(page.locator('#password_reset_alert_error')).toHaveText('Invalid or expired token'); }) // Registration tests test('[AUTH][User][Customer number] should fail to register already existing cvr', async ({ page }) => { await page.goto('/customer-creation'); await page.fill('input[id="customer_cvr"]', customerRegistrationData.existingCvr); await page.fill('input[id="email"]', customerRegistrationData.email); await page.fill('input[id="customer_phone"]', customerRegistrationData.newPhone); await page.click('button[id="customer-register-button"]'); await expect(page.locator('#customer_creation_alert_error')).toHaveText('CVR already registered'); }) test('[AUTH][User][Customer number] should fail to register already existing company phone number', async ({ page }) => { await page.goto('/customer-creation'); await page.fill('input[id="customer_cvr"]', customerRegistrationData.newCvr); await page.fill('input[id="email"]', customerRegistrationData.email); await page.fill('input[id="customer_phone"]', customerRegistrationData.existingPhone); await page.click('button[id="customer-register-button"]'); await expect(page.locator('#customer_creation_alert_error')).toHaveText('Company phone number already registered'); }) /** Subuser Authentication Tests */ // Phone number login tests test('[AUTH][Subuser][Phone number] should login successfully', async ({ page }) => { await loginAsSubuserByPhone(page); }) test('[AUTH][Subuser][Phone number] should fail to login using invalid phone number', async ({ page }) => { await goToSubuserLogin(page); await page.fill('input[name="phone_country_code"]', subuserPhoneCredentials.phoneCountryCode); await page.fill('input[name="phone"]', invalidCredentials.invalidPhoneNumber); await page.fill('input[name="password"]', subuserPhoneCredentials.password); await page.click('button[id="subuser-login-button"]'); await expect(page.locator('#subuser_auth_alert_error')).toHaveText('Subuser not found'); }) test('[AUTH][Subuser][Phone number] should fail to login using invalid password', async ({ page }) => { await goToSubuserLogin(page); await page.fill('input[name="phone_country_code"]', subuserPhoneCredentials.phoneCountryCode); await page.fill('input[name="phone"]', subuserPhoneCredentials.phone); await page.fill('input[name="password"]', invalidCredentials.invalidPassword); await page.click('button[id="subuser-login-button"]'); await expect(page.locator('#subuser_auth_alert_error')).toHaveText('Invalid password'); }) // Username login tests test('[AUTH][Subuser][Username] should login successfully', async ({ page }) => { await loginAsSubuserByUsername(page); }) test('[AUTH][Subuser][Username] should fail to login using invalid username', async ({ page }) => { await goToSubuserLogin(page); await page.click('button[id="subuser_login_method_username_button"]'); await page.waitForSelector('input[name="username"]'); await page.waitForSelector('input[name="password"]'); await page.fill('input[name="username"]', invalidCredentials.invalidUsername); await page.fill('input[name="password"]', subuserUsernameCredentials.password); await page.click('button[id="subuser-login-button"]'); await expect(page.locator('#subuser_auth_alert_error')).toHaveText('Subuser not found'); }) test('[AUTH][Subuser][Username] should fail to login using invalid password', async ({ page }) => { await goToSubuserLogin(page); await page.click('button[id="subuser_login_method_username_button"]'); await page.waitForSelector('input[name="username"]'); await page.waitForSelector('input[name="password"]'); await page.fill('input[name="username"]', subuserUsernameCredentials.username); await page.fill('input[name="password"]', invalidCredentials.invalidPassword); await page.click('button[id="subuser-login-button"]'); await expect(page.locator('#subuser_auth_alert_error')).toHaveText('Invalid password'); }) // Registration tests test('[AUTH][Subuser][Username] should fail to register with already existing phone number', async ({ page }) => { await page.goto('/customer-creation'); await page.fill('input[id="driver_cvr"]', driverRegistrationData.existingCvr); await page.fill('input[id="driver_phone"]', driverRegistrationData.existingPhone); await page.click('button[id="driver-register-button"]'); await expect(page.locator('#driver_creation_alert_error')).toHaveText('Account already exists with this phone number'); }) test('[AUTH][Subuser][Username] should fail to register with invalid (7-char) CVR number', async ({ page }) => { await page.goto('/customer-creation'); await page.fill('input[id="driver_cvr"]', driverRegistrationData.invalidCvr7Char); await page.fill('input[id="driver_phone"]', driverRegistrationData.existingPhone); await page.click('button[id="driver-register-button"]'); await expect(page.locator('#driver_creation_alert_error')).toHaveText('Parameter cvr must be at least 8 characters long'); }) test('[AUTH][Subuser][Username] should fail to register with invalid (9-char) CVR number', async ({ page }) => { await page.goto('/customer-creation'); await page.fill('input[id="driver_cvr"]', driverRegistrationData.invalidCvr9Char); await page.fill('input[id="driver_phone"]', driverRegistrationData.existingPhone); await page.click('button[id="driver-register-button"]'); await expect(page.locator('#driver_creation_alert_error')).toHaveText('Parameter cvr must be at most 8 characters long'); }) /** Operator Authentication Tests */ // User ID login tests test('[AUTH][Operator][User ID] should login successfully', async ({ page }) => { await loginAsOperator(page); }) test('[AUTH][Operator][User ID] should fail to login using invalid user ID', async ({ page }) => { await goToOperatorLogin(page); await page.fill('input[name="user_id"]', invalidCredentials.invalidUserId); await page.fill('input[name="password"]', operatorCredentials.password); await page.click('button[id="operator_login_button"]'); await expect(page.locator('#user_auth_alert_error')).toHaveText('Invalid credentials'); }) test('[AUTH][Operator][User ID] should fail to login using invalid password', async ({ page }) => { await goToOperatorLogin(page); await page.fill('input[name="user_id"]', operatorCredentials.userId); await page.fill('input[name="password"]', invalidCredentials.invalidOperatorPassword); await page.click('button[id="operator_login_button"]'); await expect(page.locator('#user_auth_alert_error')).toHaveText('Invalid credentials'); })