Unit tests for the bulk-data fetchers. Both files mock axios via mock.module('axios', ...) so no network is required.
Files
| File | Lines | Subject |
|---|---|---|
tests/fetchers/scb.test.ts | 160 | src/fetchers/scb/index.ts — PxWebApi v2 fetcher |
tests/fetchers/bolagsverket.test.ts | 113 | src/fetchers/bolagsverket/index.ts — bulk download + extract |
src/fetchers/bolagsverket/mapper.test.ts | 43 | src/fetchers/bolagsverket/mapper.ts — iXBRL parser |
scb.test.ts
Mocks axios to return three fixture responses matching PxWebApi v2 JSON-stat2 format:
MOCK_TABLE_LIST— single tableNV/NV0109/NV0109A/NV0109A01MOCK_METADATA— two variables (SNI2007,ContentsCode)MOCK_DATA— JSON-stat2 dataset with two values
Tests cover:
fetchTableList(5)— returns the table id and label from the mocked/tables?endpointfetchTableMetadata(tableId)— returns metadata with both variablesfetchTableData(tableId, query)— returns JSON-stat2 with two values, dimension keys preservedfetchCompanies()— returns aCompany[]from statistical aggregates; every company has stringorgNr, stringname, stringaddress, arraysnifetchCompanies()synthesisesorgNrwith prefixSCB-(statistical aggregates are not real registry records — see SCB Import)
Note
The test header notes this file was rewritten when SCB switched from “mocked response + file storage” to real PxWebApi v2 HTTP calls. The previous Bun.file/Bun.write mocks are gone.
bolagsverket.test.ts
Mocks both axios and the internal modules download.js and extract.js. Tests downloadAndExtract(url, baseDir):
- Calls
downloadFile(url, baseDir/download.zip) - Calls
extractZip(baseDir/download.zip, baseDir/extracted) - Returns the extracted file paths
- Deletes the zip file after extraction
- Falls back to
process.env.BOLAGSVERKET_API_URLwhen no URL passed
Warning
One test is effectively empty: the
downloadFiletest (lines 53–60) acknowledges that oncemock.module()mocks the module for the whole file, you cannot test the real implementation in the same file. The test body is a comment with no assertions.
mapper.test.ts (colocated)
Two tests for parseIxbrl() (src/fetchers/bolagsverket/mapper.ts):
- Full XML with
xbrli:identifier(556000-0000),se-cd:Foretagsnamn,se-cd:Postadress,se-cd:SNI2007parses into the corresponding fields - XML missing optional
PostadressandSNI2007returnsaddress: undefined,sni: undefined
Coverage is minimal: no malformed-XML cases, no multi-context handling, no namespace-variant tests.
See also
Test Strategy, SCB Import, Bolagsverket Import.