Skip to content

Commit

Permalink
chore: added unit tests for edge sdk.
Browse files Browse the repository at this point in the history
  • Loading branch information
yusinto committed Nov 8, 2023
1 parent 2acad70 commit 5da020e
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 4 deletions.
1 change: 1 addition & 0 deletions packages/shared/sdk-server-edge/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"crypto-js": "^4.1.1"
},
"devDependencies": {
"@launchdarkly/private-js-mocks": "0.0.1",
"@trivago/prettier-plugin-sort-imports": "^4.1.1",
"@types/crypto-js": "^4.1.1",
"@types/jest": "^29.5.0",
Expand Down
41 changes: 41 additions & 0 deletions packages/shared/sdk-server-edge/src/api/LDClient.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { internal } from '@launchdarkly/js-server-sdk-common';
import { basicPlatform } from '@launchdarkly/private-js-mocks';

import LDClient from './LDClient';

jest.mock('@launchdarkly/js-sdk-common', () => {
const actual = jest.requireActual('@launchdarkly/js-sdk-common');
return {
...actual,
...{
internal: {
...actual.internal,
DiagnosticsManager: jest.fn(),
EventProcessor: jest.fn(),
},
},
};
});

const mockEventProcessor = internal.EventProcessor as jest.Mock;
describe('Edge LDClient', () => {
it('uses clientSideID endpoints', async () => {
const client = new LDClient('client-side-id', basicPlatform.info, {
sendEvents: true,
});
await client.waitForInitialization();
const passedConfig = mockEventProcessor.mock.calls[0][0];

expect(passedConfig).toMatchObject({
sendEvents: true,
serviceEndpoints: {
includeAuthorizationHeader: false,
analyticsEventPath: '/events/bulk/client-side-id',
diagnosticEventPath: '/events/diagnostic/client-side-id',
events: 'https://events.launchdarkly.com',
polling: 'https://sdk.launchdarkly.com',
streaming: 'https://stream.launchdarkly.com',
},
});
});
});
4 changes: 1 addition & 3 deletions packages/shared/sdk-server-edge/src/api/LDClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import createOptions from './createOptions';
/**
* The LaunchDarkly SDK edge client object.
*/
export class LDClient extends LDClientImpl {
export default class LDClient extends LDClientImpl {
emitter: EventEmitter;

// clientSideID is only used to query the edge key-value store and send analytics, not to initialize with LD servers
Expand All @@ -25,5 +25,3 @@ export class LDClient extends LDClientImpl {
this.emitter = em;
}
}

export default LDClient;
4 changes: 3 additions & 1 deletion packages/shared/sdk-server-edge/src/api/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
import LDClient from './LDClient';

export * from './EdgeFeatureStore';
export * from './LDClient';
export { LDClient };
1 change: 1 addition & 0 deletions packages/shared/sdk-server/src/options/Configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ export default class Configuration {
validatedOptions.eventsUri,
internalOptions.analyticsEventPath,
internalOptions.diagnosticEventPath,
internalOptions.includeAuthorizationHeader,
);
this.eventsCapacity = validatedOptions.capacity;
this.timeout = validatedOptions.timeout;
Expand Down

0 comments on commit 5da020e

Please sign in to comment.