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
2 changes: 1 addition & 1 deletion .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM denoland/deno:2.6.4
FROM denoland/deno:2.7.7

# Install tools
RUN apt-get update && \
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/master.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ jobs:
with:
fetch-depth: 0

- name: Setup Deno v2.6.4
- name: Setup Deno v2.7.7
uses: denoland/setup-deno@v2
with:
deno-version: v2.6.4
deno-version: v2.7.7

- name: Setup LCOV
run: sudo apt install -y lcov
Expand All @@ -45,7 +45,7 @@ jobs:
strategy:
fail-fast: false
matrix:
deno-version: [v1.46.3, v2.6.4]
deno-version: [v1.46.3, v2.7.7]
os: [ ubuntu-latest, windows-latest ]
runs-on: ${{ matrix.os }}

Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/sonar.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ jobs:
ref: ${{ steps.pr.outputs.head_sha }}
fetch-depth: 0

- name: Setup Deno v2.6.4
- name: Setup Deno v2.7.7
uses: denoland/setup-deno@v2
with:
deno-version: v2.6.4
deno-version: v2.7.7

- name: Setup LCOV
run: sudo apt install -y lcov
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ A Deno SDK for Switcher API
```bash
--allow-read --allow-write --allow-net
```
(*) add `--unstable-http` when using Deno v1.4x with custom certificates

### Installation

Expand Down
4 changes: 2 additions & 2 deletions deno.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
"cache-reload": "deno cache --reload --lock=deno.lock mod.ts",
"fmt": "deno fmt mod.ts src/ --options-single-quote --options-line-width=120 --check",
"fmt:fix": "deno fmt mod.ts src/ --options-single-quote --options-line-width=120",
"test": "deno test --allow-read --allow-net --allow-write --allow-import --coverage=coverage",
"test-v1": "deno test --allow-read --allow-net --allow-write --coverage=coverage",
"test": "deno test --allow-read --allow-net --allow-write --allow-env --allow-import --coverage=coverage",
"test-v1": "deno test --allow-read --allow-net --allow-write --allow-env --unstable-http --coverage=coverage",
"clean": "rm -rf ./npm ./coverage ./generated-snapshots",
"lcov": "deno coverage coverage --lcov --output=coverage/report.lcov",
"cover": "deno task clean && deno task test && deno task lcov && genhtml -o coverage/html coverage/report.lcov",
Expand Down
6 changes: 3 additions & 3 deletions deno.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/deps.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { existsSync } from 'jsr:@std/fs@1.0.21';
export { existsSync } from 'jsr:@std/fs@1.0.23';
6 changes: 6 additions & 0 deletions src/lib/remote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ export const setCerts = (certPath: string) => {
});
};

export const destroyHttpClient = () => {
if (httpClient) {
httpClient.close();
}
};

export const getEntry = (input?: string[][]) => {
if (!input) {
return undefined;
Expand Down
8 changes: 4 additions & 4 deletions tests/deps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@ export {
assertArrayIncludes,
assertStrictEquals,
assertNotStrictEquals
} from 'jsr:@std/assert@1.0.16';
export { assertSpyCalls, spy } from 'jsr:@std/testing@1.0.16/mock';
} from 'jsr:@std/assert@1.0.19';
export { assertSpyCalls, spy } from 'jsr:@std/testing@1.0.17/mock';
export {
describe,
it,
afterAll,
beforeEach,
beforeAll,
afterEach
} from 'jsr:@std/testing@1.0.16/bdd';
export { delay } from 'jsr:@std/async@1.0.16/delay';
} from 'jsr:@std/testing@1.0.17/bdd';
export { delay } from 'jsr:@std/async@1.2.0/delay';
export { load } from 'jsr:@std/dotenv@0.225.6';
export * as mf from 'https://deno.land/x/mock_fetch@0.3.0/mod.ts';
29 changes: 29 additions & 0 deletions tests/helper/dummy-cert.pem
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
-----BEGIN CERTIFICATE-----
MIIFBTCCAu2gAwIBAgIQWgDyEtjUtIDzkkFX6imDBTANBgkqhkiG9w0BAQsFADBP
MQswCQYDVQQGEwJVUzEpMCcGA1UEChMgSW50ZXJuZXQgU2VjdXJpdHkgUmVzZWFy
Y2ggR3JvdXAxFTATBgNVBAMTDElTUkcgUm9vdCBYMTAeFw0yNDAzMTMwMDAwMDBa
Fw0yNzAzMTIyMzU5NTlaMDMxCzAJBgNVBAYTAlVTMRYwFAYDVQQKEw1MZXQncyBF
bmNyeXB0MQwwCgYDVQQDEwNSMTMwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEK
AoIBAQClZ3CN0FaBZBUXYc25BtStGZCMJlA3mBZjklTb2cyEBZPs0+wIG6BgUUNI
fSvHSJaetC3ancgnO1ehn6vw1g7UDjDKb5ux0daknTI+WE41b0VYaHEX/D7YXYKg
L7JRbLAaXbhZzjVlyIuhrxA3/+OcXcJJFzT/jCuLjfC8cSyTDB0FxLrHzarJXnzR
yQH3nAP2/Apd9Np75tt2QnDr9E0i2gB3b9bJXxf92nUupVcM9upctuBzpWjPoXTi
dYJ+EJ/B9aLrAek4sQpEzNPCifVJNYIKNLMc6YjCR06CDgo28EdPivEpBHXazeGa
XP9enZiVuppD0EqiFwUBBDDTMrOPAgMBAAGjgfgwgfUwDgYDVR0PAQH/BAQDAgGG
MB0GA1UdJQQWMBQGCCsGAQUFBwMCBggrBgEFBQcDATASBgNVHRMBAf8ECDAGAQH/
AgEAMB0GA1UdDgQWBBTnq58PLDOgU9NeT3jIsoQOO9aSMzAfBgNVHSMEGDAWgBR5
tFnme7bl5AFzgAiIyBpY9umbbjAyBggrBgEFBQcBAQQmMCQwIgYIKwYBBQUHMAKG
Fmh0dHA6Ly94MS5pLmxlbmNyLm9yZy8wEwYDVR0gBAwwCjAIBgZngQwBAgEwJwYD
VR0fBCAwHjAcoBqgGIYWaHR0cDovL3gxLmMubGVuY3Iub3JnLzANBgkqhkiG9w0B
AQsFAAOCAgEAUTdYUqEimzW7TbrOypLqCfL7VOwYf/Q79OH5cHLCZeggfQhDconl
k7Kgh8b0vi+/XuWu7CN8n/UPeg1vo3G+taXirrytthQinAHGwc/UdbOygJa9zuBc
VyqoH3CXTXDInT+8a+c3aEVMJ2St+pSn4ed+WkDp8ijsijvEyFwE47hulW0Ltzjg
9fOV5Pmrg/zxWbRuL+k0DBDHEJennCsAen7c35Pmx7jpmJ/HtgRhcnz0yjSBvyIw
6L1QIupkCv2SBODT/xDD3gfQQyKv6roV4G2EhfEyAsWpmojxjCUCGiyg97FvDtm/
NK2LSc9lybKxB73I2+P2G3CaWpvvpAiHCVu30jW8GCxKdfhsXtnIy2imskQqVZ2m
0Pmxobb28Tucr7xBK7CtwvPrb79os7u2XP3O5f9b/H66GNyRrglRXlrYjI1oGYL/
f4I1n/Sgusda6WvA6C190kxjU15Y12mHU4+BxyR9cx2hhGS9fAjMZKJss28qxvz6
Axu4CaDmRNZpK/pQrXF17yXCXkmEWgvSOEZy6Z9pcbLIVEGckV/iVeq0AOo2pkg9
p4QRIy0tK2diRENLSF2KysFwbY6B26BFeFs3v1sYVRhFW9nLkOrQVporCS0KyZmf
wVD89qSTlnctLcZnIavjKsKUu1nA1iU0yYMdYepKR7lWbnwhdx3ewok=
-----END CERTIFICATE-----
123 changes: 123 additions & 0 deletions tests/switcher-context.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
import { describe, it, beforeEach, assertRejects, assertThrows } from './deps.ts';
import { given, tearDown, generateAuth, assertTrue } from './helper/utils.ts'

import { Client, type SwitcherContext } from '../mod.ts';
import { destroyHttpClient } from "../src/lib/remote.ts";

describe('Switcher Context:', function () {
let contextSettings: SwitcherContext;

beforeEach(function() {
tearDown();

contextSettings = {
url: 'http://localhost:3000',
apiKey: '[apiKey]',
domain: '[domain]',
component: '[component]',
environment: 'default'
};
});

it('should throw when certPath is invalid', function() {
assertThrows(() => Client.buildContext(contextSettings, { certPath: 'invalid' }));
});

it('should NOT throw when certPath is valid', function() {
Client.buildContext(contextSettings, { certPath: './tests/helper/dummy-cert.pem' });
destroyHttpClient();
assertTrue(true);
});

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

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

const switcher = Client.getSwitcher();

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

it('should be invalid - Missing API Key field', async function () {
// given
given('POST@/criteria/auth', generateAuth('[auth_token]', 5));

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

const switcher = Client.getSwitcher();

await switcher
.checkValue('User 1')
.checkNetwork('192.168.0.1')
.prepare('MY_FLAG');

await assertRejects(async () =>
await switcher.isItOn(),
Error, 'Something went wrong: API Key is required');
});

it('should be invalid - Missing key field', async function () {
// given
given('POST@/criteria/auth', generateAuth('[auth_token]', 5));

// test
Client.buildContext(contextSettings);
const switcher = Client.getSwitcher();

await assertRejects(async () =>
await switcher.isItOn(),
Error, 'Something went wrong: Missing key field');
});

it('should be invalid - Missing component field', async function () {
// given
given('POST@/criteria/auth', generateAuth('[auth_token]', 5));

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

const switcher = Client.getSwitcher();

await assertRejects(async () =>
await switcher.isItOn('MY_FLAG'),
Error, 'Something went wrong: Component is required');
});

it('should be invalid - Missing token field', async function () {
// given
given('POST@/criteria/auth', generateAuth(undefined, 5));

// test
Client.buildContext(contextSettings);
const switcher = Client.getSwitcher();

await assertRejects(async () =>
await switcher.isItOn('MY_FLAG'),
Error, 'Something went wrong: Missing token field');
});

});
Loading
Loading