@@ -79,12 +79,20 @@ describe('GuestbooksRepository', () => {
7979 describe ( 'createGuestbook' , ( ) => {
8080 test ( 'should create guestbook for collection' , async ( ) => {
8181 const actual = await sut . createGuestbook ( testCollectionId , createGuestbookDTO )
82- expect ( actual ) . toBeUndefined ( )
82+ expect ( actual ) . toEqual ( expect . any ( Number ) )
83+ expect ( actual ) . toBeGreaterThan ( 0 )
84+
85+ const getGuestbookResponse = await sut . getGuestbook ( actual )
86+ expect ( getGuestbookResponse . name ) . toBe ( createGuestbookDTO . name )
8387 } )
8488
8589 test ( 'should create guestbook for collection by collection alias' , async ( ) => {
8690 const actual = await sut . createGuestbook ( testCollectionAlias , createGuestbookDTO )
87- expect ( actual ) . toBeUndefined ( )
91+ expect ( actual ) . toEqual ( expect . any ( Number ) )
92+ expect ( actual ) . toBeGreaterThan ( 0 )
93+
94+ const getGuestbookResponse = await sut . getGuestbook ( actual )
95+ expect ( getGuestbookResponse . name ) . toBe ( createGuestbookDTO . name )
8896 } )
8997
9098 test ( 'should return error when collection does not exist' , async ( ) => {
@@ -94,16 +102,20 @@ describe('GuestbooksRepository', () => {
94102
95103 describe ( 'getGuestbooksByCollectionId' , ( ) => {
96104 test ( 'should list guestbooks for collection' , async ( ) => {
97- await sut . createGuestbook ( testCollectionId , createGuestbookDTO )
105+ createdGuestbookId = await sut . createGuestbook ( testCollectionId , createGuestbookDTO )
98106 const actual = await sut . getGuestbooksByCollectionId ( testCollectionId )
99107 expect ( actual . length ) . toBeGreaterThan ( 0 )
100- createdGuestbookId = actual [ 0 ] . id as number
108+ expect ( actual . some ( ( guestbook ) => guestbook . id === createdGuestbookId ) ) . toBe ( true )
101109 } )
102110
103111 test ( 'should list guestbooks for collection by collection alias' , async ( ) => {
104- await sut . createGuestbook ( testCollectionAlias , createGuestbookDTO )
112+ const createdByAliasGuestbookId = await sut . createGuestbook (
113+ testCollectionAlias ,
114+ createGuestbookDTO
115+ )
105116 const actual = await sut . getGuestbooksByCollectionId ( testCollectionAlias )
106117 expect ( actual . length ) . toBeGreaterThan ( 0 )
118+ expect ( actual . some ( ( guestbook ) => guestbook . id === createdByAliasGuestbookId ) ) . toBe ( true )
107119 } )
108120
109121 test ( 'should return error when collection does not exist' , async ( ) => {
@@ -113,8 +125,8 @@ describe('GuestbooksRepository', () => {
113125
114126 describe ( 'getGuestbook' , ( ) => {
115127 test ( 'should get guestbook by id' , async ( ) => {
116- await sut . createGuestbook ( testCollectionId , createGuestbookDTO )
117- const actual = await sut . getGuestbook ( createdGuestbookId as number )
128+ createdGuestbookId = await sut . createGuestbook ( testCollectionId , createGuestbookDTO )
129+ const actual = await sut . getGuestbook ( createdGuestbookId )
118130 expect ( actual . id ) . toBe ( createdGuestbookId )
119131 expect ( actual . name ) . toBe ( createGuestbookDTO . name )
120132 } )
@@ -126,17 +138,17 @@ describe('GuestbooksRepository', () => {
126138
127139 describe ( 'setGuestbookEnabled' , ( ) => {
128140 test ( 'should disable guestbook' , async ( ) => {
129- await sut . createGuestbook ( testCollectionId , createGuestbookDTO )
141+ createdGuestbookId = await sut . createGuestbook ( testCollectionId , createGuestbookDTO )
130142
131- await sut . setGuestbookEnabled ( testCollectionId , createdGuestbookId as number , false )
132- const actual = await sut . getGuestbook ( createdGuestbookId as number )
143+ await sut . setGuestbookEnabled ( testCollectionId , createdGuestbookId , false )
144+ const actual = await sut . getGuestbook ( createdGuestbookId )
133145
134146 expect ( actual . enabled ) . toBe ( false )
135147 } )
136148
137149 test ( 'should enable guestbook' , async ( ) => {
138- await sut . setGuestbookEnabled ( testCollectionId , createdGuestbookId as number , true )
139- const actual = await sut . getGuestbook ( createdGuestbookId as number )
150+ await sut . setGuestbookEnabled ( testCollectionId , createdGuestbookId , true )
151+ const actual = await sut . getGuestbook ( createdGuestbookId )
140152
141153 expect ( actual . enabled ) . toBe ( true )
142154 } )
@@ -153,17 +165,11 @@ describe('GuestbooksRepository', () => {
153165 let assignableGuestbookId : number
154166
155167 beforeAll ( async ( ) => {
156- await sut . createGuestbook ( testCollectionId , {
168+ assignableGuestbookId = await sut . createGuestbook ( testCollectionId , {
157169 ...createGuestbookDTO ,
158170 name : 'assign/remove guestbook test'
159171 } )
160172
161- const guestbooks = await sut . getGuestbooksByCollectionId ( testCollectionId )
162- const assignableGuestbook = guestbooks . find (
163- ( guestbook ) => guestbook . name === 'assign/remove guestbook test'
164- )
165- assignableGuestbookId = assignableGuestbook ?. id as number
166-
167173 testDatasetIds = await createDataset . execute (
168174 TestConstants . TEST_NEW_DATASET_DTO ,
169175 testCollectionAlias
0 commit comments