You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
chajia/__tests__/lib/rpa/mothership-login-context.te...

36 lines
1.1 KiB

import { afterEach, describe, expect, it } from "vitest";
import {
getEffectiveMothershipLogin,
getMothershipLoginSource,
hasEffectiveMothershipLogin,
runWithMothershipLoginContext,
} from "@/lib/rpa/mothership-login-context";
describe("mothership login context", () => {
afterEach(() => {
delete process.env.MOTHERSHIP_EMAIL;
delete process.env.MOTHERSHIP_PASSWORD;
});
it("客户凭据优先于环境变量", async () => {
process.env.MOTHERSHIP_EMAIL = "env@example.com";
process.env.MOTHERSHIP_PASSWORD = "env-pass";
await runWithMothershipLoginContext(
{ email: "cust@example.com", password: "cust-pass" },
"customer",
async () => {
expect(hasEffectiveMothershipLogin()).toBe(true);
expect(getMothershipLoginSource()).toBe("customer");
expect(getEffectiveMothershipLogin()?.email).toBe("cust@example.com");
},
);
});
it("无 ALS 时回退 env", () => {
process.env.MOTHERSHIP_EMAIL = "env@example.com";
process.env.MOTHERSHIP_PASSWORD = "env-pass";
expect(hasEffectiveMothershipLogin()).toBe(true);
expect(getMothershipLoginSource()).toBe("env");
});
});