Skip to content

Commit

Permalink
adding default registry client tests
Browse files Browse the repository at this point in the history
  • Loading branch information
KaelynJefferson committed Jul 12, 2024
1 parent 50bae16 commit 9eb01a9
Showing 1 changed file with 38 additions and 17 deletions.
55 changes: 38 additions & 17 deletions test/registry/DefaultRegistryClient.test.ts
Original file line number Diff line number Diff line change
@@ -1,35 +1,56 @@
import { DefaultRegistryClient } from '../../src/registry/DefaultRegistryClient';
import { loggerSpy } from '../testhelpers';
import { DefaultRegistryClient } from '../../src/registry/DefaultRegistryClient';
import { NPMRegistryClient } from '../../src/registry/NPMRegistryClient';
import { FHIRRegistryClient } from '../../src/registry/FHIRRegistryClient';

describe('DefaultRegistryClient', () => {
describe('#constructor', () => {
beforeEach(() => {
loggerSpy.reset();
delete process.env.FPL_REGISTRY;
});
afterEach(() => {});

it('should make a custom registry client when specified', () => {
process.env.FPL_REGISTRY = 'https://custom-registry.example.org/';
new DefaultRegistryClient({ log: loggerSpy.log });
it('should make a client with custom registry when it has been specified', () => {
process.env.FPL_REGISTRY = 'https://custom-registry.example.org';
const defaultClient = new DefaultRegistryClient({ log: loggerSpy.log });
expect(defaultClient.clients).toHaveLength(1);
expect(defaultClient.clients[0]).toHaveProperty(
'endpoint',
'https://custom-registry.example.org'
);
expect(defaultClient.clients[0]).toBeInstanceOf(NPMRegistryClient);
expect(loggerSpy.getLastMessage('info')).toBe(
'Using custom registry specified by FPL_REGISTRY environment variable: https://custom-registry.example.org/'
'Using custom registry specified by FPL_REGISTRY environment variable: https://custom-registry.example.org'
);
});

it('should use the first default set for a custom registry client when specified', () => {
process.env.FPL_REGISTRY = 'https://custom-registry.example.org/';
new DefaultRegistryClient({ log: loggerSpy.log });
// expect(loggerSpy.getLastMessage('info')).toBe('Using custom registry specified by FPL_REGISTRY environment variable: https://custom-registry.example.org/');

process.env.FPL_REGISTRY = 'https://custom-registry-second.example.org/';
new DefaultRegistryClient({ log: loggerSpy.log });
// expect(loggerSpy.getLastMessage('info')).toBe('Using custom registry specified by FPL_REGISTRY environment variable: https://custom-registry.example.org/');
it('should make a client with fhir registries if no custom registry specified', () => {
const defaultClient = new DefaultRegistryClient({ log: loggerSpy.log });
expect(defaultClient.clients).toHaveLength(2);
expect(defaultClient.clients[0]).toHaveProperty('endpoint', 'https://packages.fhir.org');
expect(defaultClient.clients[0]).toBeInstanceOf(FHIRRegistryClient);
expect(defaultClient.clients[1]).toHaveProperty(
'endpoint',
'https://packages2.fhir.org/packages'
);
expect(defaultClient.clients[1]).toBeInstanceOf(FHIRRegistryClient);
});

it('should make a FHIR registry client when custom registry not specified', () => {
new DefaultRegistryClient({ log: loggerSpy.log });
expect(loggerSpy.getLastMessage('info')).toBeUndefined();
it('should make a client by using the first custom client specified if multiple defined', () => {
process.env.FPL_REGISTRY = 'https://custom-registry.example.org';
const defaultClient = new DefaultRegistryClient({ log: loggerSpy.log });
expect(defaultClient.clients).toHaveLength(1);
expect(defaultClient.clients[0]).toHaveProperty(
'endpoint',
'https://custom-registry.example.org'
);
expect(defaultClient.clients[0]).toBeInstanceOf(NPMRegistryClient);
// expect(loggerSpy.getLastMessage('info')).toBe(
// 'Using custom registry specified by FPL_REGISTRY environment variable: https://custom-registry.example.org'
// );
process.env.FPL_REGISTRY = 'https://custom-second-registry.example.org';

// when hasLoggedCustomRegistry = true ?
});
});
});

0 comments on commit 9eb01a9

Please sign in to comment.