test(browser): dedupe generated-token persistence assertions

This commit is contained in:
Peter Steinberger
2026-02-21 23:28:23 +00:00
parent 4f7032fbd9
commit 6bc753624f

View File

@@ -34,6 +34,18 @@ describe("ensureBrowserControlAuth", () => {
expect(mocks.writeConfigFile).not.toHaveBeenCalled();
};
const expectGeneratedTokenPersisted = (result: {
generatedToken?: string;
auth: { token?: string };
}) => {
expect(result.generatedToken).toMatch(/^[0-9a-f]{48}$/);
expect(result.auth.token).toBe(result.generatedToken);
expect(mocks.writeConfigFile).toHaveBeenCalledTimes(1);
const persisted = mocks.writeConfigFile.mock.calls[0]?.[0];
expect(persisted?.gateway?.auth?.mode).toBe("token");
expect(persisted?.gateway?.auth?.token).toBe(result.generatedToken);
};
beforeEach(() => {
vi.restoreAllMocks();
mocks.loadConfig.mockReset();
@@ -69,13 +81,7 @@ describe("ensureBrowserControlAuth", () => {
});
const result = await ensureBrowserControlAuth({ cfg, env: {} as NodeJS.ProcessEnv });
expect(result.generatedToken).toMatch(/^[0-9a-f]{48}$/);
expect(result.auth.token).toBe(result.generatedToken);
expect(mocks.writeConfigFile).toHaveBeenCalledTimes(1);
const persisted = mocks.writeConfigFile.mock.calls[0]?.[0];
expect(persisted?.gateway?.auth?.mode).toBe("token");
expect(persisted?.gateway?.auth?.token).toBe(result.generatedToken);
expectGeneratedTokenPersisted(result);
});
it("skips auto-generation in test env", async () => {