|
| 1 | +/* |
| 2 | + * Copyright (c) 2025 Ping Identity Corporation. All rights reserved. |
| 3 | + * |
| 4 | + * This software may be modified and distributed under the terms |
| 5 | + * of the MIT license. See the LICENSE file for details. |
| 6 | + */ |
| 7 | +import { describe, expectTypeOf, it } from 'vitest'; |
| 8 | +import type { |
| 9 | + JourneyClientConfig, |
| 10 | + JourneyServerConfig, |
| 11 | + InternalJourneyClientConfig, |
| 12 | +} from './config.types.js'; |
| 13 | +import type { AsyncLegacyConfigOptions } from '@forgerock/sdk-types'; |
| 14 | +import type { ResolvedServerConfig } from './wellknown.utils.js'; |
| 15 | + |
| 16 | +describe('Config Types', () => { |
| 17 | + describe('JourneyClientConfig', () => { |
| 18 | + it('should extend AsyncLegacyConfigOptions', () => { |
| 19 | + expectTypeOf<JourneyClientConfig>().toMatchTypeOf<AsyncLegacyConfigOptions>(); |
| 20 | + }); |
| 21 | + |
| 22 | + it('should narrow serverConfig to JourneyServerConfig', () => { |
| 23 | + expectTypeOf<JourneyClientConfig['serverConfig']>().toMatchTypeOf<JourneyServerConfig>(); |
| 24 | + expectTypeOf<JourneyClientConfig['serverConfig']['wellknown']>().toBeString(); |
| 25 | + }); |
| 26 | + |
| 27 | + it('should reject config without wellknown', () => { |
| 28 | + // @ts-expect-error - wellknown is required on serverConfig |
| 29 | + const config: JourneyClientConfig = { serverConfig: {} }; |
| 30 | + expectTypeOf(config).toMatchTypeOf<JourneyClientConfig>(); |
| 31 | + }); |
| 32 | + |
| 33 | + it('should allow AsyncLegacyConfigOptions properties', () => { |
| 34 | + const config: JourneyClientConfig = { |
| 35 | + clientId: 'test-client', |
| 36 | + scope: 'openid profile', |
| 37 | + redirectUri: 'https://app.example.com/callback', |
| 38 | + serverConfig: { |
| 39 | + wellknown: 'https://am.example.com/am/oauth2/alpha/.well-known/openid-configuration', |
| 40 | + timeout: 30000, |
| 41 | + }, |
| 42 | + }; |
| 43 | + expectTypeOf(config).toMatchTypeOf<JourneyClientConfig>(); |
| 44 | + }); |
| 45 | + |
| 46 | + it('should not require inherited properties like clientId', () => { |
| 47 | + const config: JourneyClientConfig = { |
| 48 | + serverConfig: { |
| 49 | + wellknown: 'https://am.example.com/am/oauth2/alpha/.well-known/openid-configuration', |
| 50 | + }, |
| 51 | + }; |
| 52 | + expectTypeOf(config).toMatchTypeOf<JourneyClientConfig>(); |
| 53 | + }); |
| 54 | + |
| 55 | + it('should have optional timeout on serverConfig', () => { |
| 56 | + expectTypeOf<JourneyClientConfig['serverConfig']>().toHaveProperty('timeout'); |
| 57 | + }); |
| 58 | + }); |
| 59 | + |
| 60 | + describe('InternalJourneyClientConfig', () => { |
| 61 | + it('should have ResolvedServerConfig', () => { |
| 62 | + expectTypeOf<InternalJourneyClientConfig>() |
| 63 | + .toHaveProperty('serverConfig') |
| 64 | + .toMatchTypeOf<ResolvedServerConfig>(); |
| 65 | + }); |
| 66 | + |
| 67 | + it('should have optional error', () => { |
| 68 | + expectTypeOf<InternalJourneyClientConfig>().toHaveProperty('error').toBeNullable(); |
| 69 | + }); |
| 70 | + }); |
| 71 | +}); |
0 commit comments