diff --git a/ts-tests/index.ts b/ts-tests/index.ts index 2278320..f5e2650 100644 --- a/ts-tests/index.ts +++ b/ts-tests/index.ts @@ -1,3 +1,16 @@ +/** + * Split software typescript declarations testing. + * + * This file is not meant to run but to be compiled without errors. This is the same way to test .d.ts files + * that you will need to comply to publish packages on @types organization on NPM (DefinitelyTyped). + * We import the declarations through the NPM package name (using the development branch of the repo) + * to test in the same way in which customers will be using it on development. + * + * The step of compiling this file is part of the continous integration systems in place. + * + * @author Emiliano Sanchez + */ + /// /// @@ -10,6 +23,49 @@ import { } from '@splitsoftware/splitio-react-native/full'; import { SplitFactory, DebugLogger, InfoLogger, WarnLogger, ErrorLogger, LocalhostFromObject } from '@splitsoftware/splitio-react-native'; +/**** Interfaces ****/ + +// Facade return interface +let SDK: SplitIO.ISDK; +// Settings interfaces +let reactNativeSettings: SplitIO.IReactNativeSettings; +// Client & Manager APIs +let client: SplitIO.IClient; +let manager: SplitIO.IManager; + +/**** Tests for SDK interface ****/ + +reactNativeSettings = { + core: { + authorizationKey: 'another-key', + key: 'customer-key', + }, +}; + +SDK = SplitFactory(reactNativeSettings); +SDK = SplitFactoryFull(reactNativeSettings); + +// Client and Manager +client = SDK.client(); +client = SDK.client('a customer key'); // `client = SDK.client('a customer key', 'a traffic type');` Not valid in Browser JS SDK +manager = SDK.manager(); + +console.log(client); +console.log(manager); + +/**** Tests for fully crowded settings interfaces ****/ + +// Config parameters +let impressionListener: SplitIO.IImpressionListener = { + logImpression: (data: SplitIO.ImpressionData) => { + console.log(data); + }, +}; +let splitFilters: SplitIO.SplitFilter[] = [ + { type: 'byName', values: ['my_split_1', 'my_split_1'] }, + { type: 'byPrefix', values: ['my_split', 'test_split_'] }, +]; + const fullReactNativeConfig: SplitIO.IReactNativeSettings = { core: { authorizationKey: 'api-key', @@ -43,19 +99,12 @@ const fullReactNativeConfig: SplitIO.IReactNativeSettings = { features: { feature1: 'treatment', }, - impressionListener: { - logImpression: (data: SplitIO.ImpressionData) => { - console.log(data); - }, - }, + impressionListener: impressionListener, debug: DebugLogger(), integrations: [], streamingEnabled: true, sync: { - splitFilters: [ - { type: 'byName', values: ['my_split_1', 'my_split_1'] }, - { type: 'byPrefix', values: ['my_split', 'test_split_'] }, - ], + splitFilters: splitFilters, impressionsMode: 'DEBUG', localhostMode: LocalhostFromObject(), enabled: true, @@ -63,6 +112,10 @@ const fullReactNativeConfig: SplitIO.IReactNativeSettings = { userConsent: 'GRANTED', }; +// debug property can be a boolean, log level or Logger instance +fullReactNativeConfig.debug = false; +fullReactNativeConfig.debug = 'ERROR'; +fullReactNativeConfig.debug = DebugLogger(); fullReactNativeConfig.debug = InfoLogger(); fullReactNativeConfig.debug = WarnLogger(); fullReactNativeConfig.debug = ErrorLogger(); @@ -71,15 +124,5 @@ fullReactNativeConfig.debug = InfoLoggerFull(); fullReactNativeConfig.debug = WarnLoggerFull(); fullReactNativeConfig.debug = ErrorLoggerFull(); -const sdkSlim = SplitFactory(fullReactNativeConfig); -const sdkFull = SplitFactoryFull(fullReactNativeConfig); - -let client: SplitIO.IClient = sdkSlim.client(); -client = sdkSlim.client('other key'); -client = sdkFull.client(); -client = sdkFull.client('other key'); -console.log(client); - -let manager: SplitIO.IManager = sdkSlim.manager(); -manager = sdkFull.manager(); -console.log(manager); +fullReactNativeConfig.userConsent = 'DECLINED'; +fullReactNativeConfig.userConsent = 'UNKNOWN';