@@ -19,6 +19,8 @@ import {
19
19
createManualAttribution ,
20
20
deleteManualAttribution ,
21
21
updateManualAttribution ,
22
+ unlinkResourceFromAttributionId ,
23
+ linkToAttributionManualData ,
22
24
} from '../save-action-helpers' ;
23
25
24
26
const testUuid : string = uuidNil ;
@@ -193,6 +195,103 @@ describe('The updateManualAttribution function', () => {
193
195
} ) ;
194
196
} ) ;
195
197
198
+ describe ( 'The linkToAttributionManualData function' , ( ) => {
199
+ it ( 'links a manual attribution' , ( ) => {
200
+ const testManualData : AttributionData = {
201
+ attributions : {
202
+ [ testUuid ] : {
203
+ packageName : 'testpackage' ,
204
+ packageVersion : '2.0' ,
205
+ licenseText : 'Permission is hereby granted' ,
206
+ } ,
207
+ } ,
208
+ resourcesToAttributions : { } ,
209
+ attributionsToResources : { } ,
210
+ resourcesWithAttributedChildren : {
211
+ attributedChildren : { } ,
212
+ pathsToIndices : {
213
+ '/' : 0 ,
214
+ '/first/' : 1 ,
215
+ } ,
216
+ paths : [ '/' , '/first/' ] ,
217
+ } ,
218
+ } ;
219
+
220
+ const newManualData = linkToAttributionManualData (
221
+ testManualData ,
222
+ '/first/' ,
223
+ testUuid ,
224
+ ( ) => false ,
225
+ ) ;
226
+
227
+ expect ( newManualData . attributions ) . toEqual ( testManualData . attributions ) ;
228
+ expect ( newManualData . resourcesToAttributions ) . toEqual ( {
229
+ '/first/' : [ testUuid ] ,
230
+ } ) ;
231
+ expect ( newManualData . attributionsToResources ) . toEqual ( {
232
+ [ testUuid ] : [ '/first/' ] ,
233
+ } ) ;
234
+ expect ( newManualData . resourcesWithAttributedChildren ) . toEqual ( {
235
+ attributedChildren : {
236
+ '0' : new Set < number > ( ) . add ( 1 ) ,
237
+ } ,
238
+ pathsToIndices : {
239
+ '/' : 0 ,
240
+ '/first/' : 1 ,
241
+ } ,
242
+ paths : [ '/' , '/first/' ] ,
243
+ } ) ;
244
+ } ) ;
245
+ } ) ;
246
+
247
+ describe ( 'The unlinkResourceFromAttributionId function' , ( ) => {
248
+ it ( 'unlinks a manual attribution' , ( ) => {
249
+ const testManualData : AttributionData = {
250
+ attributions : {
251
+ [ testUuid ] : {
252
+ packageName : 'testpackage' ,
253
+ packageVersion : '2.0' ,
254
+ licenseText : 'Permission is hereby granted' ,
255
+ } ,
256
+ } ,
257
+ resourcesToAttributions : {
258
+ '/first/' : [ testUuid ] ,
259
+ } ,
260
+ attributionsToResources : {
261
+ [ testUuid ] : [ '/first/' ] ,
262
+ } ,
263
+ resourcesWithAttributedChildren : {
264
+ attributedChildren : {
265
+ '0' : new Set < number > ( ) . add ( 1 ) ,
266
+ } ,
267
+ pathsToIndices : {
268
+ '/' : 0 ,
269
+ '/first/' : 1 ,
270
+ } ,
271
+ paths : [ '/' , '/first/' ] ,
272
+ } ,
273
+ } ;
274
+
275
+ const newManualData : AttributionData = unlinkResourceFromAttributionId (
276
+ testManualData ,
277
+ '/first/' ,
278
+ testUuid ,
279
+ ) ;
280
+
281
+ expect ( newManualData . attributions ) . toEqual ( testManualData . attributions ) ;
282
+ expect ( isEmpty ( newManualData . resourcesToAttributions ) ) . toBe ( true ) ;
283
+ expect ( isEmpty ( newManualData . attributionsToResources ) ) . toBe ( true ) ;
284
+ expect ( newManualData . resourcesWithAttributedChildren ) . toEqual ( {
285
+ attributedChildren : { } ,
286
+ pathsToIndices : {
287
+ '/' : 0 ,
288
+ '/first/' : 1 ,
289
+ } ,
290
+ paths : [ '/' , '/first/' ] ,
291
+ } ) ;
292
+ } ) ;
293
+ } ) ;
294
+
196
295
describe ( '_removeManualAttributionFromChildrenIfAllAreIdentical' , ( ) => {
197
296
it ( 'three matching' , ( ) => {
198
297
const testManualData : AttributionData = {
0 commit comments