Skip to content

[TS] Refactor type definition tests #34

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: type_definitions_splitio_namespace
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 64 additions & 21 deletions ts-tests/index.ts
Original file line number Diff line number Diff line change
@@ -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 <emiliano.sanchez@split.io>
*/

///<reference types="../types" />
///<reference types="../types/full" />

Expand All @@ -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',
Expand Down Expand Up @@ -43,26 +99,23 @@ 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,
},
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();
Expand All @@ -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';