Skip to content

Commit 75c17e5

Browse files
authored
Test option compatibility with simple-oauth2 (#229)
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
1 parent 6d3f637 commit 75c17e5

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
"devDependencies": {
3030
"@fastify/pre-commit": "^2.0.2",
3131
"@types/node": "^20.5.3",
32+
"@types/simple-oauth2": "^5.0.4",
3233
"fastify": "^4.21.0",
3334
"nock": "^13.3.3",
3435
"simple-get": "^4.0.1",

types/index.test-d.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import fastifyOauth2, {
77
OAuth2Token,
88
ProviderConfiguration
99
} from '..';
10+
import type { ModuleOptions } from 'simple-oauth2';
1011

1112
/**
1213
* Preparing some data for testing.
@@ -22,6 +23,14 @@ const credentials: Credentials = {
2223
auth: auth,
2324
};
2425

26+
const simpleOauth2Options: ModuleOptions = {
27+
client: {
28+
id: 'test_id',
29+
secret: 'test_secret',
30+
},
31+
auth: auth,
32+
};
33+
2534
const OAuth2NoneOptional: FastifyOAuth2Options = {
2635
name: 'testOAuthName',
2736
credentials: credentials,
@@ -84,6 +93,13 @@ expectType<string[]>(scope);
8493
expectType<string[]>(tags);
8594
expectType<Credentials>(credentials);
8695

96+
// Ensure duplicayed simple-oauth2 are compatible with simple-oauth2
97+
expectAssignable<ModuleOptions<string>>(credentials);
98+
expectAssignable<ModuleOptions["auth"]>(auth);
99+
// Ensure published types of simple-oauth2 are accepted
100+
expectAssignable<Credentials>(simpleOauth2Options);
101+
expectAssignable<ProviderConfiguration>(simpleOauth2Options.auth);
102+
87103
expectError(fastifyOauth2()); // error because missing required arguments
88104
expectError(fastifyOauth2(server, {}, () => {
89105
})); // error because missing required options

0 commit comments

Comments
 (0)