Skip to content
Myr

jwa.test.ts

This file

Path

src/utils/jwt/jwa.test.ts

86 lines · 2.9 KiB · TypeScript

Last changed by

Not known.

History of this file

Take it

The walk stopped after 200 commits: lines older than f0b094d point at it.

Merge commit from forkYusuke Wadabefore adoptionf0b094d

lines 1–86why, one step back
1import { AlgorithmTypes } from './jwa'
2import type { AsymmetricAlgorithm, SymmetricAlgorithm, SignatureAlgorithm } from './jwa'34describe('Types', () => {5 it('AlgorithmTypes', () => {6 expect('HS256' as AlgorithmTypes).toBe(AlgorithmTypes.HS256)7 expect('HS384' as AlgorithmTypes).toBe(AlgorithmTypes.HS384)8 expect('HS512' as AlgorithmTypes).toBe(AlgorithmTypes.HS512)9 expect('RS256' as AlgorithmTypes).toBe(AlgorithmTypes.RS256)10 expect('RS384' as AlgorithmTypes).toBe(AlgorithmTypes.RS384)11 expect('RS512' as AlgorithmTypes).toBe(AlgorithmTypes.RS512)12 expect('PS256' as AlgorithmTypes).toBe(AlgorithmTypes.PS256)13 expect('PS384' as AlgorithmTypes).toBe(AlgorithmTypes.PS384)14 expect('PS512' as AlgorithmTypes).toBe(AlgorithmTypes.PS512)15 expect('ES256' as AlgorithmTypes).toBe(AlgorithmTypes.ES256)16 expect('ES384' as AlgorithmTypes).toBe(AlgorithmTypes.ES384)17 expect('ES512' as AlgorithmTypes).toBe(AlgorithmTypes.ES512)18 expect('EdDSA' as AlgorithmTypes).toBe(AlgorithmTypes.EdDSA)1920 // eslint-disable-next-line @typescript-eslint/ban-ts-comment21 // @ts-ignore22 expect(undefined as AlgorithmTypes).toBe(undefined)23 expect('' as AlgorithmTypes).toBe('')24 })2526 it('SymmetricAlgorithm type should only include HMAC algorithms', () => {27 // These should be valid SymmetricAlgorithm values28 const hs256: SymmetricAlgorithm = 'HS256'29 const hs384: SymmetricAlgorithm = 'HS384'30 const hs512: SymmetricAlgorithm = 'HS512'3132 expect(hs256).toBe('HS256')33 expect(hs384).toBe('HS384')34 expect(hs512).toBe('HS512')3536 // Type-level test: these would cause compile errors if uncommented37 // const rs256: SymmetricAlgorithm = 'RS256' // Error: Type '"RS256"' is not assignable to type 'SymmetricAlgorithm'38 })3940 it('AsymmetricAlgorithm type should only include asymmetric algorithms', () => {41 // These should be valid AsymmetricAlgorithm values42 const asymmetricAlgs: AsymmetricAlgorithm[] = [43 'RS256',44 'RS384',45 'RS512',46 'PS256',47 'PS384',48 'PS512',49 'ES256',50 'ES384',51 'ES512',52 'EdDSA',53 ]5455 expect(asymmetricAlgs).toHaveLength(10)5657 // Verify all asymmetric algorithms are included58 expect(asymmetricAlgs).toContain('RS256')59 expect(asymmetricAlgs).toContain('ES256')60 expect(asymmetricAlgs).toContain('EdDSA')6162 // Type-level test: these would cause compile errors if uncommented63 // const hs256: AsymmetricAlgorithm = 'HS256' // Error: Type '"HS256"' is not assignable to type 'AsymmetricAlgorithm'64 })6566 it('SignatureAlgorithm type should include all algorithms', () => {67 // SignatureAlgorithm should include both symmetric and asymmetric algorithms68 const allAlgs: SignatureAlgorithm[] = [69 'HS256',70 'HS384',71 'HS512',72 'RS256',73 'RS384',74 'RS512',75 'PS256',76 'PS384',77 'PS512',78 'ES256',79 'ES384',80 'ES512',81 'EdDSA',82 ]8384 expect(allAlgs).toHaveLength(13)85 })86})