@@ -26,12 +26,13 @@ jest.mock('node:crypto');
2626const templateId = 'abc-def-ghi-jkl-123' ;
2727const templatesTableName = 'templates' ;
2828
29- const setup = ( ) => {
29+ const setup = ( enableProofing = false ) => {
3030 const ddbDocClient = mockClient ( DynamoDBDocumentClient ) ;
3131
3232 const templateRepository = new TemplateRepository (
3333 ddbDocClient as unknown as DynamoDBDocumentClient ,
34- templatesTableName
34+ templatesTableName ,
35+ enableProofing
3536 ) ;
3637
3738 return { templateRepository, mocks : { ddbDocClient } } ;
@@ -1012,77 +1013,151 @@ describe('templateRepository', () => {
10121013 } ) ;
10131014
10141015 describe ( 'setLetterValidationResult' , ( ) => {
1015- it ( 'updates the templateStatus to NOT_YET_SUBMITTED, personalisationParameters and csvHeaders if valid' , async ( ) => {
1016- const { templateRepository, mocks } = setup ( ) ;
1016+ describe ( 'when proofing flag is enabled' , ( ) => {
1017+ const { templateRepository, mocks } = setup ( true ) ;
10171018
1018- await templateRepository . setLetterValidationResult (
1019- { owner : 'template-owner' , id : 'template-id' } ,
1020- 'file-version-id' ,
1021- true ,
1022- [ 'personalisation' , 'parameters' ] ,
1023- [ 'csv' , 'headers' ]
1024- ) ;
1019+ it ( 'should update the templateStatus to PENDING_PROOF_REQUEST, personalisationParameters and csvHeader when template is valid' , async ( ) => {
1020+ await templateRepository . setLetterValidationResult (
1021+ { owner : 'template-owner' , id : 'template-id' } ,
1022+ 'file-version-id' ,
1023+ true ,
1024+ [ 'personalisation' , 'parameters' ] ,
1025+ [ 'csv' , 'headers' ]
1026+ ) ;
10251027
1026- expect ( mocks . ddbDocClient ) . toHaveReceivedCommandWith ( UpdateCommand , {
1027- TableName : 'templates' ,
1028- Key : { id : 'template-id' , owner : 'template-owner' } ,
1029- UpdateExpression :
1030- 'SET #templateStatus = :templateStatus , #updatedAt = :updatedAt , #personalisationParameters = :personalisationParameters , #csvHeaders = :csvHeaders' ,
1031- ConditionExpression :
1032- '#files.#file.#version = :version and not #templateStatus in (:templateStatusDeleted, :templateStatusSubmitted)' ,
1033- ExpressionAttributeNames : {
1034- '#csvHeaders' : 'csvHeaders' ,
1035- '#file' : 'pdfTemplate' ,
1036- '#files' : 'files' ,
1037- '#personalisationParameters' : 'personalisationParameters' ,
1038- '#templateStatus' : 'templateStatus' ,
1039- '#updatedAt' : 'updatedAt' ,
1040- '#version' : 'currentVersion' ,
1041- } ,
1042- ExpressionAttributeValues : {
1043- ':csvHeaders' : [ 'csv' , 'headers' ] ,
1044- ':personalisationParameters' : [ 'personalisation' , 'parameters' ] ,
1045- ':templateStatus' : 'NOT_YET_SUBMITTED' ,
1046- ':templateStatusDeleted' : 'DELETED' ,
1047- ':templateStatusSubmitted' : 'SUBMITTED' ,
1048- ':updatedAt' : '2024-12-27T00:00:00.000Z' ,
1049- ':version' : 'file-version-id' ,
1050- } ,
1028+ expect ( mocks . ddbDocClient ) . toHaveReceivedCommandWith ( UpdateCommand , {
1029+ TableName : 'templates' ,
1030+ Key : { id : 'template-id' , owner : 'template-owner' } ,
1031+ UpdateExpression :
1032+ 'SET #templateStatus = :templateStatus , #updatedAt = :updatedAt , #personalisationParameters = :personalisationParameters , #csvHeaders = :csvHeaders' ,
1033+ ConditionExpression :
1034+ '#files.#file.#version = :version and not #templateStatus in (:templateStatusDeleted, :templateStatusSubmitted)' ,
1035+ ExpressionAttributeNames : {
1036+ '#csvHeaders' : 'csvHeaders' ,
1037+ '#file' : 'pdfTemplate' ,
1038+ '#files' : 'files' ,
1039+ '#personalisationParameters' : 'personalisationParameters' ,
1040+ '#templateStatus' : 'templateStatus' ,
1041+ '#updatedAt' : 'updatedAt' ,
1042+ '#version' : 'currentVersion' ,
1043+ } ,
1044+ ExpressionAttributeValues : {
1045+ ':csvHeaders' : [ 'csv' , 'headers' ] ,
1046+ ':personalisationParameters' : [ 'personalisation' , 'parameters' ] ,
1047+ ':templateStatus' : 'PENDING_PROOF_REQUEST' ,
1048+ ':templateStatusDeleted' : 'DELETED' ,
1049+ ':templateStatusSubmitted' : 'SUBMITTED' ,
1050+ ':updatedAt' : '2024-12-27T00:00:00.000Z' ,
1051+ ':version' : 'file-version-id' ,
1052+ } ,
1053+ } ) ;
1054+ } ) ;
1055+
1056+ it ( 'should update the templateStatus to VALIDATION_FAILED when template is not valid' , async ( ) => {
1057+ await templateRepository . setLetterValidationResult (
1058+ { owner : 'template-owner' , id : 'template-id' } ,
1059+ 'file-version-id' ,
1060+ false ,
1061+ [ ] ,
1062+ [ ]
1063+ ) ;
1064+
1065+ expect ( mocks . ddbDocClient ) . toHaveReceivedCommandWith ( UpdateCommand , {
1066+ TableName : 'templates' ,
1067+ Key : { id : 'template-id' , owner : 'template-owner' } ,
1068+ UpdateExpression :
1069+ 'SET #templateStatus = :templateStatus , #updatedAt = :updatedAt' ,
1070+ ConditionExpression :
1071+ '#files.#file.#version = :version and not #templateStatus in (:templateStatusDeleted, :templateStatusSubmitted)' ,
1072+ ExpressionAttributeNames : {
1073+ '#file' : 'pdfTemplate' ,
1074+ '#files' : 'files' ,
1075+ '#templateStatus' : 'templateStatus' ,
1076+ '#updatedAt' : 'updatedAt' ,
1077+ '#version' : 'currentVersion' ,
1078+ } ,
1079+ ExpressionAttributeValues : {
1080+ ':templateStatus' : 'VALIDATION_FAILED' ,
1081+ ':templateStatusDeleted' : 'DELETED' ,
1082+ ':templateStatusSubmitted' : 'SUBMITTED' ,
1083+ ':updatedAt' : '2024-12-27T00:00:00.000Z' ,
1084+ ':version' : 'file-version-id' ,
1085+ } ,
1086+ } ) ;
10511087 } ) ;
10521088 } ) ;
10531089
1054- it ( 'updates the templateStatus to VALIDATION_FAILED if no valid' , async ( ) => {
1055- const { templateRepository, mocks } = setup ( ) ;
1090+ describe ( 'when proofing flag is disabled' , ( ) => {
1091+ const { templateRepository, mocks } = setup ( false ) ;
10561092
1057- await templateRepository . setLetterValidationResult (
1058- { owner : 'template-owner' , id : 'template-id' } ,
1059- 'file-version-id' ,
1060- false ,
1061- [ ] ,
1062- [ ]
1063- ) ;
1093+ it ( 'updates the templateStatus to NOT_YET_SUBMITTED, personalisationParameters and csvHeaders if valid' , async ( ) => {
1094+ await templateRepository . setLetterValidationResult (
1095+ { owner : 'template-owner' , id : 'template-id' } ,
1096+ 'file-version-id' ,
1097+ true ,
1098+ [ 'personalisation' , 'parameters' ] ,
1099+ [ 'csv' , 'headers' ]
1100+ ) ;
10641101
1065- expect ( mocks . ddbDocClient ) . toHaveReceivedCommandWith ( UpdateCommand , {
1066- TableName : 'templates' ,
1067- Key : { id : 'template-id' , owner : 'template-owner' } ,
1068- UpdateExpression :
1069- 'SET #templateStatus = :templateStatus , #updatedAt = :updatedAt' ,
1070- ConditionExpression :
1071- '#files.#file.#version = :version and not #templateStatus in (:templateStatusDeleted, :templateStatusSubmitted)' ,
1072- ExpressionAttributeNames : {
1073- '#file' : 'pdfTemplate' ,
1074- '#files' : 'files' ,
1075- '#templateStatus' : 'templateStatus' ,
1076- '#updatedAt' : 'updatedAt' ,
1077- '#version' : 'currentVersion' ,
1078- } ,
1079- ExpressionAttributeValues : {
1080- ':templateStatus' : 'VALIDATION_FAILED' ,
1081- ':templateStatusDeleted' : 'DELETED' ,
1082- ':templateStatusSubmitted' : 'SUBMITTED' ,
1083- ':updatedAt' : '2024-12-27T00:00:00.000Z' ,
1084- ':version' : 'file-version-id' ,
1085- } ,
1102+ expect ( mocks . ddbDocClient ) . toHaveReceivedCommandWith ( UpdateCommand , {
1103+ TableName : 'templates' ,
1104+ Key : { id : 'template-id' , owner : 'template-owner' } ,
1105+ UpdateExpression :
1106+ 'SET #templateStatus = :templateStatus , #updatedAt = :updatedAt , #personalisationParameters = :personalisationParameters , #csvHeaders = :csvHeaders' ,
1107+ ConditionExpression :
1108+ '#files.#file.#version = :version and not #templateStatus in (:templateStatusDeleted, :templateStatusSubmitted)' ,
1109+ ExpressionAttributeNames : {
1110+ '#csvHeaders' : 'csvHeaders' ,
1111+ '#file' : 'pdfTemplate' ,
1112+ '#files' : 'files' ,
1113+ '#personalisationParameters' : 'personalisationParameters' ,
1114+ '#templateStatus' : 'templateStatus' ,
1115+ '#updatedAt' : 'updatedAt' ,
1116+ '#version' : 'currentVersion' ,
1117+ } ,
1118+ ExpressionAttributeValues : {
1119+ ':csvHeaders' : [ 'csv' , 'headers' ] ,
1120+ ':personalisationParameters' : [ 'personalisation' , 'parameters' ] ,
1121+ ':templateStatus' : 'NOT_YET_SUBMITTED' ,
1122+ ':templateStatusDeleted' : 'DELETED' ,
1123+ ':templateStatusSubmitted' : 'SUBMITTED' ,
1124+ ':updatedAt' : '2024-12-27T00:00:00.000Z' ,
1125+ ':version' : 'file-version-id' ,
1126+ } ,
1127+ } ) ;
1128+ } ) ;
1129+
1130+ it ( 'updates the templateStatus to VALIDATION_FAILED if not valid' , async ( ) => {
1131+ await templateRepository . setLetterValidationResult (
1132+ { owner : 'template-owner' , id : 'template-id' } ,
1133+ 'file-version-id' ,
1134+ false ,
1135+ [ ] ,
1136+ [ ]
1137+ ) ;
1138+
1139+ expect ( mocks . ddbDocClient ) . toHaveReceivedCommandWith ( UpdateCommand , {
1140+ TableName : 'templates' ,
1141+ Key : { id : 'template-id' , owner : 'template-owner' } ,
1142+ UpdateExpression :
1143+ 'SET #templateStatus = :templateStatus , #updatedAt = :updatedAt' ,
1144+ ConditionExpression :
1145+ '#files.#file.#version = :version and not #templateStatus in (:templateStatusDeleted, :templateStatusSubmitted)' ,
1146+ ExpressionAttributeNames : {
1147+ '#file' : 'pdfTemplate' ,
1148+ '#files' : 'files' ,
1149+ '#templateStatus' : 'templateStatus' ,
1150+ '#updatedAt' : 'updatedAt' ,
1151+ '#version' : 'currentVersion' ,
1152+ } ,
1153+ ExpressionAttributeValues : {
1154+ ':templateStatus' : 'VALIDATION_FAILED' ,
1155+ ':templateStatusDeleted' : 'DELETED' ,
1156+ ':templateStatusSubmitted' : 'SUBMITTED' ,
1157+ ':updatedAt' : '2024-12-27T00:00:00.000Z' ,
1158+ ':version' : 'file-version-id' ,
1159+ } ,
1160+ } ) ;
10861161 } ) ;
10871162 } ) ;
10881163
0 commit comments