81 lines
2.6 KiB
TypeScript
81 lines
2.6 KiB
TypeScript
const authenticatedUser = {
|
|
id: 7,
|
|
email: 'user@example.com',
|
|
}
|
|
|
|
describe('email confirmation', () => {
|
|
beforeEach(() => {
|
|
cy.intercept('GET', '**/api/me', {
|
|
statusCode: 401,
|
|
body: { error: 'unauthenticated' },
|
|
}).as('me')
|
|
cy.intercept('GET', '**/api/sets', {
|
|
statusCode: 200,
|
|
body: { sets: [] },
|
|
})
|
|
})
|
|
|
|
it('chooses a password, confirms the account, and opens the dashboard', () => {
|
|
cy.intercept('POST', '**/api/confirm-email', (request) => {
|
|
expect(request.headers.accept).to.equal('application/json')
|
|
expect(request.body).to.deep.equal({
|
|
token: 'confirmation-token',
|
|
password: 'password123',
|
|
})
|
|
request.reply({
|
|
statusCode: 200,
|
|
body: { user: authenticatedUser },
|
|
})
|
|
}).as('confirmEmail')
|
|
|
|
cy.visit('/confirm-email?token=confirmation-token')
|
|
cy.get('#confirm-email-password').type('password123')
|
|
cy.get('#confirm-email-password-confirmation').type('password123')
|
|
cy.get('form').submit()
|
|
cy.wait('@confirmEmail')
|
|
|
|
cy.location('pathname').should('equal', '/dashboard')
|
|
cy.get('h1').should('have.text', 'Available sets')
|
|
})
|
|
|
|
it('validates password length and confirmation before submitting', () => {
|
|
cy.intercept('POST', '**/api/confirm-email').as('confirmEmail')
|
|
|
|
cy.visit('/confirm-email?token=confirmation-token')
|
|
cy.get('#confirm-email-password').type('short')
|
|
cy.get('#confirm-email-password-confirmation').type('different')
|
|
cy.get('form').submit()
|
|
|
|
cy.get('#confirm-email-password-error')
|
|
.should('have.text', 'Password must be at least 8 characters.')
|
|
.and('be.visible')
|
|
cy.get('#confirm-email-password-confirmation-error')
|
|
.should('have.text', 'Passwords do not match.')
|
|
.and('be.visible')
|
|
cy.get('@confirmEmail.all').should('have.length', 0)
|
|
})
|
|
|
|
it('shows confirmation errors from the backend', () => {
|
|
cy.intercept('POST', '**/api/confirm-email', {
|
|
statusCode: 409,
|
|
body: { error: 'token expired' },
|
|
}).as('confirmEmail')
|
|
|
|
cy.visit('/confirm-email?token=expired-token')
|
|
cy.get('#confirm-email-password').type('password123')
|
|
cy.get('#confirm-email-password-confirmation').type('password123')
|
|
cy.get('form').submit()
|
|
cy.wait('@confirmEmail')
|
|
|
|
cy.get('[role="alert"]')
|
|
.should('have.text', 'token expired')
|
|
.and('be.visible')
|
|
cy.location('pathname').should('equal', '/confirm-email')
|
|
})
|
|
|
|
it('redirects a confirmation route without a token to signup', () => {
|
|
cy.visit('/confirm-email')
|
|
|
|
cy.location('pathname').should('equal', '/signup')
|
|
})
|
|
})
|