59 lines
2.0 KiB
JavaScript
59 lines
2.0 KiB
JavaScript
// The Lucia project.
|
|
// Copyright 2024-2026 DSP, inc. All rights reserved.
|
|
// Authors:
|
|
// cindy.chang@dsp.im (Cindy Chang), 2024/07/03
|
|
// imacat.yang@dsp.im (imacat), 2026/03/05
|
|
|
|
import { loginWithFixtures } from '../../support/intercept';
|
|
|
|
const MSG_ACCOUNT_NOT_UNIQUE = 'Account has already been registered.';
|
|
|
|
describe('Account duplication check.', () => {
|
|
beforeEach(() => {
|
|
loginWithFixtures();
|
|
cy.visit('/account-admin');
|
|
cy.wait('@getUsers');
|
|
});
|
|
|
|
it('When an account already exists, show error message on confirm.', () => {
|
|
const testAccountName = '000000';
|
|
|
|
// First creation: account doesn't exist yet
|
|
cy.intercept('GET', '/api/users/000000', {
|
|
statusCode: 404,
|
|
body: { detail: 'Not found' },
|
|
}).as('checkNewUser');
|
|
|
|
cy.contains('button', 'Create New').should('be.visible').click();
|
|
cy.get('#input_account_field').type(testAccountName);
|
|
cy.get('#input_name_field').type(testAccountName);
|
|
cy.get('#input_first_pwd').type(testAccountName);
|
|
cy.get('.checkbox-and-text').first().find('div').first().click();
|
|
|
|
cy.contains('button', 'Confirm')
|
|
.should('be.visible')
|
|
.and('be.enabled')
|
|
.click();
|
|
cy.wait('@postUser');
|
|
cy.contains('Account added').should('be.visible');
|
|
|
|
// Second creation: now account exists — override to return 200
|
|
cy.intercept('GET', '/api/users/000000', {
|
|
statusCode: 200,
|
|
body: { username: '000000', name: '000000', is_admin: false, is_active: true, roles: [] },
|
|
}).as('checkExistingUser');
|
|
|
|
cy.contains('button', 'Create New').should('be.visible').click();
|
|
cy.get('#input_account_field').type(testAccountName);
|
|
cy.get('#input_name_field').type(testAccountName);
|
|
cy.get('#input_first_pwd').type(testAccountName);
|
|
cy.get('.checkbox-and-text').first().find('div').first().click();
|
|
|
|
cy.contains('button', 'Confirm')
|
|
.should('be.visible')
|
|
.and('be.enabled')
|
|
.click();
|
|
cy.contains(MSG_ACCOUNT_NOT_UNIQUE).should('be.visible');
|
|
});
|
|
});
|