88 createSaveAndExitRecord ,
99 deleteSaveAndExitGroup ,
1010 findExpiringRecords ,
11+ getLatestSaveAndExitByGroup ,
1112 getSaveAndExitRecord ,
1213 incrementInvalidPasswordAttempts ,
1314 lockRecordForExpiryEmail ,
@@ -70,7 +71,7 @@ describe('save-and-exit-repository', () => {
7071 } )
7172
7273 describe ( 'getSaveAndExitRecord' , ( ) => {
73- it ( 'should get save and exit record' , async ( ) => {
74+ it ( 'should get save and exit record if not comsumed ' , async ( ) => {
7475 mockCollection . findOne . mockReturnValueOnce ( submissionDocument )
7576 const submissionRecord = await getSaveAndExitRecord (
7677 STUB_SAVE_AND_EXIT_RECORD_ID
@@ -88,6 +89,38 @@ describe('save-and-exit-repository', () => {
8889 } )
8990 } )
9091
92+ describe ( 'getLatestSaveAndExitByGroup' , ( ) => {
93+ it ( 'should get latest save and exit record by group' , async ( ) => {
94+ const document1WithGroup = {
95+ ...submissionDocument ,
96+ magicLinkId : 'id1' ,
97+ magicLinkGroupId : 'magic-group-id'
98+ }
99+ const document2WithGroup = {
100+ ...submissionDocument ,
101+ magicLinkId : 'id2' ,
102+ magicLinkGroupId : 'magic-group-id'
103+ }
104+ mockCollection . find . mockReturnValueOnce ( {
105+ sort : jest . fn ( ( ) => {
106+ return { toArray : ( ) => [ document2WithGroup , document1WithGroup ] }
107+ } )
108+ } )
109+ const submissionRecord =
110+ await getLatestSaveAndExitByGroup ( 'magic-group-id' )
111+ expect ( submissionRecord ) . toEqual ( document2WithGroup )
112+ } )
113+
114+ it ( 'should handle get latest save and exit record failures' , async ( ) => {
115+ mockCollection . find . mockImplementation ( ( ) => {
116+ throw new Error ( 'an error' )
117+ } )
118+ await expect (
119+ getLatestSaveAndExitByGroup ( STUB_SAVE_AND_EXIT_RECORD_ID )
120+ ) . rejects . toThrow ( new Error ( 'an error' ) )
121+ } )
122+ } )
123+
91124 describe ( 'createSaveAndExitRecord' , ( ) => {
92125 it ( 'should create a save and exit record when no previous relevant ones' , async ( ) => {
93126 jest . mocked (
0 commit comments