Skip to content

Commit

Permalink
Add test ensuring we are initialized
Browse files Browse the repository at this point in the history
  • Loading branch information
keelerm84 committed Jan 29, 2025
1 parent e8a7400 commit 509aa4c
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions packages/sdk/akamai-edgekv/__tests__/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import EdgeKVProvider from '../src/edgekv/edgeKVProvider';
import { init as initWithEdgeKV, LDClient, LDContext } from '../src/index';
import { init as initWithEdgeKV, LDClient, LDContext, LDLogger } from '../src/index';
import * as testData from './testData.json';

jest.mock('../src/edgekv/edgekv', () => ({
EdgeKV: jest.fn(),
}));

let logger: LDLogger;

const sdkKey = 'test-sdk-key';
const flagKey1 = 'testFlag1';
const flagKey2 = 'testFlag2';
Expand All @@ -17,11 +19,17 @@ describe('init', () => {

describe('init with Edge KV', () => {
beforeAll(async () => {
ldClient = initWithEdgeKV({ namespace: 'akamai-test', group: 'Akamai', sdkKey });
ldClient = initWithEdgeKV({ namespace: 'akamai-test', group: 'Akamai', sdkKey, options: { logger } });

Check failure on line 22 in packages/sdk/akamai-edgekv/__tests__/index.test.ts

View workflow job for this annotation

GitHub Actions / build-test-akamai-edgekv

Replace `·namespace:·'akamai-test',·group:·'Akamai',·sdkKey,·options:·{·logger·}` with `⏎········namespace:·'akamai-test',⏎········group:·'Akamai',⏎········sdkKey,⏎········options:·{·logger·},⏎·····`
await ldClient.waitForInitialization();
});

beforeEach(() => {
logger = {
error: jest.fn(),
warn: jest.fn(),
info: jest.fn(),
debug: jest.fn(),
};
jest
.spyOn(EdgeKVProvider.prototype, 'get')
.mockImplementation(() => Promise.resolve(JSON.stringify(testData)));
Expand All @@ -31,6 +39,12 @@ describe('init', () => {
ldClient.close();
});

it('should not log a warning about initialization', async () => {
const spy = jest.spyOn(logger, 'warn');
const value = await ldClient.variation(flagKey1, context, false);

Check failure on line 44 in packages/sdk/akamai-edgekv/__tests__/index.test.ts

View workflow job for this annotation

GitHub Actions / build-test-akamai-edgekv

'value' is assigned a value but never used. Allowed unused vars must match /^__/u
expect(spy).not.toHaveBeenCalled();
})

Check failure on line 46 in packages/sdk/akamai-edgekv/__tests__/index.test.ts

View workflow job for this annotation

GitHub Actions / build-test-akamai-edgekv

Insert `;`

describe('flags', () => {
it('variation default', async () => {
const value = await ldClient.variation(flagKey1, context, false);
Expand Down

0 comments on commit 509aa4c

Please sign in to comment.