From 896ffc61454159d35bcd02dc0ae340b885bd6a0a Mon Sep 17 00:00:00 2001 From: Pelle Wessman Date: Sat, 26 Aug 2023 14:00:08 +0200 Subject: [PATCH] Test option compatibility with simple-oauth2 This is an alternative to #225 where rather than using `@types/simple-oauth2` in the published types we ensure at test time that the local types are indeed compatible with the published types of `@types/simple-oauth2`. That way a consumer that wants to have access to the full types of `simple-oauth2` can add `@types/simple-oauth2` in their own project, knowing that it will be compatible --- package.json | 1 + types/index.test-d.ts | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/package.json b/package.json index 0f6a964..ef8bc29 100644 --- a/package.json +++ b/package.json @@ -29,6 +29,7 @@ "devDependencies": { "@fastify/pre-commit": "^2.0.2", "@types/node": "^20.5.3", + "@types/simple-oauth2": "^5.0.4", "fastify": "^4.21.0", "nock": "^13.3.3", "simple-get": "^4.0.1", diff --git a/types/index.test-d.ts b/types/index.test-d.ts index 8a2d4bb..5e7c1ba 100644 --- a/types/index.test-d.ts +++ b/types/index.test-d.ts @@ -7,6 +7,7 @@ import fastifyOauth2, { OAuth2Token, ProviderConfiguration } from '..'; +import type { ModuleOptions } from 'simple-oauth2'; /** * Preparing some data for testing. @@ -22,6 +23,14 @@ const credentials: Credentials = { auth: auth, }; +const simpleOauth2Options: ModuleOptions = { + client: { + id: 'test_id', + secret: 'test_secret', + }, + auth: auth, +}; + const OAuth2NoneOptional: FastifyOAuth2Options = { name: 'testOAuthName', credentials: credentials, @@ -84,6 +93,13 @@ expectType(scope); expectType(tags); expectType(credentials); +// Ensure duplicayed simple-oauth2 are compatible with simple-oauth2 +expectAssignable>(credentials); +expectAssignable(auth); +// Ensure published types of simple-oauth2 are accepted +expectAssignable(simpleOauth2Options); +expectAssignable(simpleOauth2Options.auth); + expectError(fastifyOauth2()); // error because missing required arguments expectError(fastifyOauth2(server, {}, () => { })); // error because missing required options