mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 02:50:20 +00:00
test(browser): dedupe generated-token persistence assertions
This commit is contained in:
@@ -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 () => {
|
||||
|
||||
Reference in New Issue
Block a user