1
- import { ChainId } from '@dcl/schemas'
1
+ import { ChainId , ContractAddress , ContractNetwork , Mapping , MappingType } from '@dcl/schemas'
2
2
import { saveCollectionSuccess } from 'modules/collection/actions'
3
3
import { Collection } from 'modules/collection/types'
4
+ import {
5
+ publishAndPushChangesThirdPartyItemsSuccess ,
6
+ PublishAndPushChangesThirdPartyItemsSuccessAction ,
7
+ publishThirdPartyItemsSuccess ,
8
+ PublishThirdPartyItemsSuccessAction ,
9
+ pushChangesThirdPartyItemsSuccess ,
10
+ PushChangesThirdPartyItemsSuccessAction
11
+ } from 'modules/thirdParty/actions'
12
+ import { PaginatedResource } from 'lib/api/pagination'
13
+ import { CurationStatus } from 'modules/curations/types'
14
+ import { ItemCuration } from 'modules/curations/itemCuration/types'
4
15
import { getChainIdByNetwork } from 'decentraland-dapps/dist/lib/eth'
5
16
import {
6
17
clearSaveMultipleItems ,
@@ -19,7 +30,6 @@ import {
19
30
} from './actions'
20
31
import { INITIAL_STATE , itemReducer , ItemState } from './reducer'
21
32
import { Item } from './types'
22
- import { PaginatedResource } from 'lib/api/pagination'
23
33
import { toItemObject } from './utils'
24
34
25
35
jest . mock ( 'decentraland-dapps/dist/lib/eth' )
@@ -34,8 +44,14 @@ let itemsMap: Record<string, Item>
34
44
let fileNames : string [ ]
35
45
36
46
beforeEach ( ( ) => {
47
+ const mappings : Partial < Record < ContractNetwork , Record < ContractAddress , Mapping [ ] > > > = {
48
+ [ ContractNetwork . AMOY ] : { '0x0' : [ { type : MappingType . ANY } ] }
49
+ }
37
50
state = { ...INITIAL_STATE }
38
- items = [ { id : 'anItemId' } as Item , { id : 'anotherItemId' } as Item ]
51
+ items = [
52
+ { id : 'anItemId' , isPublished : false , mappings : mappings } as Item ,
53
+ { id : 'anotherItemId' , isPublished : false , mappings : null } as Item
54
+ ]
39
55
itemsMap = {
40
56
[ items [ 0 ] . id ] : items [ 0 ] ,
41
57
[ items [ 1 ] . id ] : items [ 1 ]
@@ -422,3 +438,71 @@ describe('when an action of type FETCH_ORPHAN_ITEM_FAILURE is called', () => {
422
438
} )
423
439
} )
424
440
} )
441
+
442
+ describe . each ( [
443
+ [ 'pushing changes and publishing third party items' , publishAndPushChangesThirdPartyItemsSuccess ] ,
444
+ [ 'pushing changes third party items' , pushChangesThirdPartyItemsSuccess ] ,
445
+ [ 'publishing third party items' , publishThirdPartyItemsSuccess ]
446
+ ] ) ( 'when reducing the successful action of %s' , ( _ , fn ) => {
447
+ let action :
448
+ | PublishThirdPartyItemsSuccessAction
449
+ | PublishAndPushChangesThirdPartyItemsSuccessAction
450
+ | PushChangesThirdPartyItemsSuccessAction
451
+
452
+ beforeEach ( ( ) => {
453
+ const curations : ItemCuration [ ] = items . map ( item => ( {
454
+ itemId : item . id ,
455
+ contentHash : 'aHash' ,
456
+ id : 'aCurationId' ,
457
+ updatedAt : 0 ,
458
+ createdAt : 0 ,
459
+ status : CurationStatus . PENDING
460
+ } ) )
461
+
462
+ switch ( fn ) {
463
+ case pushChangesThirdPartyItemsSuccess :
464
+ action = pushChangesThirdPartyItemsSuccess ( 'aCollectionId' , curations )
465
+ break
466
+ case publishThirdPartyItemsSuccess :
467
+ action = publishThirdPartyItemsSuccess ( 'aThirdPartyId' , 'aCollectionId' , items , curations )
468
+ break
469
+ case publishAndPushChangesThirdPartyItemsSuccess :
470
+ action = publishAndPushChangesThirdPartyItemsSuccess ( 'aThirdParty' , items , curations )
471
+ break
472
+ }
473
+ } )
474
+
475
+ describe ( 'and the items are not in the state' , ( ) => {
476
+ beforeEach ( ( ) => {
477
+ state = {
478
+ ...INITIAL_STATE
479
+ }
480
+ } )
481
+
482
+ it ( 'should return the state as is' , ( ) => {
483
+ expect ( itemReducer ( state , action ) ) . toEqual ( state )
484
+ } )
485
+ } )
486
+
487
+ describe ( 'and the items are in the state' , ( ) => {
488
+ beforeEach ( ( ) => {
489
+ state = {
490
+ ...INITIAL_STATE ,
491
+ data : items . reduce ( ( acc , item ) => ( { ...acc , [ item . id ] : { ...item , isPublished : false , isMappingComplete : ! ! item . mappings } } ) , { } )
492
+ }
493
+ } )
494
+
495
+ it ( "should set the items as published and set the isMappingComplete property in accordance to the item's mapping" , ( ) => {
496
+ expect ( itemReducer ( state , action ) ) . toEqual ( {
497
+ ...state ,
498
+ data : items . reduce (
499
+ ( acc , item ) => ( {
500
+ ...acc ,
501
+ [ item . id ] : { ...item , isPublished : true , isMappingComplete : ! ! item . mappings }
502
+ } ) ,
503
+ { }
504
+ )
505
+ } )
506
+ } )
507
+ } )
508
+ } )
0 commit comments