|
| 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 | + ReadOnlyCollectorBase, |
| 10 | + ReadOnlyCollector, |
| 11 | + RichContentLink, |
| 12 | + ValidatedReplacement, |
| 13 | + CollectorRichContent, |
| 14 | + ValidateReplacementsResult, |
| 15 | + NoValueCollector, |
| 16 | +} from './collector.types.js'; |
| 17 | + |
| 18 | +describe('Rich Content Types', () => { |
| 19 | + describe('RichContentLink', () => { |
| 20 | + it('should require key, type, value, and href', () => { |
| 21 | + expectTypeOf<RichContentLink>().toHaveProperty('key').toBeString(); |
| 22 | + expectTypeOf<RichContentLink>().toHaveProperty('type').toEqualTypeOf<'link'>(); |
| 23 | + expectTypeOf<RichContentLink>().toHaveProperty('value').toBeString(); |
| 24 | + expectTypeOf<RichContentLink>().toHaveProperty('href').toBeString(); |
| 25 | + }); |
| 26 | + |
| 27 | + it('should have optional target constrained to _self or _blank', () => { |
| 28 | + expectTypeOf<RichContentLink>() |
| 29 | + .toHaveProperty('target') |
| 30 | + .toEqualTypeOf<'_self' | '_blank' | undefined>(); |
| 31 | + }); |
| 32 | + }); |
| 33 | + |
| 34 | + describe('ValidatedReplacement', () => { |
| 35 | + it('should be assignable from RichContentLink', () => { |
| 36 | + expectTypeOf<RichContentLink>().toMatchTypeOf<ValidatedReplacement>(); |
| 37 | + }); |
| 38 | + |
| 39 | + it('should be assignable to RichContentLink', () => { |
| 40 | + expectTypeOf<ValidatedReplacement>().toMatchTypeOf<RichContentLink>(); |
| 41 | + }); |
| 42 | + }); |
| 43 | + |
| 44 | + describe('CollectorRichContent', () => { |
| 45 | + it('should have required content string and replacements array', () => { |
| 46 | + expectTypeOf<CollectorRichContent>().toHaveProperty('content').toBeString(); |
| 47 | + expectTypeOf<CollectorRichContent>() |
| 48 | + .toHaveProperty('replacements') |
| 49 | + .toEqualTypeOf<ValidatedReplacement[]>(); |
| 50 | + }); |
| 51 | + }); |
| 52 | + |
| 53 | + describe('ValidateReplacementsResult', () => { |
| 54 | + it('should narrow to replacements on ok: true', () => { |
| 55 | + const result = {} as ValidateReplacementsResult; |
| 56 | + if (result.ok) { |
| 57 | + expectTypeOf(result.replacements).toEqualTypeOf<ValidatedReplacement[]>(); |
| 58 | + } |
| 59 | + }); |
| 60 | + |
| 61 | + it('should narrow to error on ok: false', () => { |
| 62 | + const result = {} as ValidateReplacementsResult; |
| 63 | + if (!result.ok) { |
| 64 | + expectTypeOf(result.error).toBeString(); |
| 65 | + } |
| 66 | + }); |
| 67 | + }); |
| 68 | + |
| 69 | + describe('ReadOnlyCollectorBase', () => { |
| 70 | + it('should have content as string, not array', () => { |
| 71 | + expectTypeOf<ReadOnlyCollectorBase['output']['content']>().toBeString(); |
| 72 | + }); |
| 73 | + |
| 74 | + it('should have required richContent with CollectorRichContent shape', () => { |
| 75 | + expectTypeOf<ReadOnlyCollectorBase['output']['richContent']>().toEqualTypeOf<CollectorRichContent>(); |
| 76 | + }); |
| 77 | + |
| 78 | + it('should have standard collector fields', () => { |
| 79 | + expectTypeOf<ReadOnlyCollectorBase>().toHaveProperty('category').toEqualTypeOf<'NoValueCollector'>(); |
| 80 | + expectTypeOf<ReadOnlyCollectorBase>().toHaveProperty('type').toEqualTypeOf<'ReadOnlyCollector'>(); |
| 81 | + expectTypeOf<ReadOnlyCollectorBase>().toHaveProperty('error').toEqualTypeOf<string | null>(); |
| 82 | + }); |
| 83 | + }); |
| 84 | + |
| 85 | + describe('NoValueCollector<ReadOnlyCollector>', () => { |
| 86 | + it('should resolve to ReadOnlyCollectorBase', () => { |
| 87 | + expectTypeOf<NoValueCollector<'ReadOnlyCollector'>>().toEqualTypeOf<ReadOnlyCollectorBase>(); |
| 88 | + }); |
| 89 | + |
| 90 | + it('should have content and richContent on output', () => { |
| 91 | + type Resolved = NoValueCollector<'ReadOnlyCollector'>; |
| 92 | + expectTypeOf<Resolved['output']['content']>().toBeString(); |
| 93 | + expectTypeOf<Resolved['output']['richContent']>().toEqualTypeOf<CollectorRichContent>(); |
| 94 | + }); |
| 95 | + }); |
| 96 | + |
| 97 | + describe('ReadOnlyCollector alias', () => { |
| 98 | + it('should equal ReadOnlyCollectorBase', () => { |
| 99 | + expectTypeOf<ReadOnlyCollector>().toEqualTypeOf<ReadOnlyCollectorBase>(); |
| 100 | + }); |
| 101 | + }); |
| 102 | +}); |
0 commit comments