| 1 | import { describe, expect, it } from 'vitest'; |
| 2 | |
| 3 | import { IssueState } |
| 4 | import { toIssueNode, toOrganizationNode |
| 5 | |
| 6 | const origins = { |
| 7 | api: 'https://api.ghost.test', |
| 8 | web: 'https://ghost.test', |
| 9 | sshHost: 'ghost.test:1031', |
| 10 | }; |
| 11 | |
| 12 | describe('toUserNode', () |
| 13 | it('builds GitHub user fields from a Ghost user row', |
| 14 | const created = |
| 15 | const node = |
| 16 | { |
| 17 | id: 'u1', |
| 18 | numericId: 7, |
| 19 | username: 'ada', |
| 20 | name: 'Ada', |
| 21 | image: null, |
| 22 | createdAt: created, |
| 23 | } as never, |
| 24 | origins, |
| 25 | ); |
| 26 | expect(node).toMatchObject |
| 27 | kind: 'User', |
| 28 | ghostId: 'u1', |
| 29 | login: 'ada', |
| 30 | name: 'Ada', |
| 31 | avatarUrl: '', |
| 32 | resourcePath: '/ada', |
| 33 | url: 'https://ghost.test/ada', |
| 34 | databaseId: 7, |
| 35 | createdAt: created, |
| 36 | }); |
| 37 | expect(node.id |
| 38 | }); |
| 39 | }); |
| 40 | |
| 41 | describe('toOrganizationNode', () |
| 42 | it('uses the slug as the login', |
| 43 | const node = |
| 44 | { |
| 45 | id: 'o1', |
| 46 | slug: 'acme', |
| 47 | name: 'Acme', |
| 48 | logo: 'https://x/logo.png', |
| 49 | } as never, |
| 50 | origins, |
| 51 | ); |
| 52 | expect(node).toMatchObject |
| 53 | kind: 'Organization', |
| 54 | login: 'acme', |
| 55 | avatarUrl: 'https://x/logo.png', |
| 56 | url: 'https://ghost.test/acme', |
| 57 | }); |
| 58 | expect(node.id |
| 59 | }); |
| 60 | }); |
| 61 | |
| 62 | describe('toIssueNode', () |
| 63 | const repository = |
| 64 | ghostId: 'repo_1', |
| 65 | ownerLogin: 'ada', |
| 66 | slug: 'tools', |
| 67 | url: 'https://ghost.test/ada/tools', |
| 68 | resourcePath: '/ada/tools', |
| 69 | } as never; |
| 70 | const dto = |
| 71 | id: 'issue_1', |
| 72 | number: 7, |
| 73 | title: 'T', |
| 74 | body: null, |
| 75 | state: 'closed', |
| 76 | isPullRequest: false, |
| 77 | authorUsername: 'ada', |
| 78 | closedByUsername: 'ada', |
| 79 | labels: [], |
| 80 | assignees: ['bob'], |
| 81 | commentCount: 0, |
| 82 | closedAt: '2026-01-02T00:00:00.000Z', |
| 83 | createdAt: '2026-01-01T00:00:00.000Z', |
| 84 | updatedAt: '2026-01-02T00:00:00.000Z', |
| 85 | viewerCanEdit: true, |
| 86 | }; |
| 87 | |
| 88 | it('maps Ghost issue state, empty body and URLs onto GitHub fields', |
| 89 | const node = |
| 90 | expect(node).toMatchObject |
| 91 | number: 7, |
| 92 | body: '', |
| 93 | state: IssueState.CLOSED |
| 94 | closed: true, |
| 95 | stateReason: 'COMPLETED', |
| 96 | url: 'https://ghost.test/ada/tools/issues/7', |
| 97 | resourcePath: '/ada/tools/issues/7', |
| 98 | assigneeLogins: ['bob'], |
| 99 | viewerCanUpdate: true, |
| 100 | }); |
| 101 | expect(node.id |
| 102 | }); |
| 103 | |
| 104 | it('leaves stateReason null on an open issue', |
| 105 | expect( |
| 106 | toIssueNode( |
| 107 | { ...dto, |
| 108 | repository, |
| 109 | ).stateReason, |
| 110 | ).toBeNull(); |
| 111 | }); |
| 112 | }); |