From 9d16d54af09d7bfa3fe244ec31f5c6e485fffb7b Mon Sep 17 00:00:00 2001 From: Nicolas Morel Date: Mon, 13 Mar 2023 18:57:52 +0100 Subject: [PATCH] chore: add typings basic test --- package.json | 32 +++++++++++++++++--------------- test/index.ts | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+), 15 deletions(-) create mode 100644 test/index.ts diff --git a/package.json b/package.json index e2c88f5..e851211 100644 --- a/package.json +++ b/package.json @@ -20,27 +20,29 @@ ] }, "dependencies": { - "@hapi/b64": "^6.0.0", - "@hapi/boom": "^10.0.0", - "@hapi/bounce": "^3.0.0", + "@hapi/b64": "^6.0.1", + "@hapi/boom": "^10.0.1", + "@hapi/bounce": "^3.0.1", "@hapi/bourne": "^3.0.0", - "@hapi/catbox-object": "^3.0.0", - "@hapi/cryptiles": "^6.0.0", - "@hapi/hoek": "^10.0.0", - "@hapi/wreck": "^18.0.0", - "ecdsa-sig-formatter": "^1.0.0", - "joi": "^17.2.1" + "@hapi/catbox-object": "^3.0.1", + "@hapi/cryptiles": "^6.0.1", + "@hapi/hoek": "^11.0.2", + "@hapi/wreck": "^18.0.1", + "ecdsa-sig-formatter": "^1.0.11", + "joi": "^17.8.3" }, "devDependencies": { - "@hapi/code": "^9.0.0", + "@hapi/code": "^9.0.3", "@hapi/eslint-plugin": "^6.0.0", - "@hapi/hapi": "^21.0.0", - "@hapi/lab": "^25.0.1", - "node-forge": "^1.0.0", - "node-rsa": "^1.0.0" + "@hapi/hapi": "^21.3.0", + "@hapi/lab": "^25.1.2", + "@types/node": "^14.18.37", + "node-forge": "^1.3.1", + "node-rsa": "^1.1.1", + "typescript": "^4.9.5" }, "scripts": { - "test": "lab -a @hapi/code -t 100 -L -m 10000", + "test": "lab -a @hapi/code -t 100 -L -m 10000 -Y", "test-cov-html": "lab -a @hapi/code -r html -o coverage.html" }, "license": "BSD-3-Clause" diff --git a/test/index.ts b/test/index.ts new file mode 100644 index 0000000..676e4a5 --- /dev/null +++ b/test/index.ts @@ -0,0 +1,35 @@ +import { Server } from '@hapi/hapi'; +import { types } from '@hapi/lab'; +import HapiJwt from '..'; + +async function test() { + const server = new Server(); + + await server.register(HapiJwt); + + server.auth.strategy('my-strategy', 'jwt', { + keys: '', + verify: true, + validate: true, + }); + + types.expect.type( + HapiJwt.token.generate({}, '', { + encoding: 'utf-8', + header: { 'x-custom': 'value' }, + headless: false, + iat: true, + now: 123, + typ: true, + ttlSec: 456, + }) + ); + + types.expect.type<{ token: string }>( + HapiJwt.token.decode('', { headless: true }) + ); + + types.expect.type( + HapiJwt.token.verify(HapiJwt.token.decode(''), '') + ); +}