Skip to content
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions .github/workflows/master.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ jobs:
with:
fetch-depth: 0

- name: Setup Deno v1.22.1
- name: Setup Deno v1.25.2
uses: denoland/setup-deno@v1
with:
deno-version: v1.22.1
deno-version: v1.25.2

- name: Verify formatting
run: deno fmt mod.ts src/ --options-single-quote --options-line-width=120 --check
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,20 @@ https://github.com/switcherapi/switcher-api
The context properties stores all information regarding connectivity.

```ts
import { Switcher } from "https://deno.land/x/switcher4deno@v1.0.0/mod.ts";
import { Switcher } from "https://deno.land/x/switcher4deno@v1.0.1/mod.ts";

const url = 'https://switcherapi.com/api';
const apiKey = '[API_KEY]';
const environment = 'default';
const domain = 'My Domain';
const component = 'MyApp';
const url = 'https://switcher-api.herokuapp.com';
```

- **url**: Swither-API url.
- **apiKey**: Switcher-API key generated to your component.
- **environment**: (optional) Environment name. Production environment is named as 'default'.
- **domain**: Domain name.
- **component**: Application name.
- **url**: (optional) Swither-API endpoint.

## Options
You can also activate features such as offline and silent mode:
Expand Down Expand Up @@ -97,7 +97,7 @@ switcher.isItOn('KEY')
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.

```ts
import { checkValue, checkNetwork } from "https://deno.land/x/switcher4deno@v1.0.0/mod.ts";
import { checkValue, checkNetwork } from "https://deno.land/x/switcher4deno@v1.0.1/mod.ts";

switcher.prepare('FEATURE01', [checkValue('USER_1')];
switcher.isItOn();
Expand Down
3 changes: 1 addition & 2 deletions src/switcher-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { checkSwitchers, loadDomain, validateSnapshot } from './lib/snapshot.ts'
import * as services from './lib/remote.ts';
import checkCriteriaOffline from './lib/resolver.ts';

const DEFAULT_URL = 'https://switcher-api.herokuapp.com';
const DEFAULT_ENVIRONMENT = 'default';
const DEFAULT_SNAPSHOT_LOCATION = './snapshot/';
const DEFAULT_RETRY_TIME = '5m';
Expand Down Expand Up @@ -47,8 +46,8 @@ export class Switcher {
this._snapshot = undefined;
this._context = {};
this._context = context;
this._context.url = context.url;
this._context.environment = context.environment || DEFAULT_ENVIRONMENT;
this._context.url = context.url || DEFAULT_URL;

// Default values
this._options = {};
Expand Down
2 changes: 1 addition & 1 deletion test/playground/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const apiKey = 'JDJiJDA4JEFweTZjSTR2bE9pUjNJOUYvRy9raC4vRS80Q2tzUnk1d3o1aXFmS2o5
const domain = 'Playground';
const component = 'switcher-playground';
const environment = 'default';
const url = 'https://switcher-api.herokuapp.com';
const url = 'https://switcherapi.com/api';

let switcher;

Expand Down
21 changes: 21 additions & 0 deletions test/switcher-integrated.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,27 @@ describe('Integrated test - Switcher:', function () {
]));
});

it('Should be invalid - Missing API url field', async function () {
// given
given('GET@/check', null);
given('POST@/criteria/auth', generateAuth('[auth_token]', 5));

// test
Switcher.buildContext({
url: undefined,
apiKey: '[apiKey]',
domain: '[domain]',
component: '[component]',
environment: 'default'
});

const switcher = Switcher.factory();

await assertRejects(async () =>
await switcher.isItOn(),
Error, 'Something went wrong: Invalid URL');
});

it('Should be invalid - Missing API Key field', async function () {
// given
given('GET@/check', null);
Expand Down