Unit tests for the bulk-data fetchers. Both files mock axios via mock.module('axios', ...) so no network is required.

Files

FileLinesSubject
tests/fetchers/scb.test.ts160src/fetchers/scb/index.ts — PxWebApi v2 fetcher
tests/fetchers/bolagsverket.test.ts113src/fetchers/bolagsverket/index.ts — bulk download + extract
src/fetchers/bolagsverket/mapper.test.ts43src/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 table NV/NV0109/NV0109A/NV0109A01
  • MOCK_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? endpoint
  • fetchTableMetadata(tableId) — returns metadata with both variables
  • fetchTableData(tableId, query) — returns JSON-stat2 with two values, dimension keys preserved
  • fetchCompanies() — returns a Company[] from statistical aggregates; every company has string orgNr, string name, string address, array sni
  • fetchCompanies() synthesises orgNr with prefix SCB- (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_URL when no URL passed

Warning

One test is effectively empty: the downloadFile test (lines 53–60) acknowledges that once mock.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:SNI2007 parses into the corresponding fields
  • XML missing optional Postadress and SNI2007 returns address: 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.

See also