From 5ab6f8deddbe4c530a5321249380ef19ad11fca6 Mon Sep 17 00:00:00 2001 From: Felipe Soares <> Date: Mon, 30 Dec 2024 16:02:03 +0100 Subject: [PATCH] Added tests --- .../cypress/e2e/user/detail-user.cy.ts | 20 +++++++++++++++++++ .../cypress/fixtures/users.json | 4 ++++ .../cypress/support/commands.ts | 16 +++++++++++++++ .../user/detail-user/detail-user.component.ts | 3 +-- 4 files changed, 41 insertions(+), 2 deletions(-) diff --git a/easyfinance.client/cypress/e2e/user/detail-user.cy.ts b/easyfinance.client/cypress/e2e/user/detail-user.cy.ts index ae9ecf41..d49d66d9 100644 --- a/easyfinance.client/cypress/e2e/user/detail-user.cy.ts +++ b/easyfinance.client/cypress/e2e/user/detail-user.cy.ts @@ -58,4 +58,24 @@ describe('EconoFlow - user detail Tests', () => { cy.get('.btn').contains('Cancel').click(); cy.get('.btn').contains('Modify Password').should('exist') }) + + it('should be possible delete user', () => { + cy.fixture('users').then((users) => { + const user = users.userToDelete; + + cy.intercept('DELETE', '**/account*').as('deleteAccount') + + cy.register(user.username, user.password) + cy.visit('/user') + cy.get('.btn').contains('Delete Account').click(); + cy.wait('@deleteAccount').then((interception) => { + expect(interception?.response?.statusCode).to.equal(202) + cy.get('.modal-dialog .btn').contains('Delete').click(); + + cy.wait('@deleteAccount').then((interception2) => { + expect(interception2?.response?.statusCode).to.equal(200) + }) + }) + }) + }) }) diff --git a/easyfinance.client/cypress/fixtures/users.json b/easyfinance.client/cypress/fixtures/users.json index 95c62368..a6797400 100644 --- a/easyfinance.client/cypress/fixtures/users.json +++ b/easyfinance.client/cypress/fixtures/users.json @@ -9,5 +9,9 @@ "testUser": { "username": "test@test.com", "password": "Passw0rd!" + }, + "userToDelete": { + "username": "test2@test.com", + "password": "Passw0rd!" } } diff --git a/easyfinance.client/cypress/support/commands.ts b/easyfinance.client/cypress/support/commands.ts index b205426d..0b2cd183 100644 --- a/easyfinance.client/cypress/support/commands.ts +++ b/easyfinance.client/cypress/support/commands.ts @@ -31,6 +31,22 @@ Cypress.Commands.add('register', (username, password) => { cy.visit('/') cy.url().should('include', 'first-signin') + + cy.intercept('GET', '/api/account/').as('getAccount') + + cy.get('input[formControlName=firstName]').type('test') + cy.get('input[formControlName=lastName]').type('test') + const preferredCurrencyInput = cy.get('mat-select[formcontrolname=preferredCurrency]'); + preferredCurrencyInput.click().get('mat-option').contains('EUR').click() + cy.get('button').contains('Send').click(); + cy.wait('@getAccount') + }, + { + validate: () => { + cy.login(username, password) + cy.visit('/') + cy.url().should('not.contain', 'login') } + } ) }) diff --git a/easyfinance.client/src/app/features/user/detail-user/detail-user.component.ts b/easyfinance.client/src/app/features/user/detail-user/detail-user.component.ts index cd47890a..5f811a1d 100644 --- a/easyfinance.client/src/app/features/user/detail-user/detail-user.component.ts +++ b/easyfinance.client/src/app/features/user/detail-user/detail-user.component.ts @@ -114,8 +114,7 @@ export class DetailUserComponent implements OnInit { this.userService.deleteUser().subscribe({ next: (response: DeleteUser) => { if (response?.confirmationToken) { - var message = '
Are you sure you want to delete your account? This action cannot be undone.
' + response.confirmationMessage; - this.ConfirmDialog.openModal('Confirm Deletion', message, 'Delete'); + this.ConfirmDialog.openModal('Confirm Deletion', response.confirmationMessage, 'Delete'); this.deleteToken = response.confirmationToken; } },