Skip to content

Commit

Permalink
feat!: use standalone class for resolving service endpoints
Browse files Browse the repository at this point in the history
BREAKING CHANGE: Session.client doesn't accept custom endpoint anymore
  • Loading branch information
DavyJohnes committed Mar 13, 2023
1 parent ff2f8f0 commit d9b00eb
Show file tree
Hide file tree
Showing 6 changed files with 486 additions and 378 deletions.
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ export * from './session';
export * from './utils/operation';
export * from './utils/decode-message';
export { WrappedServiceClientType } from './types';
export * from './service-endpoints';
10 changes: 6 additions & 4 deletions src/service-endpoints.test.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
import { getServiceClientEndpoint } from './service-endpoints';
import { ServiceEndpointResolver } from './service-endpoints';
import { serviceClients } from '.';
import { GeneratedServiceClientCtor } from './types';

// eslint-disable-next-line @typescript-eslint/ban-types
type MockServiceClientCtor = GeneratedServiceClientCtor<{}>;

const serviceEndpointResolver = new ServiceEndpointResolver();

describe('service endpoints', () => {
it('each service in generated service_clients module should have endpoint declared in service-endpoints', () => {
for (const [, ServiceClient] of Object.entries(serviceClients)) {
// eslint-disable-next-line @typescript-eslint/no-loop-func
expect(() => {
const endpoint = getServiceClientEndpoint(ServiceClient as MockServiceClientCtor);
const endpoint = serviceEndpointResolver.resolve(ServiceClient as MockServiceClientCtor);

expect(endpoint).toBeTruthy();
}).not.toThrow();
Expand All @@ -21,13 +23,13 @@ describe('service endpoints', () => {
const serviceName = 'myCustomService';

expect(() => {
getServiceClientEndpoint({ serviceName } as unknown as MockServiceClientCtor);
serviceEndpointResolver.resolve({ serviceName } as unknown as MockServiceClientCtor);
}).toThrow(`Endpoint for service ${serviceName} is no defined`);
});

it('should throw exception if client class has no serviceName option', () => {
expect(() => {
getServiceClientEndpoint({} as unknown as MockServiceClientCtor);
serviceEndpointResolver.resolve({} as unknown as MockServiceClientCtor);
}).toThrow('Unable to retrieve serviceName of provided service client class');
});
});
Loading

0 comments on commit d9b00eb

Please sign in to comment.