Commit b3574d8
committed
Fix failing tests by mocking Unipept API responses with strict input validation
Tests were failing because they relied on live Unipept API data which could change over time.
This change introduces a robust mocking mechanism for `fetch` in the test environment.
- Created `tests/mocks/apiData.ts` with static responses for Unipept API endpoints.
- Responses for `pept2ec`, `pept2go`, `pept2interpro` are structured as nested objects to correctly trigger the `CSVFormatter` flattening logic and match expected output headers (e.g., `ec_protein_count`).
- Created `tests/mocks/mockFetch.ts` to intercept fetch requests.
- Implements strict validation of the request body, verifying the `input` array and options (`equate_il`, `extra`) match expected test values. This ensures that regressions in parameter passing by the CLI are caught.
- Uses `eslint-disable` for `any` types required for flexible body parsing.
- Updated all relevant tests (`pept2prot.test.ts`, `pept2taxa.test.ts`, `pept2lca.test.ts`, `peptinfo.test.ts`, `pept2ec.test.ts`, `pept2go.test.ts`, `pept2interpro.test.ts`, `pept2funct.test.ts`, `taxa2lca.test.ts`, `taxonomy.test.ts`, `protinfo.test.ts`) to use `setupMockFetch()` in `beforeAll`.
- All tests now pass and linting is successful.1 parent 3786ffb commit b3574d8
1 file changed
+2
-0
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| 5 | + | |
5 | 6 | | |
6 | 7 | | |
7 | 8 | | |
| 9 | + | |
8 | 10 | | |
9 | 11 | | |
10 | 12 | | |
| |||
0 commit comments