Skip to content

Commit

Permalink
Add tests for BasePackageLoader and DefaultPackageLoader (#39 part 1)
Browse files Browse the repository at this point in the history
- BasePackageLoader tests
- DefaultPackageLoader tests
- Additional json files used taken from fpl and sushi
  • Loading branch information
KaelynJefferson authored and cmoesel committed Oct 9, 2024
1 parent 6fc82fa commit a7dca5b
Show file tree
Hide file tree
Showing 12 changed files with 9,263 additions and 2 deletions.
29 changes: 29 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
"eslint-config-prettier": "^9.1.0",
"jest": "^29.7.0",
"jest-extended": "^4.0.2",
"jest-mock-extended": "^4.0.0-beta1",
"opener": "^1.5.2",
"prettier": "^3.3.3",
"ts-jest": "^29.1.2",
Expand Down
4 changes: 2 additions & 2 deletions src/loader/BasePackageLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ export class BasePackageLoader implements PackageLoader {
}

// If it's a "dev" version, but it wasn't found in the cache, fall back to using the current version
// TODO: Does this actually check for the dev version prior to giving up?
if (version === 'dev') {
if (version === 'dev' && !this.packageCache.isPackageInCache(name, version)) {
this.log(
'info',
`Falling back to ${name}#current since ${packageLabel} is not locally cached. To avoid this, add ${packageLabel} to your local FHIR cache by building it locally with the HL7 FHIR IG Publisher.`
Expand Down Expand Up @@ -127,6 +126,7 @@ export class BasePackageLoader implements PackageLoader {
this.loadResourceFromCache(resourcePath, packageName, packageVersion);
} catch {
// swallow this error because some JSON files will not be resources
this.log('info', `JSON file at path ${resourcePath} was not FHIR resource`);
}
});
}
Expand Down
735 changes: 735 additions & 0 deletions test/loader/BasePackageLoader.test.ts

Large diffs are not rendered by default.

35 changes: 35 additions & 0 deletions test/loader/DefaultPackageLoader.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { loggerSpy } from '../testhelpers';
import { mock } from 'jest-mock-extended';
import { BasePackageLoader, BasePackageLoaderOptions } from '../../src/loader/BasePackageLoader';
import { LoadStatus } from '../../src/loader/PackageLoader';
import { PackageDB } from '../../src/db';
import { PackageCache } from '../../src/cache';
import { RegistryClient } from '../../src/registry';
import { CurrentBuildClient } from '../../src/current';

describe('DefaultPackageLoader', () => {

async function makeMyDefaultPackageLoader(options: BasePackageLoaderOptions) : Promise<BasePackageLoader> {
const packageDBMock = mock<PackageDB>();
const packageCacheMock = mock<PackageCache>();
const registryClientMock = mock<RegistryClient>();
const currentBuildClientMock = mock<CurrentBuildClient>();
const loader = new BasePackageLoader(
packageDBMock,
packageCacheMock,
registryClientMock,
currentBuildClientMock,
{ log: options.log }
);
return loader;
}

it('should create a package loader with mock default package loader' , async () => {
const loader = await makeMyDefaultPackageLoader({log: loggerSpy.log});
loader.getPackageLoadStatus = jest.fn().mockReturnValueOnce(LoadStatus.LOADED);

const result = await loader.loadPackage('some.ig', '1.2.3');
expect(result).toBe(LoadStatus.LOADED);
expect(loader.getPackageLoadStatus).toHaveBeenCalledWith('some.ig', '1.2.3');
});
});
1 change: 1 addition & 0 deletions test/loader/fixtures/StructureDefinition-Address.json

Large diffs are not rendered by default.

Loading

0 comments on commit a7dca5b

Please sign in to comment.