-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1012 from MTES-MCT/feat-rework-account-creation-flow
Rework account creation flow
- Loading branch information
Showing
76 changed files
with
1,709 additions
and
1,304 deletions.
There are no files selected for viewing
This file contains 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 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 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,155 @@ | ||
import { faker } from '@faker-js/faker/locale/fr'; | ||
|
||
describe('Sign up', () => { | ||
it('should sign up', () => { | ||
cy.visit('/connexion'); | ||
cy.get('a').contains('Créer votre compte').click(); | ||
|
||
const user = faker.internet.email(); | ||
|
||
cy.get('label') | ||
.contains(/Adresse e-mail/i) | ||
.next() | ||
.type(`${user}{enter}`); | ||
|
||
cy.location('pathname').should('eq', '/inscription/activation'); | ||
|
||
// Fetch emails from the Nodemailer API | ||
cy.request({ | ||
method: 'GET', | ||
url: `${Cypress.env('MAILER_HOST')}/email`, | ||
auth: { | ||
username: Cypress.env('MAILER_USER'), | ||
password: Cypress.env('MAILER_PASSWORD') | ||
} | ||
}).then((response) => { | ||
const emails: ReadonlyArray<Email> = response.body; | ||
const email: Email = emails | ||
.filter(subject('Activation du compte')) | ||
.filter(to(user)) | ||
.filter(unread()) | ||
.reduce((acc, email) => (acc.date > email.date ? acc : email)); | ||
const link = email.html.substring( | ||
email.html.indexOf('/inscription/mot-de-passe') | ||
); | ||
cy.visit(link); | ||
}); | ||
|
||
cy.get('label') | ||
.contains(/Définissez votre mot de passe/i) | ||
.next() | ||
.type('123QWEasd'); | ||
cy.get('label') | ||
.contains(/Confirmez votre mot de passe/i) | ||
.next() | ||
.type('123QWEasd{enter}'); | ||
|
||
cy.get('button') | ||
.contains(/Créer mon compte/i) | ||
.click(); | ||
|
||
cy.location('pathname').should('eq', '/parc-de-logements'); | ||
}); | ||
|
||
it('should await access to LOVAC', () => { | ||
cy.visit('/connexion'); | ||
cy.get('a').contains('Créer votre compte').click(); | ||
|
||
const user = '[email protected]'; | ||
|
||
cy.get('label') | ||
.contains(/Adresse e-mail/i) | ||
.next() | ||
.type(`${user}{enter}`); | ||
|
||
cy.location('pathname').should('eq', '/inscription/activation'); | ||
|
||
// Fetch emails from the Nodemailer API | ||
cy.request({ | ||
method: 'GET', | ||
url: `${Cypress.env('MAILER_HOST')}/email`, | ||
auth: { | ||
username: Cypress.env('MAILER_USER'), | ||
password: Cypress.env('MAILER_PASSWORD') | ||
} | ||
}).then((response) => { | ||
const emails: ReadonlyArray<Email> = response.body; | ||
const email: Email = emails | ||
.filter(subject('Activation du compte')) | ||
.filter(to(user)) | ||
.filter(unread()) | ||
.reduce((acc, email) => (acc.date > email.date ? acc : email)); | ||
const link = email.html.substring( | ||
email.html.indexOf('/inscription/mot-de-passe') | ||
); | ||
cy.visit(link); | ||
}); | ||
|
||
cy.location('pathname').should('eq', '/inscription/en-attente'); | ||
}); | ||
|
||
it('should forbid access to unauthorized users', () => { | ||
cy.visit('/connexion'); | ||
cy.get('a').contains('Créer votre compte').click(); | ||
|
||
const user = '[email protected]'; | ||
|
||
cy.get('label') | ||
.contains(/Adresse e-mail/i) | ||
.next() | ||
.type(`${user}{enter}`); | ||
|
||
cy.location('pathname').should('eq', '/inscription/activation'); | ||
|
||
// Fetch emails from the Nodemailer API | ||
cy.request({ | ||
method: 'GET', | ||
url: `${Cypress.env('MAILER_HOST')}/email`, | ||
auth: { | ||
username: Cypress.env('MAILER_USER'), | ||
password: Cypress.env('MAILER_PASSWORD') | ||
} | ||
}).then((response) => { | ||
const emails: ReadonlyArray<Email> = response.body; | ||
const email: Email = emails | ||
.filter(subject('Activation du compte')) | ||
.filter(to(user)) | ||
.filter(unread()) | ||
.reduce((acc, email) => (acc.date > email.date ? acc : email)); | ||
const link = email.html.substring( | ||
email.html.indexOf('/inscription/mot-de-passe') | ||
); | ||
cy.visit(link); | ||
}); | ||
|
||
cy.location('pathname').should('eq', '/inscription/impossible'); | ||
}); | ||
}); | ||
|
||
interface Email { | ||
id: string; | ||
html: string; | ||
subject: string; | ||
from: ReadonlyArray<{ | ||
address: string; | ||
name: string; | ||
}>; | ||
to: ReadonlyArray<{ | ||
address: string; | ||
name: string; | ||
}>; | ||
date: string; | ||
read: boolean; | ||
} | ||
|
||
function subject(subject: string) { | ||
return (email: Email) => email.subject === subject; | ||
} | ||
|
||
function to(recipient: string) { | ||
return (email: Email) => email.to.some((to) => to.address === recipient); | ||
} | ||
|
||
function unread() { | ||
return (email: Email) => !email.read; | ||
} |
This file contains 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 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 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 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.