Larbi Gharib | b38e354 | 2022-12-07 06:09:10 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2022 Savoir-faire Linux Inc. |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify |
| 5 | * it under the terms of the GNU Affero General Public License as |
| 6 | * published by the Free Software Foundation; either version 3 of the |
| 7 | * License, or (at your option) any later version. |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU Affero General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU Affero General Public |
| 15 | * License along with this program. If not, see |
| 16 | * <https://www.gnu.org/licenses/>. |
| 17 | */ |
| 18 | |
| 19 | describe('authentication', () => { |
| 20 | beforeEach(() => {}); |
| 21 | |
Ziwei Wang | 207ae8e | 2023-04-03 13:02:31 -0400 | [diff] [blame] | 22 | it('log in and log out successfully with UI', () => { |
| 23 | cy.loginViaUI(); |
| 24 | |
| 25 | cy.logoutViaUI(); |
| 26 | }); |
| 27 | |
| 28 | it('login failed with invalid password', () => { |
| 29 | const wrongPassword = Date.now(); |
| 30 | |
Larbi Gharib | b38e354 | 2022-12-07 06:09:10 -0500 | [diff] [blame] | 31 | cy.visit(Cypress.env('CLIENT_URL')); |
| 32 | |
| 33 | cy.url().should('include', '/login'); |
| 34 | |
| 35 | cy.get('[data-cy = "username-input"]') |
| 36 | .type(Cypress.env('TEST_USERNAME')) |
| 37 | .find('input') |
| 38 | .should('have.value', Cypress.env('TEST_USERNAME')); |
| 39 | |
| 40 | cy.get('[data-cy = "password-input"]') |
Ziwei Wang | 207ae8e | 2023-04-03 13:02:31 -0400 | [diff] [blame] | 41 | .type(wrongPassword.toString()) |
Larbi Gharib | b38e354 | 2022-12-07 06:09:10 -0500 | [diff] [blame] | 42 | .find('input') |
Ziwei Wang | 207ae8e | 2023-04-03 13:02:31 -0400 | [diff] [blame] | 43 | .should('have.value', wrongPassword.toString()); |
Larbi Gharib | b38e354 | 2022-12-07 06:09:10 -0500 | [diff] [blame] | 44 | |
| 45 | cy.get('[data-cy="login-button"]').contains('Log in').click(); |
| 46 | |
idillon | 440e530 | 2023-08-03 20:25:24 -0400 | [diff] [blame] | 47 | cy.get('.MuiAlert-message').contains('Invalid credentials'); |
Ziwei Wang | 207ae8e | 2023-04-03 13:02:31 -0400 | [diff] [blame] | 48 | }); |
Larbi Gharib | b38e354 | 2022-12-07 06:09:10 -0500 | [diff] [blame] | 49 | |
Ziwei Wang | 207ae8e | 2023-04-03 13:02:31 -0400 | [diff] [blame] | 50 | it('log in without UI', () => { |
| 51 | cy.loginWithoutUI(); |
Larbi Gharib | b38e354 | 2022-12-07 06:09:10 -0500 | [diff] [blame] | 52 | |
Ziwei Wang | 207ae8e | 2023-04-03 13:02:31 -0400 | [diff] [blame] | 53 | cy.logoutViaUI(); |
Larbi Gharib | b38e354 | 2022-12-07 06:09:10 -0500 | [diff] [blame] | 54 | }); |
| 55 | }); |