Files
lucia-frontend/cypress/e2e/accountAdmin/accountDuplicationCheck.cy.js
2026-03-22 09:30:22 +08:00

73 lines
2.3 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.contains("Test Admin").should("exist");
});
it("When an account already exists, show error message on confirm.", () => {
const testAccountName = "000000";
// First creation: account doesn't exist yet — override via MSW
cy.window().then((win) => {
const { http, HttpResponse } = win.__msw__;
win.__mswWorker__.use(
http.get("/api/users/000000", () =>
HttpResponse.json(
{ detail: "Not found" },
{ status: 404 },
)),
);
});
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("Account added").should("be.visible");
// Second creation: now account exists — override to return 200 via MSW
cy.window().then((win) => {
const { http, HttpResponse } = win.__msw__;
win.__mswWorker__.use(
http.get("/api/users/000000", () =>
HttpResponse.json({
username: "000000",
name: "000000",
is_admin: false,
is_active: true,
roles: [],
})),
);
});
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");
});
});