-
Notifications
You must be signed in to change notification settings - Fork 0
feat: user api integration + sign in / sign up flow fix #145
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
1ca4c97
integration of the user-service api
Alessandro100 023d4d4
centralizing the auth flow logic
Alessandro100 335df0f
disabled page protection on verify-email and complete-registration
Alessandro100 dd0596f
types of the new API
Alessandro100 a4945e5
user service api integration
Alessandro100 b7eebea
ability to edit user profile
Alessandro100 3c0f9c4
updated suite of e2e tests
Alessandro100 25e9986
scripts to generate types
Alessandro100 b99148d
lint fix
Alessandro100 2612312
Potential fix for pull request finding
Alessandro100 f4e7a69
Potential fix for pull request finding
Alessandro100 a8f56b2
account general localization
Alessandro100 b64058d
sign-in support for oauth providers
Alessandro100 5f4d3e5
disabled changepassword tests
Alessandro100 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,159 @@ | ||
| describe('Account General Page', () => { | ||
| const password = 'IloveOrangeCones123!'; | ||
| const email = 'cypressTestUser@mobilitydata.org'; | ||
| beforeEach(() => { | ||
| cy.visit('/'); | ||
| cy.get('[data-testid="home-title"]').should('exist'); | ||
| cy.createNewUserAndSignIn(email, password); | ||
| cy.get('[data-cy="accountHeader"]').should('exist').click(); | ||
| cy.location('pathname').should('eq', '/account'); | ||
| }); | ||
|
|
||
| describe('renders initial elements', () => { | ||
| it('should render the Personal Information section', () => { | ||
| cy.contains('Personal Information').should('exist'); | ||
| cy.contains('Your account details and contact information').should( | ||
| 'exist', | ||
| ); | ||
| cy.contains('button', 'Edit').should('exist'); | ||
| cy.contains('label', 'Name').should('exist'); | ||
| cy.contains('label', 'Email').should('exist'); | ||
| cy.contains('label', 'Organization').should('exist'); | ||
| }); | ||
|
|
||
| it('should render the Account Support section', () => { | ||
| cy.contains('Account Support').should('exist'); | ||
| cy.contains('api@mobilitydata.org').should('exist'); | ||
| cy.get('[data-cy="changePasswordButtonAccount"]').should('exist'); | ||
| }); | ||
| }); | ||
|
|
||
| describe('editing user information', () => { | ||
| it('should enter edit mode and show Cancel and Save buttons', () => { | ||
| cy.contains('button', 'Edit').click(); | ||
| cy.contains('button', 'Cancel').should('exist'); | ||
| cy.contains('button', 'Save').should('exist'); | ||
| cy.contains('button', 'Edit').should('not.exist'); | ||
| }); | ||
|
|
||
| it('should cancel editing and return to view mode', () => { | ||
| cy.contains('button', 'Edit').click(); | ||
| cy.contains('button', 'Cancel').click(); | ||
| cy.contains('button', 'Edit').should('exist'); | ||
| cy.contains('button', 'Cancel').should('not.exist'); | ||
| cy.contains('button', 'Save').should('not.exist'); | ||
| }); | ||
|
|
||
| it('should save updated full name and organization', () => { | ||
| cy.intercept('PUT', '**/v1/user', { | ||
| statusCode: 200, | ||
| body: {}, | ||
| }).as('updateUser'); | ||
|
|
||
| cy.contains('button', 'Edit').click(); | ||
|
|
||
| cy.contains('label', 'Name') | ||
| .invoke('attr', 'for') | ||
| .then((id) => { | ||
| cy.get(`#${id}`).clear().type('Updated Name'); | ||
| }); | ||
|
|
||
| cy.contains('label', 'Organization') | ||
| .invoke('attr', 'for') | ||
| .then((id) => { | ||
| cy.get(`#${id}`).clear().type('Updated Organization'); | ||
| }); | ||
|
|
||
| cy.contains('button', 'Save').click(); | ||
| cy.wait('@updateUser'); | ||
|
|
||
| cy.contains('button', 'Edit').should('exist'); | ||
| cy.contains('button', 'Save').should('not.exist'); | ||
|
|
||
| cy.contains('label', 'Name') | ||
| .invoke('attr', 'for') | ||
| .then((id) => { | ||
| cy.get(`#${id}`).should('have.value', 'Updated Name'); | ||
| }); | ||
|
|
||
| cy.contains('label', 'Organization') | ||
| .invoke('attr', 'for') | ||
| .then((id) => { | ||
| cy.get(`#${id}`).should('have.value', 'Updated Organization'); | ||
| }); | ||
| }); | ||
| }); | ||
|
|
||
| describe('save error flow', () => { | ||
| it('should show an error alert and keep the form open when the API call fails', () => { | ||
| cy.intercept('PUT', '**/v1/user', { | ||
| statusCode: 500, | ||
| body: { message: 'Internal Server Error' }, | ||
| }).as('updateUserFail'); | ||
|
|
||
| cy.contains('button', 'Edit').click(); | ||
|
|
||
| cy.contains('label', 'Name') | ||
| .invoke('attr', 'for') | ||
| .then((id) => { | ||
| cy.get(`#${id}`).clear().type('Will Not Save'); | ||
| }); | ||
|
|
||
| cy.contains('button', 'Save').click(); | ||
| cy.wait('@updateUserFail'); | ||
|
|
||
| // Form should remain open after a failure | ||
| cy.contains('button', 'Save').should('exist'); | ||
| cy.contains('button', 'Cancel').should('exist'); | ||
| cy.contains('button', 'Edit').should('not.exist'); | ||
|
|
||
| // Error alert should be visible | ||
| cy.contains('Failed to save account changes. Please try again.').should( | ||
| 'exist', | ||
| ); | ||
| }); | ||
|
|
||
| it('should dismiss the error alert after 4 seconds', () => { | ||
| cy.clock(); | ||
|
|
||
| cy.intercept('PUT', '**/v1/user', { | ||
| statusCode: 500, | ||
| body: { message: 'Internal Server Error' }, | ||
| }).as('updateUserFail'); | ||
|
|
||
| cy.contains('button', 'Edit').click(); | ||
| cy.contains('button', 'Save').click(); | ||
| cy.wait('@updateUserFail'); | ||
|
|
||
| cy.contains('Failed to save account changes. Please try again.').should( | ||
| 'exist', | ||
| ); | ||
|
|
||
| cy.tick(4000); | ||
|
|
||
| cy.contains('Failed to save account changes. Please try again.').should( | ||
| 'not.be.visible', | ||
| ); | ||
| }); | ||
|
|
||
| it('should dismiss the error alert when clicking the close button', () => { | ||
| cy.intercept('PUT', '**/v1/user', { | ||
| statusCode: 500, | ||
| body: { message: 'Internal Server Error' }, | ||
| }).as('updateUserFail'); | ||
|
|
||
| cy.contains('button', 'Edit').click(); | ||
| cy.contains('button', 'Save').click(); | ||
| cy.wait('@updateUserFail'); | ||
|
|
||
| cy.contains('Failed to save account changes. Please try again.') | ||
| .closest('[role="alert"]') | ||
| .find('button[aria-label="Close"]') | ||
| .click(); | ||
|
|
||
| cy.contains('Failed to save account changes. Please try again.').should( | ||
| 'not.be.visible', | ||
| ); | ||
|
Alessandro100 marked this conversation as resolved.
|
||
| }); | ||
| }); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,15 +1,61 @@ | ||
| describe('Sign In page', () => { | ||
| beforeEach(() => { | ||
| cy.visit('/sign-in'); | ||
| }); | ||
| const email = 'cypressSignInTest@mobilitydata.org'; | ||
| const password = 'IloveOrangeCones123!'; | ||
|
|
||
| describe('renders', () => { | ||
| beforeEach(() => { | ||
| cy.visit('/sign-in'); | ||
| }); | ||
|
|
||
| it('should render page header', () => { | ||
| cy.get('[data-testid=websiteTile]') | ||
| .should('exist') | ||
| .contains('MobilityDatabase'); | ||
| }); | ||
|
|
||
| it('should render page header', () => { | ||
| cy.get('[data-testid=websiteTile]') | ||
| .should('exist') | ||
| .contains('MobilityDatabase'); | ||
| it('should render signin form', () => { | ||
| cy.get('[data-testid=signin]').should('exist'); | ||
| }); | ||
| }); | ||
|
|
||
| it('should render signin', () => { | ||
| cy.get('[data-testid=signin]').should('exist'); | ||
| describe('redirect after sign-in', () => { | ||
| it('should redirect to the contribute page when signed in with add_feed=true', () => { | ||
| cy.visit('/sign-in?add_feed=true'); | ||
| cy.get('[data-testid=signin]').should('exist'); | ||
| cy.createNewUserAndSignIn(email, password); | ||
| cy.location('pathname', { timeout: 10000 }).should('eq', '/contribute'); | ||
| }); | ||
|
|
||
| it('should redirect to the redirect_to path after sign-in', () => { | ||
| const redirectPath = '/feeds'; | ||
| cy.visit(`/sign-in?redirect_to=${encodeURIComponent(redirectPath)}`); | ||
| cy.get('[data-testid=signin]').should('exist'); | ||
| cy.createNewUserAndSignIn(email, password); | ||
| cy.location('pathname', { timeout: 10000 }).should('eq', redirectPath); | ||
| }); | ||
|
|
||
| it('should redirect to complete-registration when the account is in authenticated state', () => { | ||
| cy.visit('/sign-in'); | ||
| cy.get('[data-testid=signin]').should('exist'); | ||
| cy.window() | ||
| .its('store') | ||
| .invoke('dispatch', { | ||
| type: 'userProfile/loginSuccess', | ||
| payload: { | ||
| fullName: 'Test User', | ||
| email, | ||
| isRegistered: false, | ||
| isEmailVerified: true, | ||
| organization: undefined, | ||
| isRegisteredToReceiveAPIAnnouncements: false, | ||
| isAnonymous: false, | ||
| refreshToken: '', | ||
| }, | ||
| }); | ||
| cy.location('pathname', { timeout: 10000 }).should( | ||
| 'eq', | ||
| '/complete-registration', | ||
| ); | ||
| }); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.