|
| 1 | +import { describe, it, beforeEach, mock } from "node:test"; |
| 2 | +import assert from "node:assert/strict"; |
| 3 | +import { z } from "zod"; |
| 4 | + |
| 5 | +let calls: unknown[] = []; |
| 6 | +let nextListImpl: (opts: unknown) => Promise<unknown> = async () => ({ |
| 7 | + operations: [], |
| 8 | + cursor: null, |
| 9 | +}); |
| 10 | + |
| 11 | +mock.module("../allowance-auth.js", { |
| 12 | + namedExports: { |
| 13 | + requireAllowanceAuth: () => ({ headers: { "SIGN-IN-WITH-X": "dGVzdA==" } }), |
| 14 | + }, |
| 15 | +}); |
| 16 | + |
| 17 | +mock.module("../sdk.js", { |
| 18 | + namedExports: { |
| 19 | + getSdk: () => ({ |
| 20 | + deploy: { |
| 21 | + list: async (opts: unknown) => { |
| 22 | + calls.push(opts); |
| 23 | + return nextListImpl(opts); |
| 24 | + }, |
| 25 | + }, |
| 26 | + }), |
| 27 | + _resetSdk: () => {}, |
| 28 | + }, |
| 29 | +}); |
| 30 | + |
| 31 | +mock.module("../errors.js", { |
| 32 | + namedExports: { |
| 33 | + mapSdkError: () => ({ |
| 34 | + content: [{ type: "text", text: "mapped SDK error" }], |
| 35 | + isError: true, |
| 36 | + }), |
| 37 | + }, |
| 38 | +}); |
| 39 | + |
| 40 | +const { deployListSchema, handleDeployList } = await import("./deploy-list.js"); |
| 41 | + |
| 42 | +beforeEach(() => { |
| 43 | + calls = []; |
| 44 | + nextListImpl = async () => ({ |
| 45 | + operations: [], |
| 46 | + cursor: null, |
| 47 | + }); |
| 48 | +}); |
| 49 | + |
| 50 | +describe("deploy_list", () => { |
| 51 | + it("accepts a pagination cursor in the schema", () => { |
| 52 | + const parsed = z.object(deployListSchema).parse({ |
| 53 | + project_id: "prj_test", |
| 54 | + limit: 5, |
| 55 | + cursor: "op_cursor", |
| 56 | + }); |
| 57 | + |
| 58 | + assert.equal(parsed.cursor, "op_cursor"); |
| 59 | + }); |
| 60 | + |
| 61 | + it("forwards cursor to SDK deploy.list and still renders the next cursor", async () => { |
| 62 | + nextListImpl = async () => ({ |
| 63 | + operations: [ |
| 64 | + { |
| 65 | + operation_id: "op_1", |
| 66 | + status: "ready", |
| 67 | + release_id: "rel_1", |
| 68 | + updated_at: "2026-05-15T00:00:00Z", |
| 69 | + }, |
| 70 | + ], |
| 71 | + cursor: "op_next", |
| 72 | + }); |
| 73 | + |
| 74 | + const result = await handleDeployList({ |
| 75 | + project_id: "prj_test", |
| 76 | + limit: 5, |
| 77 | + cursor: "op_cursor", |
| 78 | + }); |
| 79 | + |
| 80 | + assert.equal(result.isError, undefined); |
| 81 | + assert.deepEqual(calls, [ |
| 82 | + { project: "prj_test", limit: 5, cursor: "op_cursor" }, |
| 83 | + ]); |
| 84 | + assert.match(result.content[0]!.text, /Next cursor: `op_next`/); |
| 85 | + }); |
| 86 | +}); |
0 commit comments