qbo_auth: страница ручных тестов /tests, разбор CloudEvents в вебхуке; список тестовых событий
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -25,6 +25,22 @@ describe("вебхук Intuit", () => {
|
||||
expect(parseWebhook("{}")).toEqual([]);
|
||||
});
|
||||
|
||||
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" }]);
|
||||
expect(parseWebhook(JSON.stringify([ev, { ...ev, type: "qbo.vendor.deleted.v1", intuitentityid: "8" }])).map((e) => `${e.name}:${e.operation}`)).toEqual(["Bill:Create", "Vendor:Delete"]);
|
||||
});
|
||||
|
||||
it("страница /tests открыта, действия /tests/* закрыты токеном, заметка принимается", async () => {
|
||||
const app = buildApi({} as QboAuth, "svc");
|
||||
expect((await app.inject({ url: "/tests" })).statusCode).toBe(200);
|
||||
expect((await app.inject({ url: "/tests/status" })).statusCode).toBe(401);
|
||||
expect((await app.inject({ method: "POST", url: "/tests/disconnect" })).statusCode).toBe(401);
|
||||
const h = { authorization: "Bearer svc", "content-type": "application/json" };
|
||||
expect((await app.inject({ method: "POST", url: "/tests/note", headers: h, payload: { text: "Bill 12.50" } })).statusCode).toBe(200);
|
||||
expect((await app.inject({ method: "POST", url: "/tests/note", headers: h, payload: { text: " " } })).statusCode).toBe(400);
|
||||
});
|
||||
|
||||
it("маршрут /webhook: без токенов 503, плохая подпись 401, верная 200 и вызов onEvents без Bearer-токена сервиса", async () => {
|
||||
const onEvents = vi.fn();
|
||||
const auth = {} as QboAuth;
|
||||
|
||||
Reference in New Issue
Block a user