Skip to content

Commit

Permalink
SW tests, tweaks (#8)
Browse files Browse the repository at this point in the history
* Fix PKCE tests

* Fix the storage tests

* Fix the login tests

* Refactor tests setup, utils/operations

* Fix postMessage tests

* Fix register tests

* Fix fetch and interceptor

* Fix remaining tests, refactor state persistance

* Add some missing tests

* Streamline the idb layer

* Add missing state tests

* Add interceptor tests

* Fix some code smells

* Resolve deprecation warnings
  • Loading branch information
DarkoKukovec authored Jun 20, 2023
1 parent 101526c commit 61eba68
Show file tree
Hide file tree
Showing 29 changed files with 807 additions and 360 deletions.
4 changes: 2 additions & 2 deletions example/workers/service-worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ addEventListener('activate', (event) => {
initAuthServiceWorker(
{ google, facebook, twitter, reddit, auth0: auth0('dev-u8csbbr8zashh2k8.us.auth0.com') },
'/auth',
['https://www.googleapis.com/oauth2/v3/userinfo'],
'foobartest'
['https://www.googleapis.com/oauth2/v3/userinfo']
// 'foobartest'
);
192 changes: 190 additions & 2 deletions package-lock.json

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

8 changes: 7 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "auth-worker",
"version": "2.0.0-beta.5",
"version": "2.0.0-beta.6",
"description": "OAuth2 Service Worker handler",
"main": "index.js",
"module": "index.mjs",
Expand All @@ -23,9 +23,11 @@
"homepage": "https://github.com/infinum/auth-worker#readme",
"devDependencies": {
"@infinumjs/eslint-config-core-ts": "^3.3.1",
"@peculiar/webcrypto": "^1.4.3",
"@types/jest": "^29.5.1",
"@typescript-eslint/parser": "^5.59.2",
"eslint": "^8.39.0",
"fake-indexeddb": "^4.0.1",
"jest": "^29.5.0",
"jest-environment-jsdom": "^29.5.0",
"lint-staged": "^13.2.2",
Expand All @@ -49,6 +51,10 @@
"ts",
"js"
],
"testEnvironment": "jest-environment-jsdom",
"setupFilesAfterEnv": [
"./test/setup.ts"
],
"testRegex": "src/(.*).test.ts$",
"preset": "ts-jest",
"testMatch": null
Expand Down
42 changes: 42 additions & 0 deletions src/shared/db.mock.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
let secret: string | null = null;
const data = new Map<string, string>();

export const SECURE_KEY = 'auth-worker-state';

export function setSecret(secretPhrase: string | undefined) {
secret = secretPhrase ?? null;
}

export function isPersistable(): boolean {
return Boolean(secret);
}

export function setMockData(key: string, value: string): void;
export function setMockData(value: string): void;
export function setMockData(key: string, value?: string) {
if (value === undefined) {
data.set(SECURE_KEY, key);
} else {
data.set(key, value);
}
}

export function clearMockData() {
data.clear();
}

export async function getData(key: string): Promise<string | null> {
return data.get(key) ?? null;
}

export async function saveData(key: string, value: string) {
data.set(key, value);
}

export async function deleteData(keys: Array<string>): Promise<void> {
keys.forEach((key) => data.delete(key));
}

export async function getKeys(): Promise<Array<string>> {
return Array.from(data.keys());
}
Loading

0 comments on commit 61eba68

Please sign in to comment.