|
| 1 | +import { describe, expect, it } from "vitest"; |
| 2 | + |
| 3 | +import type { |
| 4 | + GitHubActionDispatchResult, |
| 5 | + GitHubActionDispatcher, |
| 6 | +} from "../../application/ports/github-action-dispatcher.port.js"; |
| 7 | +import { GitHubCompositeActionDispatcher } from "./github-composite-action.dispatcher.js"; |
| 8 | + |
| 9 | +describe("GitHubCompositeActionDispatcher", () => { |
| 10 | + it("routes check runs to REST and body actions to GraphQL", async () => { |
| 11 | + const graphql = new RecordingDispatcher({ |
| 12 | + githubDeliveryId: "graphql", |
| 13 | + kind: "success", |
| 14 | + }); |
| 15 | + const rest = new RecordingDispatcher({ githubDeliveryId: "rest", kind: "success" }); |
| 16 | + const dispatcher = new GitHubCompositeActionDispatcher(graphql, rest); |
| 17 | + |
| 18 | + await expect( |
| 19 | + dispatcher.dispatch(dispatchInput("github.issue_comment.create")), |
| 20 | + ).resolves.toMatchObject({ |
| 21 | + githubDeliveryId: "graphql", |
| 22 | + kind: "success", |
| 23 | + }); |
| 24 | + await expect( |
| 25 | + dispatcher.dispatch(dispatchInput("github.check_run.create_or_update")), |
| 26 | + ).resolves.toMatchObject({ |
| 27 | + githubDeliveryId: "rest", |
| 28 | + kind: "success", |
| 29 | + }); |
| 30 | + |
| 31 | + expect(graphql.actionTypes).toEqual(["github.issue_comment.create"]); |
| 32 | + expect(rest.actionTypes).toEqual(["github.check_run.create_or_update"]); |
| 33 | + }); |
| 34 | +}); |
| 35 | + |
| 36 | +class RecordingDispatcher implements GitHubActionDispatcher { |
| 37 | + public readonly actionTypes: string[] = []; |
| 38 | + |
| 39 | + public constructor(private readonly result: GitHubActionDispatchResult) {} |
| 40 | + |
| 41 | + public dispatch( |
| 42 | + input: Parameters<GitHubActionDispatcher["dispatch"]>[0], |
| 43 | + ): Promise<GitHubActionDispatchResult> { |
| 44 | + this.actionTypes.push(input.actionType); |
| 45 | + return Promise.resolve(this.result); |
| 46 | + } |
| 47 | +} |
| 48 | + |
| 49 | +function dispatchInput( |
| 50 | + actionType: Parameters<GitHubActionDispatcher["dispatch"]>[0]["actionType"], |
| 51 | +): Parameters<GitHubActionDispatcher["dispatch"]>[0] { |
| 52 | + return { |
| 53 | + actionRequestId: "action-1", |
| 54 | + actionType, |
| 55 | + payload: |
| 56 | + actionType === "github.check_run.create_or_update" |
| 57 | + ? { |
| 58 | + headSha: "a".repeat(40), |
| 59 | + name: "Agent Teams / review", |
| 60 | + status: "queued", |
| 61 | + } |
| 62 | + : { |
| 63 | + body: "body", |
| 64 | + issueNumber: 1, |
| 65 | + }, |
| 66 | + renderedBody: "rendered", |
| 67 | + target: { owner: "octo", repo: "repo" }, |
| 68 | + tokenLease: { |
| 69 | + expiresAtMs: 1000, |
| 70 | + githubInstallationId: "installation-1", |
| 71 | + token: "secret-token", |
| 72 | + }, |
| 73 | + }; |
| 74 | +} |
0 commit comments