refactor(test): extract shared doctor migration test setup

This commit is contained in:
Peter Steinberger
2026-02-16 16:32:15 +00:00
parent 261f5ee492
commit ffeeb835aa
3 changed files with 161 additions and 222 deletions

View File

@@ -13,6 +13,15 @@ describe("normalizeLegacyConfigValues", () => {
fs.writeFileSync(path.join(dir, "creds.json"), JSON.stringify({ me: {} }));
};
const expectNoWhatsAppConfigForLegacyAuth = (setup?: () => void) => {
setup?.();
const res = normalizeLegacyConfigValues({
messages: { ackReaction: "👀", ackReactionScope: "group-mentions" },
});
expect(res.config.channels?.whatsapp).toBeUndefined();
expect(res.changes).toEqual([]);
};
beforeEach(() => {
previousOauthDir = process.env.OPENCLAW_OAUTH_DIR;
tempOauthDir = fs.mkdtempSync(path.join(os.tmpdir(), "openclaw-oauth-"));
@@ -57,39 +66,24 @@ describe("normalizeLegacyConfigValues", () => {
});
it("does not add whatsapp config when only auth exists (issue #900)", () => {
const credsDir = path.join(tempOauthDir ?? "", "whatsapp", "default");
writeCreds(credsDir);
const res = normalizeLegacyConfigValues({
messages: { ackReaction: "👀", ackReactionScope: "group-mentions" },
expectNoWhatsAppConfigForLegacyAuth(() => {
const credsDir = path.join(tempOauthDir ?? "", "whatsapp", "default");
writeCreds(credsDir);
});
expect(res.config.channels?.whatsapp).toBeUndefined();
expect(res.changes).toEqual([]);
});
it("does not add whatsapp config when only legacy auth exists (issue #900)", () => {
const credsPath = path.join(tempOauthDir ?? "", "creds.json");
fs.writeFileSync(credsPath, JSON.stringify({ me: {} }));
const res = normalizeLegacyConfigValues({
messages: { ackReaction: "👀", ackReactionScope: "group-mentions" },
expectNoWhatsAppConfigForLegacyAuth(() => {
const credsPath = path.join(tempOauthDir ?? "", "creds.json");
fs.writeFileSync(credsPath, JSON.stringify({ me: {} }));
});
expect(res.config.channels?.whatsapp).toBeUndefined();
expect(res.changes).toEqual([]);
});
it("does not add whatsapp config when only non-default auth exists (issue #900)", () => {
const credsDir = path.join(tempOauthDir ?? "", "whatsapp", "work");
writeCreds(credsDir);
const res = normalizeLegacyConfigValues({
messages: { ackReaction: "👀", ackReactionScope: "group-mentions" },
expectNoWhatsAppConfigForLegacyAuth(() => {
const credsDir = path.join(tempOauthDir ?? "", "whatsapp", "work");
writeCreds(credsDir);
});
expect(res.config.channels?.whatsapp).toBeUndefined();
expect(res.changes).toEqual([]);
});
it("copies legacy ack reaction when authDir override exists", () => {