mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-16 06:20:44 +00:00
test: set zalouser credential mtime explicitly
This commit is contained in:
@@ -1,4 +1,14 @@
|
||||
import { lstat, mkdir, mkdtemp, readFile, rm, stat, symlink, writeFile } from "node:fs/promises";
|
||||
import {
|
||||
lstat,
|
||||
mkdir,
|
||||
mkdtemp,
|
||||
readFile,
|
||||
rm,
|
||||
stat,
|
||||
symlink,
|
||||
utimes,
|
||||
writeFile,
|
||||
} from "node:fs/promises";
|
||||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
import { withEnvAsync } from "openclaw/plugin-sdk/test-env";
|
||||
@@ -7,7 +17,6 @@ import type { API, Credentials, LoginQRCallbackEvent } from "./zca-client.js";
|
||||
import { LoginQRCallbackEventType } from "./zca-constants.js";
|
||||
|
||||
const createZaloMock = vi.hoisted(() => vi.fn());
|
||||
const TEST_MTIME_TICK_MS = 20;
|
||||
const ISO_TIMESTAMP_RE = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z$/u;
|
||||
|
||||
vi.mock("./zca-client.js", () => ({
|
||||
@@ -51,10 +60,6 @@ async function readStoredCredentials(
|
||||
) as StoredCredentialFile;
|
||||
}
|
||||
|
||||
async function waitForMtimeTick(): Promise<void> {
|
||||
await new Promise((resolve) => setTimeout(resolve, TEST_MTIME_TICK_MS));
|
||||
}
|
||||
|
||||
function createMockApi(params: {
|
||||
imei: string;
|
||||
userAgent: string;
|
||||
@@ -308,10 +313,11 @@ describe("zalouser credential persistence", () => {
|
||||
await withEnvAsync({ OPENCLAW_STATE_DIR: stateDir }, async () => {
|
||||
await expect(listZaloFriends(profile)).resolves.toEqual([]);
|
||||
const firstRaw = await readFile(filePath, "utf8");
|
||||
const stableMtime = new Date("2026-04-01T00:00:10.000Z");
|
||||
await utimes(filePath, stableMtime, stableMtime);
|
||||
const firstMtimeMs = (await stat(filePath)).mtimeMs;
|
||||
|
||||
currentCookie = cookieB;
|
||||
await waitForMtimeTick();
|
||||
|
||||
await expect(listZaloFriends(profile)).resolves.toEqual([]);
|
||||
expect(await readFile(filePath, "utf8")).toBe(firstRaw);
|
||||
|
||||
Reference in New Issue
Block a user