forked from baron/baron-sso
test(adminfront): fix flaky tests caused by missing dynamic loginId field and greedy URL mocks
This commit is contained in:
@@ -68,8 +68,8 @@ test.describe("User Management", () => {
|
|||||||
id: "t-1",
|
id: "t-1",
|
||||||
slug: "test-tenant",
|
slug: "test-tenant",
|
||||||
name: "Test Tenant",
|
name: "Test Tenant",
|
||||||
config: {
|
config: { userSchema: [{key: "loginId", label: "Login ID", type: "text", isLoginId: true}],
|
||||||
userSchema: [],
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
@@ -80,7 +80,7 @@ test.describe("User Management", () => {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (url.includes("/admin/users/u-1") && method === "GET") {
|
if (url.match(/\/admin\/users\/u-1$/) && method === "GET") {
|
||||||
return route.fulfill({
|
return route.fulfill({
|
||||||
json: {
|
json: {
|
||||||
id: "u-1",
|
id: "u-1",
|
||||||
@@ -90,7 +90,7 @@ test.describe("User Management", () => {
|
|||||||
tenantSlug: "test-tenant",
|
tenantSlug: "test-tenant",
|
||||||
role: "user",
|
role: "user",
|
||||||
status: "active",
|
status: "active",
|
||||||
metadata: {},
|
metadata: { loginId: "johndoe" },
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -113,10 +113,10 @@ test.describe("User Management", () => {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (url.includes("/admin/users") && method === "POST") {
|
if (url.match(/\/admin\/users(\?.*)?$/) && method === "POST") {
|
||||||
// Parse request payload to simulate validation checks
|
// Parse request payload to simulate validation checks
|
||||||
const postData = route.request().postDataJSON();
|
const postData = route.request().postDataJSON();
|
||||||
if (postData && postData.loginId === "existing_user") {
|
if (postData && postData.metadata?.loginId === "existing_user") {
|
||||||
// Simulate a backend conflict error (409) for an existing loginId
|
// Simulate a backend conflict error (409) for an existing loginId
|
||||||
return route.fulfill({
|
return route.fulfill({
|
||||||
status: 409,
|
status: 409,
|
||||||
@@ -131,15 +131,15 @@ test.describe("User Management", () => {
|
|||||||
id: "new-user-id",
|
id: "new-user-id",
|
||||||
name: "New User",
|
name: "New User",
|
||||||
email: "newuser@test.com",
|
email: "newuser@test.com",
|
||||||
loginId: postData?.loginId || "newuser123",
|
loginId: postData?.metadata?.loginId || "newuser123",
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (url.includes("/admin/users/u-1") && method === "PUT") {
|
if (url.match(/\/admin\/users\/u-1$/) && method === "PUT") {
|
||||||
// Parse request payload
|
// Parse request payload
|
||||||
const postData = route.request().postDataJSON();
|
const postData = route.request().postDataJSON();
|
||||||
if (postData && postData.loginId === "existing_user") {
|
if (postData && postData.metadata?.loginId === "existing_user") {
|
||||||
// Simulate a backend conflict error (409) for an existing loginId
|
// Simulate a backend conflict error (409) for an existing loginId
|
||||||
return route.fulfill({
|
return route.fulfill({
|
||||||
status: 409,
|
status: 409,
|
||||||
@@ -155,12 +155,12 @@ test.describe("User Management", () => {
|
|||||||
id: "u-1",
|
id: "u-1",
|
||||||
name: "John Doe Updated",
|
name: "John Doe Updated",
|
||||||
email: "john@test.com",
|
email: "john@test.com",
|
||||||
loginId: postData?.loginId || "johndoe_updated",
|
loginId: postData?.metadata?.loginId || "johndoe_updated",
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (url.includes("/admin/users") && method === "GET") {
|
if (url.match(/\/admin\/users(\?.*)?$/) && method === "GET") {
|
||||||
return route.fulfill({
|
return route.fulfill({
|
||||||
json: {
|
json: {
|
||||||
items: [
|
items: [
|
||||||
@@ -188,7 +188,7 @@ test.describe("User Management", () => {
|
|||||||
await page.goto("/users/u-1");
|
await page.goto("/users/u-1");
|
||||||
|
|
||||||
// Wait for the form to load with the existing login ID
|
// Wait for the form to load with the existing login ID
|
||||||
const loginIdInput = page.locator('input[id="loginId"]');
|
const loginIdInput = page.locator('input[id="metadata.loginId"]');
|
||||||
await expect(loginIdInput).toBeVisible();
|
await expect(loginIdInput).toBeVisible();
|
||||||
await expect(loginIdInput).toHaveValue("johndoe");
|
await expect(loginIdInput).toHaveValue("johndoe");
|
||||||
|
|
||||||
@@ -212,7 +212,7 @@ test.describe("User Management", () => {
|
|||||||
}) => {
|
}) => {
|
||||||
await page.goto("/users/u-1");
|
await page.goto("/users/u-1");
|
||||||
|
|
||||||
const loginIdInput = page.locator('input[id="loginId"]');
|
const loginIdInput = page.locator('input[id="metadata.loginId"]');
|
||||||
await expect(loginIdInput).toBeVisible();
|
await expect(loginIdInput).toBeVisible();
|
||||||
|
|
||||||
// Enter a login ID that triggers our mock conflict error
|
// Enter a login ID that triggers our mock conflict error
|
||||||
@@ -242,7 +242,7 @@ test.describe("User Management", () => {
|
|||||||
await page.locator('input[name="email"]').fill("newuser@test.com");
|
await page.locator('input[name="email"]').fill("newuser@test.com");
|
||||||
|
|
||||||
// Fill Login ID
|
// Fill Login ID
|
||||||
const loginIdInput = page.locator('input[name="loginId"]');
|
const loginIdInput = page.locator('input[id="metadata.loginId"]');
|
||||||
await loginIdInput.fill("newuser123");
|
await loginIdInput.fill("newuser123");
|
||||||
|
|
||||||
// Submit the form
|
// Submit the form
|
||||||
@@ -265,7 +265,7 @@ test.describe("User Management", () => {
|
|||||||
await page.locator('input[name="email"]').fill("newuser@test.com");
|
await page.locator('input[name="email"]').fill("newuser@test.com");
|
||||||
|
|
||||||
// Fill Login ID that triggers the mock conflict error
|
// Fill Login ID that triggers the mock conflict error
|
||||||
const loginIdInput = page.locator('input[name="loginId"]');
|
const loginIdInput = page.locator('input[id="metadata.loginId"]');
|
||||||
await loginIdInput.fill("existing_user");
|
await loginIdInput.fill("existing_user");
|
||||||
|
|
||||||
// Submit the form
|
// Submit the form
|
||||||
|
|||||||
@@ -90,7 +90,7 @@ test.describe("User Schema Dynamic Form", () => {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (url.includes("/admin/users/u-1")) {
|
if (url.match(/\/admin\/users\/u-1$/)) {
|
||||||
console.log("Mocking /admin/users/u-1");
|
console.log("Mocking /admin/users/u-1");
|
||||||
return route.fulfill({
|
return route.fulfill({
|
||||||
json: {
|
json: {
|
||||||
|
|||||||
Reference in New Issue
Block a user