1
0
forked from baron/baron-sso

test: add unit and e2e tests for bulk user creation and schema validation

This commit is contained in:
2026-03-04 13:26:44 +09:00
parent 03a4c553f8
commit 02acdf835f
7 changed files with 499 additions and 71 deletions

View File

@@ -0,0 +1,40 @@
import { type BulkUserItem } from "../../../lib/adminApi";
export function parseUserCSV(text: string): BulkUserItem[] {
const lines = text.split(/\r?\n/);
if (lines.length < 2) {
return [];
}
const headers = lines[0].split(",").map((h) => h.trim().toLowerCase());
const data: BulkUserItem[] = [];
for (let i = 1; i < lines.length; i++) {
if (!lines[i].trim()) continue;
const values = lines[i].split(",").map((v) => v.trim());
const item: any = { metadata: {} };
headers.forEach((header, index) => {
const value = values[index];
if (value === undefined || value === "") return;
if (
["email", "name", "phone", "role", "companycode", "department"].includes(
header,
)
) {
const key = header === "companycode" ? "companyCode" : header;
item[key] = value;
} else {
item.metadata[header] = value;
}
});
if (item.email && item.name) {
data.push(item as BulkUserItem);
}
}
return data;
}