@@ -97,6 +97,67 @@ describe('execute', () => {
9797 }
9898 } )
9999
100+ test ( 'should not duplicate tabular tags when merging' , async ( ) => {
101+ const datasetFiles = await getDatasetFiles . execute ( testDatasetIds . numericId )
102+ const fileId = datasetFiles . files [ 0 ] . id
103+
104+ const initialTags = [ 'Survey' , 'Panel' ]
105+ const newTags = [ 'Panel' , 'Event' ]
106+ const expectedMergedTags = [ 'Survey' , 'Panel' , 'Event' ]
107+
108+ await updateFileTabularTags . execute ( fileId , initialTags , true )
109+ await updateFileTabularTags . execute ( fileId , newTags , false )
110+
111+ const fileInfo = ( await getFile . execute ( fileId , DatasetNotNumberedVersion . LATEST ) ) as FileModel
112+
113+ expect ( fileInfo . tabularTags ?. sort ( ) ) . toEqual ( expectedMergedTags . sort ( ) )
114+ } )
115+
116+ test ( 'should replace tabular tags when replace = true' , async ( ) => {
117+ const datasetFiles = await getDatasetFiles . execute ( testDatasetIds . numericId )
118+ const fileId = datasetFiles . files [ 0 ] . id
119+
120+ const initialTags = [ 'Survey' , 'Panel' , 'Event' ]
121+ const newTags = [ 'Survey' , 'Network' ]
122+
123+ await updateFileTabularTags . execute ( fileId , initialTags , true )
124+ await updateFileTabularTags . execute ( fileId , newTags , true )
125+
126+ const fileInfo = ( await getFile . execute ( fileId , DatasetNotNumberedVersion . LATEST ) ) as FileModel
127+
128+ expect ( fileInfo . tabularTags ?. sort ( ) ) . toEqual ( newTags . sort ( ) )
129+ } )
130+
131+ test ( 'should throw an error when updating tabular tags on a non-tabular file' , async ( ) => {
132+ const nonTabularFileName = 'test-file-1.txt'
133+
134+ try {
135+ await uploadFileViaApi ( testDatasetIds . numericId , nonTabularFileName )
136+ } catch {
137+ throw new Error ( `Error uploading non-tabular file: ${ nonTabularFileName } ` )
138+ }
139+ const datasetFiles = await getDatasetFiles . execute ( testDatasetIds . numericId )
140+ const matchingFile = datasetFiles . files . find ( ( f ) => f . name === nonTabularFileName )
141+ if ( ! matchingFile ) {
142+ throw new Error ( 'Uploaded non-tabular file not found in dataset' )
143+ }
144+
145+ const fileId = matchingFile . id
146+
147+ let writeError : WriteError | undefined = undefined
148+
149+ try {
150+ await updateFileTabularTags . execute ( fileId , [ 'Survey' ] , false )
151+ } catch ( error ) {
152+ writeError = error as WriteError
153+ } finally {
154+ expect ( writeError ) . toBeInstanceOf ( WriteError )
155+ expect ( writeError ?. message ) . toEqual (
156+ `There was an error when writing the resource. Reason was: [400] This operation is only available for tabular files.`
157+ )
158+ }
159+ } )
160+
100161 test ( 'should throw an error when the file id does not exist' , async ( ) => {
101162 let writeError : WriteError | undefined = undefined
102163 const nonExistentFileId = 5
0 commit comments