Skip to content

Commit

Permalink
Added tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Felipe Soares committed Dec 30, 2024
1 parent 174c82d commit 5ab6f8d
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 2 deletions.
20 changes: 20 additions & 0 deletions easyfinance.client/cypress/e2e/user/detail-user.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
})
})
})
})
4 changes: 4 additions & 0 deletions easyfinance.client/cypress/fixtures/users.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,9 @@
"testUser": {
"username": "[email protected]",
"password": "Passw0rd!"
},
"userToDelete": {
"username": "[email protected]",
"password": "Passw0rd!"
}
}
16 changes: 16 additions & 0 deletions easyfinance.client/cypress/support/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
}
}
)
})
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,7 @@ export class DetailUserComponent implements OnInit {
this.userService.deleteUser().subscribe({
next: (response: DeleteUser) => {
if (response?.confirmationToken) {
var message = '<p>Are you sure you want to delete your account? This action cannot be undone.</p>' + response.confirmationMessage;
this.ConfirmDialog.openModal('Confirm Deletion', message, 'Delete');
this.ConfirmDialog.openModal('Confirm Deletion', response.confirmationMessage, 'Delete');
this.deleteToken = response.confirmationToken;
}
},
Expand Down

0 comments on commit 5ab6f8d

Please sign in to comment.