11import { mapLetterBaseToApiDocument , mapLetterBaseToApiResource } from '../letter-mapper' ;
2- import { Letter , LetterBase } from '../../../../../internal/datastore' ;
3- import { LetterApiDocument } from '../../contracts/letter-api' ;
4- import { ZodError } from "zod" ;
2+ import { Letter } from '../../../../../internal/datastore' ;
3+ import { LetterApiDocument , LetterApiResource } from '../../contracts/letter-api' ;
54
65describe ( 'letter-mapper' , ( ) => {
76 it ( 'maps a Letter to LetterApiDocument' , ( ) => {
@@ -34,7 +33,7 @@ describe('letter-mapper', () => {
3433 } ) ;
3534 } ) ;
3635
37- it ( 'maps a Letter to LetterApiDocument with reasonCode and reasonText' , ( ) => {
36+ it ( 'maps a Letter to LetterApiDocument with reasonCode and reasonText when present ' , ( ) => {
3837 const letter : Letter = {
3938 id : 'abc123' ,
4039 status : 'PENDING' ,
@@ -51,7 +50,7 @@ describe('letter-mapper', () => {
5150 reasonText : 'Reason text'
5251 } ;
5352
54- const result : LetterApiDocument = mapLetterBaseToApiDocument ( letter ) ;
53+ const result : LetterApiDocument = mapLetterBaseToApiDocument ( letter , { excludeOptional : false } ) ;
5554
5655 expect ( result ) . toEqual ( {
5756 data : {
@@ -67,4 +66,69 @@ describe('letter-mapper', () => {
6766 }
6867 } ) ;
6968 } ) ;
69+
70+ it ( 'maps a Letter to LetterApiDocument without reasonCode and reasonText when present' , ( ) => {
71+ const letter : Letter = {
72+ id : 'abc123' ,
73+ status : 'PENDING' ,
74+ supplierId : 'supplier1' ,
75+ specificationId : 'spec123' ,
76+ groupId : 'group123' ,
77+ url : 'https://example.com/letter/abc123' ,
78+ createdAt : new Date ( ) . toISOString ( ) ,
79+ updatedAt : new Date ( ) . toISOString ( ) ,
80+ supplierStatus : 'supplier1#PENDING' ,
81+ supplierStatusSk : Date . now ( ) . toString ( ) ,
82+ ttl : 123 ,
83+ reasonCode : 123 ,
84+ reasonText : 'Reason text'
85+ } ;
86+
87+ const result : LetterApiDocument = mapLetterBaseToApiDocument ( letter , { excludeOptional : true } ) ;
88+
89+ expect ( result ) . toEqual ( {
90+ data : {
91+ id : 'abc123' ,
92+ type : 'Letter' ,
93+ attributes : {
94+ specificationId : 'spec123' ,
95+ status : 'PENDING' ,
96+ groupId : 'group123'
97+ }
98+ }
99+ } ) ;
100+ } ) ;
101+
102+
103+ it ( 'maps a Letter to LetterApiResource with reasonCode and reasonText when present' , ( ) => {
104+ const letter : Letter = {
105+ id : 'abc123' ,
106+ status : 'PENDING' ,
107+ supplierId : 'supplier1' ,
108+ specificationId : 'spec123' ,
109+ groupId : 'group123' ,
110+ url : 'https://example.com/letter/abc123' ,
111+ createdAt : new Date ( ) . toISOString ( ) ,
112+ updatedAt : new Date ( ) . toISOString ( ) ,
113+ supplierStatus : 'supplier1#PENDING' ,
114+ supplierStatusSk : Date . now ( ) . toString ( ) ,
115+ ttl : 123 ,
116+ reasonCode : 123 ,
117+ reasonText : 'Reason text'
118+ } ;
119+
120+ const result : LetterApiResource = mapLetterBaseToApiResource ( letter ) ;
121+
122+ expect ( result ) . toEqual ( {
123+ id : 'abc123' ,
124+ type : 'Letter' ,
125+ attributes : {
126+ specificationId : 'spec123' ,
127+ status : 'PENDING' ,
128+ groupId : 'group123' ,
129+ reasonCode : 123 ,
130+ reasonText : 'Reason text'
131+ }
132+ } ) ;
133+ } ) ;
70134} ) ;
0 commit comments