@@ -17,16 +17,20 @@ import {
1717} from '../../testHelpers/datasets/datasetHelper'
1818import {
1919 createCollectionViaApi ,
20- deleteCollectionViaApi
20+ deleteCollectionViaApi ,
21+ publishCollectionViaApi
2122} from '../../testHelpers/collections/collectionHelper'
2223import { CollectionPayload } from '../../../src/collections/infra/repositories/transformers/CollectionPayload'
2324import { AccessRepository } from '../../../src/access/infra/repositories/AccessRepository'
2425import { GuestbookResponseDTO } from '../../../src/access/domain/dtos/GuestbookResponseDTO'
2526import { testTextFile1Name , uploadFileViaApi } from '../../testHelpers/files/filesHelper'
27+ import { FilesRepository } from '../../../src/files/infra/repositories/FilesRepository'
28+ import { FileOrderCriteria } from '../../../src/files/domain/models/FileCriteria'
2629
2730describe ( 'GuestbooksRepository' , ( ) => {
2831 const sut = new GuestbooksRepository ( )
2932 const accessRepository = new AccessRepository ( )
33+ const filesRepository = new FilesRepository ( )
3034 const testCollectionAlias = 'testGuestbooksRepository'
3135 let testCollectionId : number
3236 let createdGuestbookId : number
@@ -79,6 +83,7 @@ describe('GuestbooksRepository', () => {
7983 await createCollectionViaApi ( testCollectionAlias ) . then (
8084 ( collectionPayload : CollectionPayload ) => ( testCollectionId = collectionPayload . id )
8185 )
86+ await publishCollectionViaApi ( testCollectionAlias )
8287 } )
8388
8489 afterAll ( async ( ) => {
@@ -142,7 +147,7 @@ describe('GuestbooksRepository', () => {
142147 expect ( createdGuestbookWithStats ?. responseCount ) . toEqual ( expect . any ( Number ) )
143148 } )
144149
145- test ( 'should increment usageCount when assigned to a dataset and responseCount when a response is submitted ' , async ( ) => {
150+ test ( 'should increment usageCount when assigned by the dataset admin and responseCount only when a guest submits a response ' , async ( ) => {
146151 let statsDatasetIds : CreatedDatasetIdentifiers | undefined
147152 let statsDatasetPublished = false
148153 const guestbookResponse : GuestbookResponseDTO = {
@@ -164,6 +169,13 @@ describe('GuestbooksRepository', () => {
164169 testCollectionAlias
165170 )
166171 await uploadFileViaApi ( statsDatasetIds . numericId , testTextFile1Name )
172+ const datasetFiles = await filesRepository . getDatasetFiles (
173+ statsDatasetIds . numericId ,
174+ DatasetNotNumberedVersion . LATEST ,
175+ false ,
176+ FileOrderCriteria . NAME_AZ
177+ )
178+ const fileId = datasetFiles . files [ 0 ] . id
167179
168180 await sut . assignDatasetGuestbook ( statsDatasetIds . numericId , statsGuestbookId )
169181
@@ -175,11 +187,14 @@ describe('GuestbooksRepository', () => {
175187 statsDatasetPublished = true
176188 await waitForNoLocks ( statsDatasetIds . numericId , 10 )
177189
178- ApiConfig . init ( TestConstants . TEST_API_URL , DataverseApiAuthMechanism . API_KEY , undefined )
179- await accessRepository . submitGuestbookForDatasetDownload (
180- statsDatasetIds . numericId ,
181- guestbookResponse
190+ ApiConfig . init (
191+ TestConstants . TEST_API_URL ,
192+ DataverseApiAuthMechanism . BEARER_TOKEN ,
193+ undefined ,
194+ undefined ,
195+ ( ) => null
182196 )
197+ await accessRepository . submitGuestbookForDatafileDownload ( fileId , guestbookResponse )
183198
184199 ApiConfig . init (
185200 TestConstants . TEST_API_URL ,
0 commit comments