diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile
index 2d3077f..ad4c0a8 100644
--- a/.devcontainer/Dockerfile
+++ b/.devcontainer/Dockerfile
@@ -1,4 +1,4 @@
-FROM denoland/deno:2.4.3
+FROM denoland/deno:2.5.4
# Install tools
RUN apt-get update && \
diff --git a/.github/workflows/master.yml b/.github/workflows/master.yml
index 121b579..3d0cb70 100644
--- a/.github/workflows/master.yml
+++ b/.github/workflows/master.yml
@@ -17,10 +17,10 @@ jobs:
with:
fetch-depth: 0
- - name: Setup Deno v2.5.3
+ - name: Setup Deno v2.5.4
uses: denoland/setup-deno@v2
with:
- deno-version: v2.5.3
+ deno-version: v2.5.4
- name: Setup LCOV
run: sudo apt install -y lcov
@@ -45,7 +45,7 @@ jobs:
strategy:
fail-fast: false
matrix:
- deno-version: [v1.46.3, v2.5.3]
+ deno-version: [v1.46.3, v2.5.4]
os: [ ubuntu-latest, windows-latest ]
runs-on: ${{ matrix.os }}
diff --git a/.github/workflows/sonar.yml b/.github/workflows/sonar.yml
index c86f38e..b95d31d 100644
--- a/.github/workflows/sonar.yml
+++ b/.github/workflows/sonar.yml
@@ -33,10 +33,10 @@ jobs:
ref: ${{ steps.pr.outputs.head_sha }}
fetch-depth: 0
- - name: Setup Deno v2.5.3
+ - name: Setup Deno v2.5.4
uses: denoland/setup-deno@v2
with:
- deno-version: v2.5.3
+ deno-version: v2.5.4
- name: Setup LCOV
run: sudo apt install -y lcov
diff --git a/README.md b/README.md
index 9056a3a..debed6d 100644
--- a/README.md
+++ b/README.md
@@ -1,4 +1,4 @@
-***
+# Switcher4Deno
Switcher4Deno
@@ -16,244 +16,339 @@ A Deno SDK for Switcher API
-***
+
+

+
-
+## ๐ Table of Contents
+
+- [๐ฏ About](#-about)
+ - [โจ Key Features](#-key-features)
+- [๐ Quick Start](#-quick-start)
+ - [Prerequisites](#prerequisites)
+ - [Installation](#installation)
+ - [Basic Setup](#basic-setup)
+- [โ๏ธ Configuration](#๏ธ-configuration)
+ - [Context Parameters](#context-parameters)
+ - [Advanced Options](#advanced-options)
+ - [Options Reference](#options-reference)
+- [๐ก Usage Examples](#-usage-examples)
+ - [1. Basic Feature Flag Check](#1-basic-feature-flag-check)
+ - [2. Strategy Validation with Input Preparation](#2-strategy-validation-with-input-preparation)
+ - [3. All-in-One Execution](#3-all-in-one-execution)
+ - [4. Performance Optimization with Throttling](#4-performance-optimization-with-throttling)
+ - [5. Hybrid Mode - Force Remote Resolution](#5-hybrid-mode---force-remote-resolution)
+- [๐งช Testing & Development](#-testing--development)
+ - [Built-in Stub Feature](#built-in-stub-feature)
+ - [Test Mode](#test-mode)
+ - [Smoke Testing](#smoke-testing)
+- [๐ธ Snapshot Management](#-snapshot-management)
+ - [Loading Snapshots](#loading-snapshots)
+ - [Real-time Snapshot Monitoring](#real-time-snapshot-monitoring)
+ - [Snapshot Version Checking](#snapshot-version-checking)
+ - [Automatic Snapshot Updates](#automatic-snapshot-updates)
+
+## ๐ฏ About
+
+**Switcher4Deno** is a feature-rich SDK for integrating [Switcher API](https://github.com/switcherapi/switcher-api) into your Deno applications. It provides robust feature flag management with enterprise-grade capabilities.
+
+### โจ Key Features
+
+- ๐ **Zero Latency**: Local mode with snapshot files or in-memory for instant feature flag resolution
+- ๐ **Hybrid Configuration**: Silent mode with automatic fallback handling
+- ๐งช **Testing Ready**: Built-in stub implementation for comprehensive testing
+- โก **Performance Optimized**: Throttling optimizes remote API calls to reduce bottlenecks in critical code paths
+- ๐ ๏ธ **Developer Tools**: Runtime snapshot updates without app restart and automatic sync with remote API
+
+## ๐ Quick Start
+
+### Prerequisites
+
+- **Deno**: Version 1.4x or higher
+- **Required Permissions**:
+ ```bash
+ --allow-read --allow-write --allow-net
+ ```
+
+### Installation
-# About
-Deno SDK for working with Switcher-API.
-https://github.com/switcherapi/switcher-api
+```ts
+// Via JSR (Recommended)
+import { Client } from "@switcherapi/switcher-client-deno@[VERSION]";
-- Flexible and robust functions that will keep your code clean and maintainable.
-- Able to work locally using a snapshot file downloaded from your remote Switcher-API Domain.
-- Silent mode is a hybrid configuration that automatically enables a contingent sub-process in case of any connectivity issue.
-- Built-in stub implementation for clear and easy implementation of automated testing.
-- Easy to setup. Switcher Context is responsible to manage all the complexity between your application and API.
+// Via deno.land
+import { Client } from 'https://deno.land/x/switcher4deno@v[VERSION]/mod.ts';
+```
-# Usage
+### Basic Setup
-## Module initialization
-The context properties stores all information regarding connectivity.
+```ts
+import { Client } from "@switcherapi/switcher-client-deno";
+
+// Initialize the client context
+Client.buildContext({
+ url: 'https://api.switcherapi.com',
+ apiKey: '[YOUR_API_KEY]',
+ domain: 'My Domain',
+ component: 'MyApp',
+ environment: 'default'
+});
-(*) Requires Deno 1.4x or higher (use `--unstable` flag for Deno versions lower than 1.4x)
+// Get a switcher instance
+const switcher = Client.getSwitcher();
-> Flags required
-```
---allow-read
---allow-write
---allow-net
+// Check if a feature is enabled
+const isEnabled = await switcher.isItOn('FEATURE01');
+console.log('Feature enabled:', isEnabled);
```
-> Initialization
-```ts
-import { Client } from "@switcherapi/switcher-client-deno@[VERSION]"; // or
-import { Client } from 'https://deno.land/x/switcher4deno@v[VERSION]/mod.ts';
+## โ๏ธ Configuration
+### Context Parameters
-const url = 'https://api.switcherapi.com';
-const apiKey = '[API_KEY]';
-const environment = 'default';
-const domain = 'My Domain';
-const component = 'MyApp';
-```
+| Parameter | Type | Required | Description |
+|-----------|------|----------|-------------|
+| `domain` | string | โ
| Your Switcher domain name |
+| `url` | string | | Switcher API endpoint |
+| `apiKey` | string | | API key for your component |
+| `component` | string | | Your application name |
+| `environment` | string | | Environment name (default: 'default' for production) |
-- **domain**: Domain name.
-- **url**: (optional) Swither-API endpoint.
-- **apiKey**: (optional) Switcher-API key generated to your component.
-- **component**: (optional) Application name.
-- **environment**: (optional) Environment name. Production environment is named as 'default'.
+### Advanced Options
-## Options
-You can also activate features such as local and silent mode:
+Configure additional features for enhanced functionality:
```ts
-const local = true;
-const freeze = true;
-const logger = true;
-const snapshotLocation = './snapshot/';
-const snapshotAutoUpdateInterval = 3;
-const snapshotWatcher = true;
-const silentMode = '5m';
-const restrictRelay = true;
-const certPath = './certs/ca.pem';
-
-Client.buildContext({ url, apiKey, domain, component, environment }, {
- local, static, logger, snapshotLocation, snapshotAutoUpdateInterval,
- snapshotWatcher, silentMode, restrictRelay, certPath
+Client.buildContext({
+ url, apiKey, domain, component, environment
+}, {
+ local: true, // Enable local mode
+ freeze: false, // Prevent background updates
+ logger: true, // Enable request logging
+ snapshotLocation: './snapshot/', // Snapshot files directory
+ snapshotAutoUpdateInterval: 300, // Auto-update interval (seconds)
+ snapshotWatcher: true, // Monitor snapshot changes
+ silentMode: '5m', // Fallback timeout
+ restrictRelay: true, // Relay restrictions in local mode
+ regexSafe: true, // Prevent reDOS attacks
+ certPath: './certs/ca.pem' // SSL certificate path
});
-
-const switcher = Client.getSwitcher();
```
-- **local**: If activated, the client will only fetch the configuration inside your snapshot file. The default value is 'false'
-- **freeze**: If activated, prevents the execution of background cache update when using throttle. The default value is 'false'
-- **logger**: If activated, it is possible to retrieve the last results from a given Switcher key using Client.getLogger('KEY')
-- **snapshotLocation**: Location of snapshot files
-- **snapshotAutoUpdateInterval**: Enable Snapshot Auto Update given an interval in seconds (default: 0 disabled)
-- **snapshotWatcher**: Enable Snapshot Watcher to monitor changes in the snapshot file (default: false)
-- **silentMode**: Enable contigency given the time for the client to retry - e.g. 5s (s: seconds - m: minutes - h: hours)
-- **restrictRelay**: Enable Relay Restriction - Allow managing Relay restrictions when running in local mode (default: true)
-- **regexSafe**: Enable REGEX Safe mode - Prevent agaist reDOS attack (default: true)
-- **regexMaxBlackList**: Number of entries cached when REGEX Strategy fails to perform (reDOS safe) - default: 50
-- **regexMaxTimeLimit**: Time limit (ms) used by REGEX workers (reDOS safe) - default - 3000ms
-- **certPath**: Path to the certificate file used to establish a secure connection with the API
-
-(*) regexSafe is a feature that prevents your application from being exposed to a reDOS attack. It is recommended to keep this feature enabled.
-However, this feature uses Web Worker API which is currently not compatible with compiled executables.
-
-## Executing
-There are a few different ways to call the API.
-Here are some examples:
-
-1. **Basic usage**
-Some of the ways you can check if a feature is enabled or not.
+#### Options Reference
+
+| Option | Type | Description |
+|--------|------|-------------|
+| `local` | boolean | Use only snapshot files/in-memory (no API calls) |
+| `freeze` | boolean | Disable background cache updates with throttling |
+| `logger` | boolean | Enable logging for debugging (`Client.getLogger('KEY')`) |
+| `snapshotLocation` | string | Directory for snapshot files |
+| `snapshotAutoUpdateInterval` | number | Auto-update interval in seconds (0 = disabled) |
+| `snapshotWatcher` | boolean | Watch for snapshot file changes |
+| `silentMode` | string | Fallback timeout (e.g., '5s', '2m', '1h') |
+| `restrictRelay` | boolean | Enable relay restrictions in local mode |
+| `regexSafe` | boolean | Protection against reDOS attacks |
+| `regexMaxBlackList` | number | Max cached regex failures |
+| `regexMaxTimeLimit` | number | Regex timeout in milliseconds |
+| `certPath` | string | Path to SSL certificate file |
+
+> **โ ๏ธ Note on regexSafe**: This feature protects against reDOS attacks but uses Web Workers, which are incompatible with compiled executables.
+
+## ๐ก Usage Examples
+
+### 1. Basic Feature Flag Check
+
+Simple on/off checks for feature flags:
```ts
const switcher = Client.getSwitcher();
-// Local (synchronous) execution
-const isOnBool = switcher.isItOn('FEATURE01') as boolean; // true or false
-const isOnBool = switcher.isItOnBool('FEATURE01'); // true or false
-const isOnDetail = switcher.detail().isItOn('FEATURE01') as SwitcherResult; // { result: true, reason: 'Success', metadata: {} }
-const isOnDetail = switcher.isItOnDetail('FEATURE01'); // { result: true, reason: 'Success', metadata: {} }
-
-// Remote (asynchronous) execution or hybrid (local/remote) execution
-const isOnBoolAsync = await switcher.isItOn('FEATURE01'); // Promise
-const isOnBoolAsync = await switcher.isItOnBool('FEATURE01', true); // Promise
-const isOnDetailAsync = await switcher.detail().isItOn('FEATURE01'); // Promise
-const isOnDetailAsync = await switcher.isItOnDetail('FEATURE01', true); // Promise
+// Synchronous (local mode only)
+const isEnabled = switcher.isItOn('FEATURE01') as boolean;
+const isEnabledBool = switcher.isItOnBool('FEATURE01');
+// Returns: true or false
+
+// With detailed response
+const response = switcher.detail().isItOn('FEATURE01') as SwitcherResult;
+const detailedResponse = switcher.isItOnDetail('FEATURE01');
+// Returns: { result: true, reason: 'Success', metadata: {} }
+
+// Asynchronous (remote/hybrid mode)
+const isEnabledAsync = await switcher.isItOn('FEATURE01');
+const isEnabledBoolAsync = await switcher.isItOnBool('FEATURE01', true);
+const responseAsync = await switcher.detail().isItOn('FEATURE01');
+const detailedResponseAsync = await switcher.isItOnDetail('FEATURE01', true);
+// Returns: Promise or Promise
```
-2. **Strategy validation - preparing input**
-Loading information into the switcher can be made by using *prepare*, in case you want to include input from a different place of your code. Otherwise, it is also possible to include everything in the same call.
+### 2. Strategy Validation with Input Preparation
+
+Prepare context data before evaluation:
```ts
+// Prepare input in advance
await switcher.checkValue('USER_1').prepare('FEATURE01');
-await switcher.isItOn();
+const result = await switcher.isItOn();
+
+// Or chain preparations
+await switcher
+ .checkValue('premium_user')
+ .checkNetwork('192.168.1.0/24')
+ .prepare('ADVANCED_FEATURE');
```
-3. **Strategy validation - all-in-one execution**
-All-in-one method is fast and include everything you need to execute a complex call to the API.
+### 3. All-in-One Execution
+
+Complex feature flag evaluation with multiple strategies:
```ts
-await switcher
- .defaultResult(true) // Default result to be returned in case of no API response
- .throttle(1000) // Throttle the API call to improve performance
- .checkValue('User 1')
- .checkNetwork('192.168.0.1')
- .isItOn('FEATURE01');
+const result = await switcher
+ .defaultResult(true) // Fallback value if API fails
+ .throttle(1000) // Cache result for 1 second
+ .checkValue('User 1') // VALUE strategy
+ .checkNetwork('192.168.0.1') // NETWORK strategy
+ .isItOn('FEATURE01');
```
-4. **Throttle**
-Throttling is useful when placing Feature Flags at critical code blocks that require zero-latency.
-API calls will be scheduled to be executed after the throttle time has passed.
+### 4. Performance Optimization with Throttling
+
+Reduce API calls for high-frequency checks:
```ts
const switcher = Client.getSwitcher();
-await switcher
- .throttle(1000)
- .isItOn('FEATURE01');
-```
-In order to capture issues that may occur during the process, it is possible to log the error by subscribing to the error events.
+// Cache result for 1 second
+const result = await switcher
+ .throttle(1000)
+ .isItOn('FEATURE01');
-```js
+// Handle throttling errors
Client.subscribeNotifyError((error) => {
- console.log(error);
+ console.error('Switcher error:', error);
});
```
-5. **Hybrid mode**
-Forcing Switchers to resolve remotely can help you define exclusive features that cannot be resolved locally.
-This feature is ideal if you want to run the SDK in local mode but still want to resolve a specific switcher remotely.
+### 5. Hybrid Mode - Force Remote Resolution
-A particular use case is when a swithcer has a Relay Strategy that requires a remote call to resolve the value.
+Override local mode for specific switchers:
```ts
-const switcher = Client.getSwitcher();
-await switcher.remote().isItOn('FEATURE01');
+// Force remote resolution even in local mode
+const result = await switcher
+ .remote()
+ .isItOn('CRITICAL_FEATURE');
```
-## Built-in stub feature
-You can also bypass your switcher configuration with 'Client.assume' API. This is perfect for your test code where you want to validate both scenarios when the switcher is true and false.
+This is useful for:
+- Relay strategies requiring remote calls
+- Critical features that must be resolved remotely
+- Real-time configuration updates
+
+## ๐งช Testing & Development
+
+### Built-in Stub Feature
+
+Mock feature flag responses for comprehensive testing:
```ts
+// Simple true/false mocking
Client.assume('FEATURE01').true();
-switcher.isItOn('FEATURE01'); // true
+console.log(switcher.isItOn('FEATURE01')); // Always returns true
+Client.assume('FEATURE01').false();
+console.log(switcher.isItOn('FEATURE01')); // Always returns false
+
+// Reset to normal behavior
Client.forget('FEATURE01');
-switcher.isItOn('FEATURE01'); // Now, it's going to return the result retrieved from the API or the Snaopshot file
-Client.assume('FEATURE01').false().withMetadata({ message: 'Feature is disabled' }); // Include metadata to emulate Relay response
-const response = await switcher.detail().isItOn('FEATURE01') as SwitcherResult; // false
-console.log(response.metadata.message); // Feature is disabled
+// Mock with metadata (simulating Relay responses)
+Client.assume('FEATURE01')
+ .false()
+ .withMetadata({ message: 'Feature disabled for maintenance' });
+
+const response = await switcher.detail().isItOn('FEATURE01') as SwitcherResult;
+console.log(response.result); // false
+console.log(response.metadata.message); // 'Feature disabled for maintenance'
-Client.assume('FEATURE01').true().when(StrategiesType.VALUE, 'USER_1');
-switcher.checkValue('USER_1').isItOn('FEATURE01'); // true when the value is 'USER_1'
+// Conditional mocking based on input
+Client.assume('FEATURE01').true().when(StrategiesType.VALUE, 'premium_user');
+console.log(switcher.checkValue('premium_user').isItOn('FEATURE01')); // true
+console.log(switcher.checkValue('basic_user').isItOn('FEATURE01')); // false
-Client.assume('FEATURE01').true().when(StrategiesType.NETWORK, ['USER_2', 'USER_3']);
-switcher.checkValue('USER_1').isItOn('FEATURE01'); // false as the value is not in the list
+// Mock with multiple values
+Client.assume('FEATURE01').true().when(StrategiesType.NETWORK, ['192.168.1.1', '10.0.0.1']);
```
-**Enabling Test Mode**
-You may want to enable this feature while using Switcher Client with automated testing.
-It prevents the Switcher Client from locking snapshot files even after the test execution.
+### Test Mode
+
+Enable test mode to prevent file locking during automated testing:
-To enable this feature, it is recommended to place the following on your test setup files:
```ts
+// In your test setup
Client.testMode();
```
-**Smoke Test**
-It can validate Switcher Keys on your testing pipelines before deploying a change.
-Switcher Keys may not be configured correctly and can cause your code to have unwanted results.
+### Smoke Testing
+
+Validate feature flag during startup to catch configuration issues early:
-This feature will validate using the context provided to check if everything is properly configured.
-In case something is missing, this operation will throw an exception pointing out which Switcher Keys are not configured.
```ts
-await Client.checkSwitchers(['FEATURE01', 'FEATURE02'])
+try {
+ await Client.checkSwitchers(['FEATURE01', 'FEATURE02', 'CRITICAL_FEATURE']);
+ console.log('โ
All switchers configured correctly');
+} catch (error) {
+ console.error('โ Configuration issues found:', error.message);
+ process.exit(1);
+}
```
-## Loading Snapshot from the API
-This step is optional if you want to load a copy of the configuration that can be used to eliminate latency when local mode is activated.
-Activate watchSnapshot optionally passing true in the arguments.
-Auto load Snapshot from API passing true as second argument.
+## ๐ธ Snapshot Management
+
+Snapshots enable zero-latency local mode by caching your feature flag configuration.
+
+### Loading Snapshots
```ts
+// Load snapshot from API
const version = await Client.loadSnapshot();
+console.log('Loaded snapshot version:', version);
```
-## Watch for Snapshot file changes
-Activate and monitor snapshot changes using this feature. Optionally, you can implement any action based on the callback response.
+### Real-time Snapshot Monitoring
+
+#### Option 1: Programmatic Watching
```ts
Client.watchSnapshot({
- success: () => console.log('In-memory snapshot updated'),
- reject: (err: Error) => console.log(err)
+ success: () => console.log('โ
Snapshot updated successfully'),
+ reject: (err: Error) => console.error('โ Snapshot update failed:', err)
});
```
-Alternatively, you can also use the client context configuration to monitor changes in the snapshot file.
+#### Option 2: Configuration-based Watching
```ts
Client.buildContext({ domain, component, environment }, {
- local: true,
- snapshotLocation: './snapshot/',
- snapshotWatcher: true
+ local: true,
+ snapshotLocation: './snapshot/',
+ snapshotWatcher: true // Enable automatic monitoring
});
```
-## Snapshot version check
-For convenience, an implementation of a domain version checker is available if you have external processes that manage snapshot files.
+### Snapshot Version Checking
+
+Verify snapshot currency for external management:
```ts
-Client.checkSnapshot();
+const isLatest = Client.checkSnapshot();
+console.log('Snapshot is up to date:', isLatest);
```
-## Snapshot Update Scheduler
-You can also schedule a snapshot update using the method below.
-It allows you to run the Client SDK in local mode (zero latency) and still have the snapshot updated automatically.
+### Automatic Snapshot Updates
+
+Schedule periodic updates for local mode with automatic refresh:
```ts
+// Update every 3 seconds (3000 milliseconds)
Client.scheduleSnapshotAutoUpdate(3000, {
success: (updated) => console.log('Snapshot updated', updated),
reject: (err: Error) => console.log(err)
diff --git a/tests/deps.ts b/tests/deps.ts
index cf77edc..ad67b5c 100644
--- a/tests/deps.ts
+++ b/tests/deps.ts
@@ -1,6 +1,5 @@
// Library dependencies
-import { existsSync } from '../src/deps.ts'
-export { existsSync };
+export { existsSync } from '../src/deps.ts'
// Test dependencies
export {
@@ -12,8 +11,8 @@ export {
assertNotEquals,
assertGreater,
assertArrayIncludes
-} from 'jsr:@std/assert@1.0.14';
-export { assertSpyCalls, spy } from 'jsr:@std/testing@1.0.15/mock';
+} from 'jsr:@std/assert@1.0.15';
+export { assertSpyCalls, spy } from 'jsr:@std/testing@1.0.16/mock';
export {
describe,
it,
@@ -21,7 +20,7 @@ export {
beforeEach,
beforeAll,
afterEach
-} from 'jsr:@std/testing@1.0.15/bdd';
-export { delay } from 'jsr:@std/async@1.0.14/delay';
+} from 'jsr:@std/testing@1.0.16/bdd';
+export { delay } from 'jsr:@std/async@1.0.15/delay';
export { load } from 'jsr:@std/dotenv@0.225.5';
export * as mf from 'https://deno.land/x/mock_fetch@0.3.0/mod.ts';
\ No newline at end of file
diff --git a/tests/helper/utils.ts b/tests/helper/utils.ts
index c56c50f..1e9dfdb 100644
--- a/tests/helper/utils.ts
+++ b/tests/helper/utils.ts
@@ -1,7 +1,7 @@
import { assertEquals, mf } from '../deps.ts';
export function given(route: string, expect: object | undefined, status = 200) {
- mf.mock(route, (_req, _match) => {
+ mf.mock(route, (_req: Request, _match: Record) => {
return new Response(JSON.stringify(expect), {
status,
});
diff --git a/tests/strategy-operations/date.test.ts b/tests/strategy-operations/date.test.ts
index 6386a13..3cbcf22 100644
--- a/tests/strategy-operations/date.test.ts
+++ b/tests/strategy-operations/date.test.ts
@@ -27,69 +27,69 @@ describe('Strategy [DATE] tests:', function () {
activated: true,
});
- it('should agree when input is LOWER', async function () {
+ it('should agree when input is LOWER', function () {
const strategyConfig = givenStrategyConfig(OperationsType.LOWER, mock_values1);
- const result = await processOperation(strategyConfig, '2019-11-26');
+ const result = processOperation(strategyConfig, '2019-11-26');
assertTrue(result);
});
- it('should agree when input is LOWER or SAME', async function () {
+ it('should agree when input is LOWER or SAME', function () {
const strategyConfig = givenStrategyConfig(OperationsType.LOWER, mock_values1);
- const result = await processOperation(strategyConfig, '2019-12-01');
+ const result = processOperation(strategyConfig, '2019-12-01');
assertTrue(result);
});
- it('should NOT agree when input is NOT LOWER', async function () {
+ it('should NOT agree when input is NOT LOWER', function () {
const strategyConfig = givenStrategyConfig(OperationsType.LOWER, mock_values1);
- const result = await processOperation(strategyConfig, '2019-12-02');
+ const result = processOperation(strategyConfig, '2019-12-02');
assertFalse(result);
});
- it('should agree when input is GREATER', async function () {
+ it('should agree when input is GREATER', function () {
const strategyConfig = givenStrategyConfig(OperationsType.GREATER, mock_values1);
- const result = await processOperation(strategyConfig, '2019-12-02');
+ const result = processOperation(strategyConfig, '2019-12-02');
assertTrue(result);
});
- it('should agree when input is GREATER or SAME', async function () {
+ it('should agree when input is GREATER or SAME', function () {
const strategyConfig = givenStrategyConfig(OperationsType.GREATER, mock_values1);
- const result = await processOperation(strategyConfig, '2019-12-01');
+ const result = processOperation(strategyConfig, '2019-12-01');
assertTrue(result);
});
- it('should NOT agree when input is NOT GREATER', async function () {
+ it('should NOT agree when input is NOT GREATER', function () {
const strategyConfig = givenStrategyConfig(OperationsType.GREATER, mock_values1);
- const result = await processOperation(strategyConfig, '2019-11-10');
+ const result = processOperation(strategyConfig, '2019-11-10');
assertFalse(result);
});
- it('should agree when input is in BETWEEN', async function () {
+ it('should agree when input is in BETWEEN', function () {
const strategyConfig = givenStrategyConfig(OperationsType.BETWEEN, mock_values2);
- const result = await processOperation(strategyConfig, '2019-12-03');
+ const result = processOperation(strategyConfig, '2019-12-03');
assertTrue(result);
});
- it('should NOT agree when input is NOT in BETWEEN', async function () {
+ it('should NOT agree when input is NOT in BETWEEN', function () {
const strategyConfig = givenStrategyConfig(OperationsType.BETWEEN, mock_values2);
- const result = await processOperation(strategyConfig, '2019-12-12');
+ const result = processOperation(strategyConfig, '2019-12-12');
assertFalse(result);
});
- it('should agree when input is LOWER including time', async function () {
+ it('should agree when input is LOWER including time', function () {
const strategyConfig = givenStrategyConfig(OperationsType.LOWER, mock_values3);
- const result = await processOperation(strategyConfig, '2019-12-01T07:00');
+ const result = processOperation(strategyConfig, '2019-12-01T07:00');
assertTrue(result);
});
- it('should NOT agree when input is NOT LOWER including time', async function () {
+ it('should NOT agree when input is NOT LOWER including time', function () {
const strategyConfig = givenStrategyConfig(OperationsType.LOWER, mock_values1);
- const result = await processOperation(strategyConfig, '2019-12-01T07:00');
+ const result = processOperation(strategyConfig, '2019-12-01T07:00');
assertFalse(result);
});
- it('should agree when input is GREATER including time', async function () {
+ it('should agree when input is GREATER including time', function () {
const strategyConfig = givenStrategyConfig(OperationsType.GREATER, mock_values3);
- const result = await processOperation(strategyConfig, '2019-12-01T08:40');
+ const result = processOperation(strategyConfig, '2019-12-01T08:40');
assertTrue(result);
});
diff --git a/tests/strategy-operations/network.test.ts b/tests/strategy-operations/network.test.ts
index deb8565..67c5c51 100644
--- a/tests/strategy-operations/network.test.ts
+++ b/tests/strategy-operations/network.test.ts
@@ -29,57 +29,57 @@ describe('Strategy [NETWORK] tests:', function () {
activated: true,
});
- it('should agree when input range EXIST', async function () {
+ it('should agree when input range EXIST', function () {
const strategyConfig = givenStrategyConfig(OperationsType.EXIST, mock_values1);
- const result = await processOperation(strategyConfig, '10.0.0.3');
+ const result = processOperation(strategyConfig, '10.0.0.3');
assertTrue(result);
});
- it('should agree when input range EXIST - Irregular CIDR', async function () {
+ it('should agree when input range EXIST - Irregular CIDR', function () {
const strategyConfig = givenStrategyConfig(OperationsType.EXIST, ['10.0.0.3/24']);
- const result = await processOperation(strategyConfig, '10.0.0.3');
+ const result = processOperation(strategyConfig, '10.0.0.3');
assertTrue(result);
});
- it('should NOT agree when input range DOES NOT EXIST', async function () {
+ it('should NOT agree when input range DOES NOT EXIST', function () {
const strategyConfig = givenStrategyConfig(OperationsType.EXIST, mock_values1);
- const result = await processOperation(strategyConfig, '10.0.0.4');
+ const result = processOperation(strategyConfig, '10.0.0.4');
assertFalse(result);
});
- it('should agree when input DOES NOT EXIST', async function () {
+ it('should agree when input DOES NOT EXIST', function () {
const strategyConfig = givenStrategyConfig(OperationsType.NOT_EXIST, mock_values1);
- const result = await processOperation(strategyConfig, '10.0.0.4');
+ const result = processOperation(strategyConfig, '10.0.0.4');
assertTrue(result);
});
- it('should NOT agree when input EXIST but assumed that it DOES NOT EXIST', async function () {
+ it('should NOT agree when input EXIST but assumed that it DOES NOT EXIST', function () {
const strategyConfig = givenStrategyConfig(OperationsType.NOT_EXIST, mock_values1);
- const result = await processOperation(strategyConfig, '10.0.0.3');
+ const result = processOperation(strategyConfig, '10.0.0.3');
assertFalse(result);
});
- it('should agree when input IP EXIST', async function () {
+ it('should agree when input IP EXIST', function () {
const strategyConfig = givenStrategyConfig(OperationsType.EXIST, mock_values3);
- const result = await processOperation(strategyConfig, '192.168.56.58');
+ const result = processOperation(strategyConfig, '192.168.56.58');
assertTrue(result);
});
- it('should agree when input IP DOES NOT EXIST', async function () {
+ it('should agree when input IP DOES NOT EXIST', function () {
const strategyConfig = givenStrategyConfig(OperationsType.NOT_EXIST, mock_values3);
- const result = await processOperation(strategyConfig, '192.168.56.50');
+ const result = processOperation(strategyConfig, '192.168.56.50');
assertTrue(result);
});
- it('should agree when input range EXIST for multiple ranges', async function () {
+ it('should agree when input range EXIST for multiple ranges', function () {
const strategyConfig = givenStrategyConfig(OperationsType.EXIST, mock_values2);
- const result = await processOperation(strategyConfig, '192.168.0.3');
+ const result = processOperation(strategyConfig, '192.168.0.3');
assertTrue(result);
});
- it('should NOT agree when input range DOES NOT EXIST for multiple ranges', async function () {
+ it('should NOT agree when input range DOES NOT EXIST for multiple ranges', function () {
const strategyConfig = givenStrategyConfig(OperationsType.NOT_EXIST, mock_values2);
- const result = await processOperation(strategyConfig, '127.0.0.0');
+ const result = processOperation(strategyConfig, '127.0.0.0');
assertTrue(result);
});
diff --git a/tests/strategy-operations/numeric.test.ts b/tests/strategy-operations/numeric.test.ts
index d9f69a5..f1340ba 100644
--- a/tests/strategy-operations/numeric.test.ts
+++ b/tests/strategy-operations/numeric.test.ts
@@ -27,94 +27,94 @@ describe('Strategy [NUMERIC] tests:', function () {
activated: true,
});
- it('should agree when input EXIST in values - String type', async function () {
+ it('should agree when input EXIST in values - String type', function () {
const strategyConfig = givenStrategyConfig(OperationsType.EXIST, mock_values2);
- const result = await processOperation(strategyConfig, '3');
+ const result = processOperation(strategyConfig, '3');
assertTrue(result);
});
- it('should NOT agree when input exist but test as DOES NOT EXIST ', async function () {
+ it('should NOT agree when input exist but test as DOES NOT EXIST ', function () {
const strategyConfig = givenStrategyConfig(OperationsType.NOT_EXIST, mock_values2);
- const result = await processOperation(strategyConfig, '1');
+ const result = processOperation(strategyConfig, '1');
assertFalse(result);
});
- it('should agree when input DOES NOT EXIST in values', async function () {
+ it('should agree when input DOES NOT EXIST in values', function () {
const strategyConfig = givenStrategyConfig(OperationsType.NOT_EXIST, mock_values2);
- const result = await processOperation(strategyConfig, '2');
+ const result = processOperation(strategyConfig, '2');
assertTrue(result);
});
- it('should agree when input is EQUAL to value', async function () {
+ it('should agree when input is EQUAL to value', function () {
const strategyConfig = givenStrategyConfig(OperationsType.EQUAL, mock_values1);
- const result = await processOperation(strategyConfig, '1');
+ const result = processOperation(strategyConfig, '1');
assertTrue(result);
});
- it('should NOT agree when input is not equal but test as EQUAL', async function () {
+ it('should NOT agree when input is not equal but test as EQUAL', function () {
const strategyConfig = givenStrategyConfig(OperationsType.EQUAL, mock_values1);
- const result = await processOperation(strategyConfig, '2');
+ const result = processOperation(strategyConfig, '2');
assertFalse(result);
});
- it('should agree when input is NOT EQUAL to value', async function () {
+ it('should agree when input is NOT EQUAL to value', function () {
const strategyConfig = givenStrategyConfig(OperationsType.NOT_EQUAL, mock_values1);
- const result = await processOperation(strategyConfig, '2');
+ const result = processOperation(strategyConfig, '2');
assertTrue(result);
});
- it('should agree when input is GREATER than value', async function () {
+ it('should agree when input is GREATER than value', function () {
let strategyConfig = givenStrategyConfig(OperationsType.GREATER, mock_values1);
- let result = await processOperation(strategyConfig, '2');
+ let result = processOperation(strategyConfig, '2');
assertTrue(result);
// test decimal
- result = await processOperation(strategyConfig, '1.01');
+ result = processOperation(strategyConfig, '1.01');
assertTrue(result);
strategyConfig = givenStrategyConfig(OperationsType.GREATER, mock_values3);
- result = await processOperation(strategyConfig, '1.55');
+ result = processOperation(strategyConfig, '1.55');
assertTrue(result);
});
- it('should NOT agree when input is lower but tested as GREATER than value', async function () {
+ it('should NOT agree when input is lower but tested as GREATER than value', function () {
let strategyConfig = givenStrategyConfig(OperationsType.GREATER, mock_values1);
- let result = await processOperation(strategyConfig, '0');
+ let result = processOperation(strategyConfig, '0');
assertFalse(result);
// test decimal
- result = await processOperation(strategyConfig, '0.99');
+ result = processOperation(strategyConfig, '0.99');
assertFalse(result);
strategyConfig = givenStrategyConfig(OperationsType.GREATER, mock_values3);
- result = await processOperation(strategyConfig, '1.49');
+ result = processOperation(strategyConfig, '1.49');
assertFalse(result);
});
- it('should agree when input is LOWER than value', async function () {
+ it('should agree when input is LOWER than value', function () {
let strategyConfig = givenStrategyConfig(OperationsType.LOWER, mock_values1);
- let result = await processOperation(strategyConfig, '0');
+ let result = processOperation(strategyConfig, '0');
assertTrue(result);
// test decimal
- result = await processOperation(strategyConfig, '0.99');
+ result = processOperation(strategyConfig, '0.99');
assertTrue(result);
strategyConfig = givenStrategyConfig(OperationsType.LOWER, mock_values3);
- result = await processOperation(strategyConfig, '1.49');
+ result = processOperation(strategyConfig, '1.49');
assertTrue(result);
});
- it('should agree when input is BETWEEN values', async function () {
+ it('should agree when input is BETWEEN values', function () {
const strategyConfig = givenStrategyConfig(OperationsType.BETWEEN, mock_values2);
- let result = await processOperation(strategyConfig, '1');
+ let result = processOperation(strategyConfig, '1');
assertTrue(result);
// test decimal
- result = await processOperation(strategyConfig, '2.99');
+ result = processOperation(strategyConfig, '2.99');
assertTrue(result);
- result = await processOperation(strategyConfig, '1.001');
+ result = processOperation(strategyConfig, '1.001');
assertTrue(result);
});
diff --git a/tests/strategy-operations/payload.test.ts b/tests/strategy-operations/payload.test.ts
index de5cf92..50256bc 100644
--- a/tests/strategy-operations/payload.test.ts
+++ b/tests/strategy-operations/payload.test.ts
@@ -90,33 +90,33 @@ describe('Strategy [PAYLOAD] tests:', function () {
]);
});
- it('should return TRUE when payload has field', async function () {
+ it('should return TRUE when payload has field', function () {
const strategyConfig = givenStrategyConfig(OperationsType.HAS_ONE, ['login']);
- assertTrue(await processOperation(strategyConfig, fixture_1));
+ assertTrue(processOperation(strategyConfig, fixture_1));
});
- it('should return FALSE when payload does not have field', async function () {
+ it('should return FALSE when payload does not have field', function () {
const strategyConfig = givenStrategyConfig(OperationsType.HAS_ONE, ['user']);
- assertFalse(await processOperation(strategyConfig, fixture_1));
+ assertFalse(processOperation(strategyConfig, fixture_1));
});
- it('should return TRUE when payload has nested field', async function () {
+ it('should return TRUE when payload has nested field', function () {
const strategyConfig = givenStrategyConfig(OperationsType.HAS_ONE, [
'order.qty', 'order.total'
]);
- assertTrue(await processOperation(strategyConfig, fixture_values2));
+ assertTrue(processOperation(strategyConfig, fixture_values2));
});
- it('should return TRUE when payload has nested field with arrays', async function () {
+ it('should return TRUE when payload has nested field with arrays', function () {
const strategyConfig = givenStrategyConfig(OperationsType.HAS_ONE, [
'order.deliver.tracking.status'
]);
- assertTrue(await processOperation(strategyConfig, fixture_values2));
+ assertTrue(processOperation(strategyConfig, fixture_values2));
});
- it('should return TRUE when payload has all', async function () {
+ it('should return TRUE when payload has all', function () {
const strategyConfig = givenStrategyConfig(OperationsType.HAS_ALL, [
'product',
'order',
@@ -128,22 +128,22 @@ describe('Strategy [PAYLOAD] tests:', function () {
'order.deliver.tracking.status'
]);
- assertTrue(await processOperation(strategyConfig, fixture_values2));
+ assertTrue(processOperation(strategyConfig, fixture_values2));
});
- it('should return FALSE when payload does not have all', async function () {
+ it('should return FALSE when payload does not have all', function () {
const strategyConfig = givenStrategyConfig(OperationsType.HAS_ALL, [
'product',
'order',
'order.NOT_EXIST_KEY',
]);
- assertFalse(await processOperation(strategyConfig, fixture_values2));
+ assertFalse(processOperation(strategyConfig, fixture_values2));
});
- it('should return FALSE when payload is not a JSON string', async function () {
+ it('should return FALSE when payload is not a JSON string', function () {
const strategyConfig = givenStrategyConfig(OperationsType.HAS_ALL, []);
- assertFalse(await processOperation(strategyConfig, 'NOT_JSON'));
+ assertFalse(processOperation(strategyConfig, 'NOT_JSON'));
});
});
\ No newline at end of file
diff --git a/tests/strategy-operations/regex.test.ts b/tests/strategy-operations/regex.test.ts
index 7fd4a13..3ef2e10 100644
--- a/tests/strategy-operations/regex.test.ts
+++ b/tests/strategy-operations/regex.test.ts
@@ -8,12 +8,12 @@ import {
} from '../../src/lib/snapshot.ts';
const mock_values1 = [
- '\\bUSER_[0-9]{1,2}\\b',
+ String.raw`\bUSER_[0-9]{1,2}\b`,
];
const mock_values2 = [
- '\\bUSER_[0-9]{1,2}\\b',
- '\\buser-[0-9]{1,2}\\b',
+ String.raw`\bUSER_[0-9]{1,2}\b`,
+ String.raw`\buser-[0-9]{1,2}\b`,
];
const mock_values3 = [
diff --git a/tests/strategy-operations/time.test.ts b/tests/strategy-operations/time.test.ts
index fba2e15..1c0f5d2 100644
--- a/tests/strategy-operations/time.test.ts
+++ b/tests/strategy-operations/time.test.ts
@@ -23,51 +23,51 @@ describe('Strategy [TIME] tests:', function () {
activated: true,
});
- it('should agree when input is LOWER', async function () {
+ it('should agree when input is LOWER', function () {
const strategyConfig = givenStrategyConfig(OperationsType.LOWER, mock_values1);
- const result = await processOperation(strategyConfig, '06:00');
+ const result = processOperation(strategyConfig, '06:00');
assertTrue(result);
});
- it('should agree when input is LOWER or SAME', async function () {
+ it('should agree when input is LOWER or SAME', function () {
const strategyConfig = givenStrategyConfig(OperationsType.LOWER, mock_values1);
- const result = await processOperation(strategyConfig, '08:00');
+ const result = processOperation(strategyConfig, '08:00');
assertTrue(result);
});
- it('should NOT agree when input is NOT LOWER', async function () {
+ it('should NOT agree when input is NOT LOWER', function () {
const strategyConfig = givenStrategyConfig(OperationsType.LOWER, mock_values1);
- const result = await processOperation(strategyConfig, '10:00');
+ const result = processOperation(strategyConfig, '10:00');
assertFalse(result);
});
- it('should agree when input is GREATER', async function () {
+ it('should agree when input is GREATER', function () {
const strategyConfig = givenStrategyConfig(OperationsType.GREATER, mock_values1);
- const result = await processOperation(strategyConfig, '10:00');
+ const result = processOperation(strategyConfig, '10:00');
assertTrue(result);
});
- it('should agree when input is GREATER or SAME', async function () {
+ it('should agree when input is GREATER or SAME', function () {
const strategyConfig = givenStrategyConfig(OperationsType.GREATER, mock_values1);
- const result = await processOperation(strategyConfig, '08:00');
+ const result = processOperation(strategyConfig, '08:00');
assertTrue(result);
});
- it('should NOT agree when input is NOT GREATER', async function () {
+ it('should NOT agree when input is NOT GREATER', function () {
const strategyConfig = givenStrategyConfig(OperationsType.GREATER, mock_values1);
- const result = await processOperation(strategyConfig, '06:00');
+ const result = processOperation(strategyConfig, '06:00');
assertFalse(result);
});
- it('should agree when input is in BETWEEN', async function () {
+ it('should agree when input is in BETWEEN', function () {
const strategyConfig = givenStrategyConfig(OperationsType.BETWEEN, mock_values2);
- const result = await processOperation(strategyConfig, '09:00');
+ const result = processOperation(strategyConfig, '09:00');
assertTrue(result);
});
- it('should NOT agree when input is NOT in BETWEEN', async function () {
+ it('should NOT agree when input is NOT in BETWEEN', function () {
const strategyConfig = givenStrategyConfig(OperationsType.BETWEEN, mock_values2);
- const result = await processOperation(strategyConfig, '07:00');
+ const result = processOperation(strategyConfig, '07:00');
assertFalse(result);
});
diff --git a/tests/strategy-operations/value.test.ts b/tests/strategy-operations/value.test.ts
index 77d2c9e..5e98d12 100644
--- a/tests/strategy-operations/value.test.ts
+++ b/tests/strategy-operations/value.test.ts
@@ -23,45 +23,45 @@ describe('Strategy [VALUE] tests:', function () {
activated: true,
});
- it('should agree when input EXIST', async function () {
+ it('should agree when input EXIST', function () {
const strategyConfig = givenStrategyConfig(OperationsType.EXIST, mock_values1);
- const result = await processOperation(strategyConfig, 'USER_1');
+ const result = processOperation(strategyConfig, 'USER_1');
assertTrue(result);
});
- it('should NOT agree when input DOES NOT EXIST', async function () {
+ it('should NOT agree when input DOES NOT EXIST', function () {
const strategyConfig = givenStrategyConfig(OperationsType.EXIST, mock_values1);
- const result = await processOperation(strategyConfig, 'USER_123');
+ const result = processOperation(strategyConfig, 'USER_123');
assertFalse(result);
});
- it('should agree when input DOES NOT EXIST', async function () {
+ it('should agree when input DOES NOT EXIST', function () {
const strategyConfig = givenStrategyConfig(OperationsType.NOT_EXIST, mock_values1);
- const result = await processOperation(strategyConfig, 'USER_123');
+ const result = processOperation(strategyConfig, 'USER_123');
assertTrue(result);
});
- it('should agree when input is EQUAL', async function () {
+ it('should agree when input is EQUAL', function () {
const strategyConfig = givenStrategyConfig(OperationsType.EQUAL, mock_values1);
- const result = await processOperation(strategyConfig, 'USER_1');
+ const result = processOperation(strategyConfig, 'USER_1');
assertTrue(result);
});
- it('should NOT agree when input is NOT EQUAL', async function () {
+ it('should NOT agree when input is NOT EQUAL', function () {
const strategyConfig = givenStrategyConfig(OperationsType.EQUAL, mock_values1);
- const result = await processOperation(strategyConfig, 'USER_2');
+ const result = processOperation(strategyConfig, 'USER_2');
assertFalse(result);
});
- it('should agree when input is NOT EQUAL', async function () {
+ it('should agree when input is NOT EQUAL', function () {
const strategyConfig = givenStrategyConfig(OperationsType.NOT_EQUAL, mock_values2);
- const result = await processOperation(strategyConfig, 'USER_123');
+ const result = processOperation(strategyConfig, 'USER_123');
assertTrue(result);
});
- it('should NOT agree when input is NOT EQUAL', async function () {
+ it('should NOT agree when input is NOT EQUAL', function () {
const strategyConfig = givenStrategyConfig(OperationsType.NOT_EQUAL, mock_values2);
- const result = await processOperation(strategyConfig, 'USER_2');
+ const result = processOperation(strategyConfig, 'USER_2');
assertFalse(result);
});
diff --git a/tests/switcher-functional.test.ts b/tests/switcher-functional.test.ts
index 6812b52..2ca1ba9 100644
--- a/tests/switcher-functional.test.ts
+++ b/tests/switcher-functional.test.ts
@@ -364,7 +364,7 @@ describe('Integrated test - Client:', function () {
.checkNetwork('192.168.0.1')
.checkDate('2019-12-01T08:30')
.checkTime('08:00')
- .checkRegex('\\bUSER_[0-9]{1,2}\\b')
+ .checkRegex(String.raw`\bUSER_[0-9]{1,2}\b`)
.checkPayload(JSON.stringify({ name: 'User 1' }))
.prepare('SWITCHER_MULTIPLE_INPUT');
@@ -374,7 +374,7 @@ describe('Integrated test - Client:', function () {
[ 'NETWORK_VALIDATION', '192.168.0.1' ],
[ 'DATE_VALIDATION', '2019-12-01T08:30' ],
[ 'TIME_VALIDATION', '08:00' ],
- [ 'REGEX_VALIDATION', '\\bUSER_[0-9]{1,2}\\b' ],
+ [ 'REGEX_VALIDATION', String.raw`\bUSER_[0-9]{1,2}\b` ],
[ 'PAYLOAD_VALIDATION', '{"name":"User 1"}' ]
]);