| 1 | import { describe, expect, it } from 'vitest'; |
| 2 | import { decodeNodeId, decodeNodeIdAs |
| 3 | import { CouldNotResolveError } |
| 4 | |
| 5 | describe('node ids', () |
| 6 | it('round-trips every type with GitHub prefixes', |
| 7 | expect(encodeNodeId('Issue |
| 8 | expect(encodeNodeId('IssueComment |
| 9 | expect(encodeNodeId('Label |
| 10 | expect(encodeNodeId('PullRequest |
| 11 | for (const type |
| 12 | 'User', |
| 13 | 'Organization', |
| 14 | 'Repository', |
| 15 | 'Issue', |
| 16 | 'PullRequest', |
| 17 | 'IssueComment', |
| 18 | 'Label', |
| 19 | 'PullRequestReview', |
| 20 | 'PullRequestCommit', |
| 21 | 'Commit', |
| 22 | ] as const) |
| 23 | expect(decodeNodeId(encodeNodeId |
| 24 | type, |
| 25 | id: 'some_id-1', |
| 26 | }); |
| 27 | } |
| 28 | }); |
| 29 | |
| 30 | it('rejects unknown prefixes, missing separators and empty ids', |
| 31 | expect(decodeNodeId('ZZ_abc |
| 32 | expect(decodeNodeId('nounderscore |
| 33 | expect(decodeNodeId('I_ |
| 34 | }); |
| 35 | |
| 36 | it('refuses an id of another type with GitHub wording', |
| 37 | const label = |
| 38 | expect(() => |
| 39 | expect(() => |
| 40 | `Could not resolve to a node with the global id of '${label}'` |
| 41 | ); |
| 42 | expect(decodeNodeIdAs(label |
| 43 | }); |
| 44 | |
| 45 | it('accepts any of several types, as for a Labelable that is an issue or a pull request', |
| 46 | const pull = |
| 47 | expect(decodeNodeIdAs(pull |
| 48 | expect(() => |
| 49 | }); |
| 50 | }); |