qbo_auth: после invalid_grant статус сохраняется (не откатывается), sync отвечает 409 reauth_needed; найдено ручным тестом M1
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -2,7 +2,8 @@ import { createHmac } from "node:crypto";
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import { buildApi, testsSlug } from "./http-api.js";
|
||||
import { parseWebhook, SyncTrigger, verifyWebhook } from "./webhook.js";
|
||||
import type { QboAuth } from "./service.js";
|
||||
import { ReauthNeeded, type QboAuth } from "./service.js";
|
||||
import type { QboSync } from "./sync.js";
|
||||
|
||||
const BODY = JSON.stringify({ eventNotifications: [{ realmId: "R1", dataChangeEvent: { entities: [{ name: "Bill", id: "5", operation: "Create", lastUpdated: "2026-11-18T10:00:00Z" }, { name: "Purchase", id: "9", operation: "Update" }] } }] });
|
||||
const sign = (body: string, token: string) => createHmac("sha256", token).update(body).digest("base64");
|
||||
@@ -25,6 +26,16 @@ describe("вебхук Intuit", () => {
|
||||
expect(parseWebhook("{}")).toEqual([]);
|
||||
});
|
||||
|
||||
it("синхронизация без действующей авторизации: 409 reauth_needed (и на /sync, и на странице тестов), а не 502", async () => {
|
||||
const sync = { isRunning: false, run: async () => { throw new ReauthNeeded("нужна новая авторизация QuickBooks"); } } as unknown as QboSync;
|
||||
const app = buildApi({} as QboAuth, "svc", sync);
|
||||
const r1 = await app.inject({ method: "POST", url: "/sync", headers: { authorization: "Bearer svc" } });
|
||||
expect(r1.statusCode).toBe(409);
|
||||
expect(r1.json().error).toBe("reauth_needed");
|
||||
const r2 = await app.inject({ method: "POST", url: `/tests/${testsSlug("svc")}/sync` });
|
||||
expect(r2.statusCode).toBe(409);
|
||||
});
|
||||
|
||||
it("разбор CloudEvents: один объект и массив", () => {
|
||||
const ev = { specversion: "1.0", type: "qbo.bill.created.v1", intuitentityid: "7", intuitaccountid: "R1" };
|
||||
expect(parseWebhook(JSON.stringify(ev))).toEqual([{ realmId: "R1", name: "Bill", id: "7", operation: "Create" }]);
|
||||
|
||||
Reference in New Issue
Block a user