Skip to content

Commit

Permalink
add tests for options in readme
Browse files Browse the repository at this point in the history
  • Loading branch information
KirillTregubov committed Nov 6, 2023
1 parent bf769d8 commit 233bafd
Showing 1 changed file with 37 additions and 1 deletion.
38 changes: 37 additions & 1 deletion types/jwt.test-d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import fastify from 'fastify';
import fastifyJwt, { FastifyJWTOptions, FastifyJwtNamespace, JWT } from '..'
import fastifyJwt, { FastifyJWTOptions, FastifyJwtNamespace, JWT, SignOptions, VerifyOptions } from '..'
import { expectAssignable, expectType } from 'tsd'

const app = fastify();
Expand Down Expand Up @@ -166,3 +166,39 @@ expectType<JWT['verify']>(({} as FastifyJwtNamespace<{ namespace: 'security', jw
expectType<JWT['decode']>(({} as FastifyJwtNamespace<{ jwtDecode: 'decode'}>).decode)
expectType<JWT['sign']>(({} as FastifyJwtNamespace<{ jwtSign: 'sign'}>).sign)
expectType<JWT['verify']>(({} as FastifyJwtNamespace<{ jwtVerify: 'verify'}>).verify)

let signOptions: SignOptions = {
key: "supersecret",
algorithm: "HS256",
mutatePayload: true,
expiresIn: 3600,
notBefore: 0,
}

signOptions = {
key: Buffer.from("supersecret", "utf-8"),
algorithm: "HS256",
mutatePayload: true,
expiresIn: 3600,
notBefore: 0,
}

let verifyOptions: VerifyOptions = {
key: "supersecret",
algorithms: ["HS256"],
complete: true,
cache: true,
cacheTTL: 3600,
maxAge: "1 hour",
onlyCookie: false,
}

verifyOptions = {
key: Buffer.from("supersecret", "utf-8"),
algorithms: ["HS256"],
complete: true,
cache: 3600,
cacheTTL: 3600,
maxAge: 3600,
onlyCookie: true,
}

0 comments on commit 233bafd

Please sign in to comment.