import { expect, tap } from '@git.zone/tstest/tapbundle'; import * as opendata from '../ts/index.js'; import * as paths from '../ts/paths.js'; import * as plugins from '../ts/plugins.js'; const testDbFolder = plugins.path.join(paths.packageDir, '.nogit', 'law-smartdb-test'); let lawService: opendata.LawService; tap.test('LawService - setup local smartdb', async () => { await plugins.smartfs.directory(testDbFolder).recursive().delete().catch(() => {}); lawService = new opendata.LawService({ dbFolderPath: testDbFolder, dbName: 'lawstest', }); await lawService.start(); expect(lawService).toBeInstanceOf(opendata.LawService); }); tap.test('LawService - sync and search Germany law', async () => { const germanLaw = await lawService.syncLaw({ jurisdiction: 'de', identifier: 'aeg', }); expect(germanLaw.identifier).toEqual('aeg'); expect(germanLaw.title).toInclude('Eisenbahngesetz'); expect(germanLaw.text).toInclude('Ausgleichspflicht'); const results = await lawService.searchLaws({ jurisdiction: 'de', query: 'Eisenbahngesetz', limit: 5, }); expect(results.length).toBeGreaterThan(0); expect(results[0].identifier).toEqual('aeg'); }); tap.test('LawService - sync and search EU law', async () => { const euLaw = await lawService.syncLaw({ jurisdiction: 'eu', identifier: '32024R1689', language: 'EN', }); expect(euLaw.identifier).toEqual('32024R1689'); expect(euLaw.title).toInclude('Artificial Intelligence Act'); expect(euLaw.text.toLowerCase()).toInclude('artificial intelligence'); const results = await lawService.searchLaws({ jurisdiction: 'eu', query: 'Artificial Intelligence Act', limit: 5, }); expect(results.length).toBeGreaterThan(0); expect(results[0].identifier).toEqual('32024R1689'); }); tap.test('LawService - sync and search USA law', async () => { const usLaw = await lawService.syncLaw({ jurisdiction: 'us', identifier: 'PLAW-119publ1', usCollection: 'PLAW', }); expect(usLaw.identifier).toEqual('PLAW-119publ1'); expect(usLaw.shortTitle).toInclude('Laken Riley Act'); expect(usLaw.text).toInclude('To require the Secretary of Homeland Security'); const results = await lawService.searchLaws({ jurisdiction: 'us', query: 'Laken Riley Act', limit: 5, }); expect(results.length).toBeGreaterThan(0); expect(results[0].identifier).toEqual('PLAW-119publ1'); }); tap.test('LawService - sync and search USA code citation', async () => { const usCodeSection = await lawService.syncLaw({ jurisdiction: 'us', identifier: '8 U.S.C. ยง 1226', }); expect(usCodeSection.identifier).toEqual('8 USC 1226'); expect(usCodeSection.citation).toEqual('8 USC 1226'); expect(usCodeSection.title).toInclude('Apprehension and detention of aliens'); expect(usCodeSection.text).toInclude('Detention of criminal aliens'); const results = await lawService.searchLaws({ jurisdiction: 'us', query: 'Apprehension and detention of aliens', limit: 10, }); expect(results.length).toBeGreaterThan(0); expect(results.map((lawArg) => lawArg.identifier).includes('8 USC 1226')).toEqual(true); }); tap.test('LawService - local lookup returns synced law', async () => { const euLaw = await lawService.getLaw({ jurisdiction: 'eu', identifier: '32024R1689', language: 'EN', }); expect(euLaw).toBeDefined(); expect(euLaw?.title).toInclude('Artificial Intelligence Act'); const usCodeLaw = await lawService.getLaw({ jurisdiction: 'us', identifier: '8 USC 1226(c)', }); expect(usCodeLaw).toBeDefined(); expect(usCodeLaw?.identifier).toEqual('8 USC 1226'); }); tap.test('LawService - teardown local smartdb', async () => { await lawService.stop(); await plugins.smartfs.directory(testDbFolder).recursive().delete().catch(() => {}); }); export default tap.start();