diff --git a/.github/workflows/master.yml b/.github/workflows/master.yml index 76ec07c..815e0d9 100644 --- a/.github/workflows/master.yml +++ b/.github/workflows/master.yml @@ -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 diff --git a/README.md b/README.md index b9d805e..f08a1b5 100644 --- a/README.md +++ b/README.md @@ -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: @@ -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(); diff --git a/src/switcher-client.ts b/src/switcher-client.ts index 6a6b9f0..ef1292c 100644 --- a/src/switcher-client.ts +++ b/src/switcher-client.ts @@ -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'; @@ -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 = {}; diff --git a/test/playground/index.ts b/test/playground/index.ts index f9eb226..2539276 100644 --- a/test/playground/index.ts +++ b/test/playground/index.ts @@ -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; diff --git a/test/switcher-integrated.test.ts b/test/switcher-integrated.test.ts index 843e45a..d15d824 100644 --- a/test/switcher-integrated.test.ts +++ b/test/switcher-integrated.test.ts @@ -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);