Skip to content

Commit ffd847f

Browse files
committed
Minor fixes + updated tests
1 parent 95deaca commit ffd847f

File tree

4 files changed

+268
-272
lines changed

4 files changed

+268
-272
lines changed

packages/optimizely-sdk/lib/index.browser.tests.js

Lines changed: 85 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ import configValidator from './utils/config_validator';
2626
import eventProcessorConfigValidator from './utils/event_processor_config_validator';
2727
import OptimizelyUserContext from './optimizely_user_context';
2828
import { LOG_MESSAGES } from './utils/enums';
29+
import { OdpSegmentManager } from './core/odp/odp_segment_manager';
30+
import { BrowserLRUCache } from './utils/lru_cache';
31+
import { OdpConfig } from './core/odp/odp_config';
32+
import { OdpSegmentApiManager } from './core/odp/odp_segment_api_manager';
33+
import { BrowserRequestHandler } from './utils/http_request_handler/browser_request_handler';
2934

3035
var LocalStoragePendingEventsDispatcher = eventProcessor.LocalStoragePendingEventsDispatcher;
3136

@@ -637,37 +642,103 @@ describe('javascript-sdk (Browser)', function() {
637642
sinon.assert.calledWith(logger.log, optimizelyFactory.enums.LOG_LEVEL.INFO, LOG_MESSAGES.ODP_DISABLED);
638643
});
639644

640-
it('should accept a custom cache size', () => {
641-
// TODO
642-
})
645+
it('should accept a valid custom cache size', () => {
646+
const client = optimizelyFactory.createInstance({
647+
datafile: testData.getTestProjectConfigWithFeatures(),
648+
errorHandler: fakeErrorHandler,
649+
eventDispatcher: fakeEventDispatcher,
650+
eventBatchSize: null,
651+
logger: logger,
652+
odpServiceConfig: {
653+
odpSegmentsCacheSize: 10,
654+
},
655+
});
656+
657+
sinon.assert.calledWith(
658+
logger.log,
659+
optimizelyFactory.enums.LOG_LEVEL.DEBUG,
660+
'Provisioning cache with maxSize of 10'
661+
);
662+
});
643663

644664
it('should accept a custom cache timeout', () => {
645-
// TODO
646-
})
665+
const client = optimizelyFactory.createInstance({
666+
datafile: testData.getTestProjectConfigWithFeatures(),
667+
errorHandler: fakeErrorHandler,
668+
eventDispatcher: fakeEventDispatcher,
669+
eventBatchSize: null,
670+
logger: logger,
671+
odpServiceConfig: {
672+
odpSegmentsCacheTimeout: 10,
673+
},
674+
});
675+
676+
sinon.assert.calledWith(
677+
logger.log,
678+
optimizelyFactory.enums.LOG_LEVEL.DEBUG,
679+
'Provisioning cache with timeout of 10'
680+
);
681+
});
647682

648683
it('should accept both a custom cache size and timeout', () => {
649-
// TODO
650-
})
684+
const client = optimizelyFactory.createInstance({
685+
datafile: testData.getTestProjectConfigWithFeatures(),
686+
errorHandler: fakeErrorHandler,
687+
eventDispatcher: fakeEventDispatcher,
688+
eventBatchSize: null,
689+
logger: logger,
690+
odpServiceConfig: {
691+
odpSegmentsCacheSize: 10,
692+
odpSegmentsCacheTimeout: 10,
693+
},
694+
});
651695

652-
it('should accept a valid custom cache', () => {
653-
// TODO
654-
})
696+
sinon.assert.calledWith(
697+
logger.log,
698+
optimizelyFactory.enums.LOG_LEVEL.DEBUG,
699+
'Provisioning cache with maxSize of 10'
700+
);
701+
702+
sinon.assert.calledWith(
703+
logger.log,
704+
optimizelyFactory.enums.LOG_LEVEL.DEBUG,
705+
'Provisioning cache with timeout of 10'
706+
);
707+
});
655708

656709
it('should accept a valid custom odp segment manager', () => {
710+
const segmentManager = new OdpSegmentManager(
711+
new OdpConfig(),
712+
new BrowserLRUCache(),
713+
new OdpSegmentApiManager(new BrowserRequestHandler(), logger),
714+
logger
715+
);
716+
717+
const client = optimizelyFactory.createInstance({
718+
datafile: testData.getTestProjectConfigWithFeatures(),
719+
errorHandler: fakeErrorHandler,
720+
eventDispatcher: fakeEventDispatcher,
721+
eventBatchSize: null,
722+
logger: logger,
723+
odpServiceConfig: {
724+
odpSegmentManager: segmentManager,
725+
},
726+
});
727+
657728
// TODO
658-
})
729+
});
659730

660731
it('should accept a valid custom odp event manager', () => {
661732
// TODO
662-
})
733+
});
663734

664735
it('should send an odp event with sendOdpEvent', () => {
665736
// TODO
666-
})
737+
});
667738

668739
it('should log an error when attempting to send an odp event when odp is disabled', () => {
669740
// TODO
670-
})
741+
});
671742
});
672743
});
673744
});

0 commit comments

Comments
 (0)