@@ -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 ;
@@ -91,24 +93,19 @@ describe('The deleteManualAttribution function', () => {
91
93
} ) ;
92
94
93
95
it ( 'correctly maintains childrenFromAttributedResources' , ( ) => {
94
- const testAnotherUuid = '000' ;
95
96
const testManualData : AttributionData = {
96
97
attributions : {
97
- [ testAnotherUuid ] : {
98
- packageName : 'another testpackage' ,
99
- } ,
100
98
[ testUuid ] : {
101
99
packageName : 'testpackage' ,
102
100
packageVersion : '2.0' ,
103
101
licenseText : 'Permission is hereby granted' ,
104
102
} ,
105
103
} ,
106
104
resourcesToAttributions : {
107
- '/first/' : [ testUuid , testAnotherUuid ] ,
105
+ '/first/' : [ testUuid ] ,
108
106
} ,
109
107
attributionsToResources : {
110
108
[ testUuid ] : [ '/first/' ] ,
111
- [ testAnotherUuid ] : [ '/first/' ] ,
112
109
} ,
113
110
resourcesWithAttributedChildren : {
114
111
attributedChildren : {
@@ -126,19 +123,11 @@ describe('The deleteManualAttribution function', () => {
126
123
testUuid ,
127
124
( ) => false ,
128
125
) ;
129
- expect ( newManualData . attributions ) . toEqual ( {
130
- '000' : { packageName : 'another testpackage' } ,
131
- } ) ;
132
- expect ( newManualData . resourcesToAttributions ) . toEqual ( {
133
- '/first/' : [ '000' ] ,
134
- } ) ;
135
- expect ( newManualData . attributionsToResources ) . toEqual ( {
136
- '000' : [ '/first/' ] ,
137
- } ) ;
126
+ expect ( newManualData . attributions ) . toEqual ( { } ) ;
127
+ expect ( newManualData . resourcesToAttributions ) . toEqual ( { } ) ;
128
+ expect ( newManualData . attributionsToResources ) . toEqual ( { } ) ;
138
129
expect ( newManualData . resourcesWithAttributedChildren ) . toEqual ( {
139
- attributedChildren : {
140
- '0' : new Set < number > ( ) . add ( 1 ) ,
141
- } ,
130
+ attributedChildren : { } ,
142
131
pathsToIndices : {
143
132
'/' : 0 ,
144
133
'/first/' : 1 ,
@@ -193,6 +182,190 @@ describe('The updateManualAttribution function', () => {
193
182
} ) ;
194
183
} ) ;
195
184
185
+ describe ( 'The linkToAttributionManualData function' , ( ) => {
186
+ it ( 'links a manual attribution' , ( ) => {
187
+ const testAnotherUuid = '000' ;
188
+ const testManualData : AttributionData = {
189
+ attributions : {
190
+ [ testAnotherUuid ] : {
191
+ packageName : 'another testpackage' ,
192
+ } ,
193
+ [ testUuid ] : {
194
+ packageName : 'testpackage' ,
195
+ packageVersion : '2.0' ,
196
+ licenseText : 'Permission is hereby granted' ,
197
+ } ,
198
+ } ,
199
+ resourcesToAttributions : {
200
+ '/first/' : [ testAnotherUuid ] ,
201
+ } ,
202
+ attributionsToResources : {
203
+ [ testAnotherUuid ] : [ '/first/' ] ,
204
+ } ,
205
+ resourcesWithAttributedChildren : {
206
+ attributedChildren : {
207
+ '0' : new Set < number > ( ) . add ( 1 ) ,
208
+ } ,
209
+ pathsToIndices : {
210
+ '/' : 0 ,
211
+ '/first/' : 1 ,
212
+ } ,
213
+ paths : [ '/' , '/first/' ] ,
214
+ } ,
215
+ } ;
216
+
217
+ const newManualData = linkToAttributionManualData (
218
+ testManualData ,
219
+ '/first/' ,
220
+ testUuid ,
221
+ ( ) => false ,
222
+ ) ;
223
+
224
+ expect ( newManualData . attributions ) . toEqual ( testManualData . attributions ) ;
225
+ expect ( newManualData . resourcesToAttributions ) . toEqual ( {
226
+ '/first/' : [ testAnotherUuid , testUuid ] ,
227
+ } ) ;
228
+ expect ( newManualData . attributionsToResources ) . toEqual ( {
229
+ [ testUuid ] : [ '/first/' ] ,
230
+ [ testAnotherUuid ] : [ '/first/' ] ,
231
+ } ) ;
232
+ expect ( newManualData . resourcesWithAttributedChildren ) . toEqual (
233
+ testManualData . resourcesWithAttributedChildren ,
234
+ ) ;
235
+ } ) ;
236
+
237
+ it ( 'correctly maintains childrenFromAttributedResources' , ( ) => {
238
+ const testManualData : AttributionData = {
239
+ attributions : {
240
+ [ testUuid ] : {
241
+ packageName : 'testpackage' ,
242
+ packageVersion : '2.0' ,
243
+ licenseText : 'Permission is hereby granted' ,
244
+ } ,
245
+ } ,
246
+ resourcesToAttributions : { } ,
247
+ attributionsToResources : { } ,
248
+ resourcesWithAttributedChildren : {
249
+ attributedChildren : { } ,
250
+ pathsToIndices : {
251
+ '/' : 0 ,
252
+ '/first/' : 1 ,
253
+ } ,
254
+ paths : [ '/' , '/first/' ] ,
255
+ } ,
256
+ } ;
257
+
258
+ const newManualData = linkToAttributionManualData (
259
+ testManualData ,
260
+ '/first/' ,
261
+ testUuid ,
262
+ ( ) => false ,
263
+ ) ;
264
+
265
+ expect ( newManualData . resourcesWithAttributedChildren ) . toEqual ( {
266
+ attributedChildren : {
267
+ '0' : new Set < number > ( ) . add ( 1 ) ,
268
+ } ,
269
+ pathsToIndices : {
270
+ '/' : 0 ,
271
+ '/first/' : 1 ,
272
+ } ,
273
+ paths : [ '/' , '/first/' ] ,
274
+ } ) ;
275
+ } ) ;
276
+ } ) ;
277
+
278
+ describe ( 'The unlinkResourceFromAttributionId function' , ( ) => {
279
+ it ( 'unlinks a manual attribution' , ( ) => {
280
+ const testManualData : AttributionData = {
281
+ attributions : {
282
+ [ testUuid ] : {
283
+ packageName : 'testpackage' ,
284
+ packageVersion : '2.0' ,
285
+ licenseText : 'Permission is hereby granted' ,
286
+ } ,
287
+ } ,
288
+ resourcesToAttributions : {
289
+ '/first/' : [ testUuid ] ,
290
+ } ,
291
+ attributionsToResources : {
292
+ [ testUuid ] : [ '/first/' ] ,
293
+ } ,
294
+ resourcesWithAttributedChildren : {
295
+ attributedChildren : {
296
+ '0' : new Set < number > ( ) . add ( 1 ) ,
297
+ } ,
298
+ pathsToIndices : {
299
+ '/' : 0 ,
300
+ '/first/' : 1 ,
301
+ } ,
302
+ paths : [ '/' , '/first/' ] ,
303
+ } ,
304
+ } ;
305
+
306
+ const newManualData : AttributionData = unlinkResourceFromAttributionId (
307
+ testManualData ,
308
+ '/first/' ,
309
+ testUuid ,
310
+ ) ;
311
+
312
+ expect ( newManualData . attributions ) . toEqual ( testManualData . attributions ) ;
313
+ expect ( isEmpty ( newManualData . resourcesToAttributions ) ) . toBe ( true ) ;
314
+ expect ( isEmpty ( newManualData . attributionsToResources ) ) . toBe ( true ) ;
315
+ expect ( newManualData . resourcesWithAttributedChildren ) . toEqual ( {
316
+ attributedChildren : { } ,
317
+ pathsToIndices : {
318
+ '/' : 0 ,
319
+ '/first/' : 1 ,
320
+ } ,
321
+ paths : [ '/' , '/first/' ] ,
322
+ } ) ;
323
+ } ) ;
324
+
325
+ it ( 'correctly maintains childrenFromAttributedResources' , ( ) => {
326
+ const testManualData : AttributionData = {
327
+ attributions : {
328
+ [ testUuid ] : {
329
+ packageName : 'testpackage' ,
330
+ packageVersion : '2.0' ,
331
+ licenseText : 'Permission is hereby granted' ,
332
+ } ,
333
+ } ,
334
+ resourcesToAttributions : {
335
+ '/first/' : [ testUuid ] ,
336
+ } ,
337
+ attributionsToResources : {
338
+ [ testUuid ] : [ '/first/' ] ,
339
+ } ,
340
+ resourcesWithAttributedChildren : {
341
+ attributedChildren : {
342
+ '0' : new Set < number > ( ) . add ( 1 ) ,
343
+ } ,
344
+ pathsToIndices : {
345
+ '/' : 0 ,
346
+ '/first/' : 1 ,
347
+ } ,
348
+ paths : [ '/' , '/first/' ] ,
349
+ } ,
350
+ } ;
351
+
352
+ const newManualData : AttributionData = unlinkResourceFromAttributionId (
353
+ testManualData ,
354
+ '/first/' ,
355
+ testUuid ,
356
+ ) ;
357
+
358
+ expect ( newManualData . resourcesWithAttributedChildren ) . toEqual ( {
359
+ attributedChildren : { } ,
360
+ pathsToIndices : {
361
+ '/' : 0 ,
362
+ '/first/' : 1 ,
363
+ } ,
364
+ paths : [ '/' , '/first/' ] ,
365
+ } ) ;
366
+ } ) ;
367
+ } ) ;
368
+
196
369
describe ( '_removeManualAttributionFromChildrenIfAllAreIdentical' , ( ) => {
197
370
it ( 'three matching' , ( ) => {
198
371
const testManualData : AttributionData = {
0 commit comments