(
fetchMock: ReturnType<typeof vi.fn>,
options: { repositoryStatus?: number; mintStatus?: number } = {}
)
| 47 | } |
| 48 | |
| 49 | function stubRegistryFetch( |
| 50 | fetchMock: ReturnType<typeof vi.fn>, |
| 51 | options: { repositoryStatus?: number; mintStatus?: number } = {} |
| 52 | ) { |
| 53 | const repositoryStatus = options.repositoryStatus ?? 200; |
| 54 | const mintStatus = options.mintStatus ?? 200; |
| 55 | fetchMock.mockImplementation((url: string | URL) => { |
| 56 | const href = String(url); |
| 57 | if (href.includes('/v1/projects/') && href.includes('/token')) { |
| 58 | const projectId = |
| 59 | href.match(/\/projects\/([^/?]+)\/token/)?.[1] ?? 'prj_test'; |
| 60 | const token = fakeOidcToken({ |
| 61 | project_id: projectId, |
| 62 | owner_id: 'team_test', |
| 63 | }); |
| 64 | return Promise.resolve({ |
| 65 | ok: mintStatus >= 200 && mintStatus < 300, |
| 66 | status: mintStatus, |
| 67 | json: async () => ({ token }), |
| 68 | text: async () => |
| 69 | mintStatus === 403 ? 'Forbidden' : JSON.stringify({ token }), |
| 70 | }); |
| 71 | } |
| 72 | if (href.includes('/v1/vcr/repository')) { |
| 73 | return Promise.resolve({ |
| 74 | ok: repositoryStatus >= 200 && repositoryStatus < 300, |
| 75 | status: repositoryStatus, |
| 76 | text: async () => '', |
| 77 | }); |
| 78 | } |
| 79 | return Promise.resolve({ |
| 80 | ok: true, |
| 81 | status: 200, |
| 82 | text: async () => '', |
| 83 | }); |
| 84 | }); |
| 85 | } |
| 86 | |
| 87 | /** Fake child process that exits with a failure code. */ |
| 88 | function fakeChildFailure(stderr = '') { |
no test coverage detected