| 346 | }; |
| 347 | |
| 348 | function buildAdapter( |
| 349 | overrides: { |
| 350 | installation?: LinearInstallation | null; |
| 351 | decodeThreadId?: (id: string) => { issueId: string }; |
| 352 | } = {} |
| 353 | ): AdapterHarness { |
| 354 | const installation = |
| 355 | overrides.installation === undefined ? defaultInstallation : overrides.installation; |
| 356 | const getInstallation = jest.fn(async () => installation); |
| 357 | const decodeThreadId = jest.fn( |
| 358 | overrides.decodeThreadId ?? ((id: string) => ({ issueId: id.replace(/^linear:/, '') })) |
| 359 | ); |
| 360 | const withInstallation = jest.fn(async <T>(_id: unknown, fn: () => Promise<T> | T) => fn()); |
| 361 | |
| 362 | return { |
| 363 | getInstallation, |
| 364 | decodeThreadId, |
| 365 | withInstallation, |
| 366 | adapter: { |
| 367 | name: 'linear', |
| 368 | getInstallation, |
| 369 | decodeThreadId, |
| 370 | withInstallation, |
| 371 | } as unknown as LinearAdapter, |
| 372 | }; |
| 373 | } |
| 374 | |
| 375 | beforeEach(() => { |
| 376 | jest.clearAllMocks(); |