1
1
import uuidv4 from 'uuid/v4'
2
+ import { ContractData , ContractName , getContract } from 'decentraland-transactions'
3
+ import { ChainId , Network } from '@dcl/schemas'
2
4
import { MerkleDistributorInfo } from '@dcl/content-hash-tree/dist/types'
3
5
import { CatalystClient } from 'dcl-catalyst-client'
4
6
import { DeploymentPreparationData } from 'dcl-catalyst-client/dist/client/utils/DeploymentBuilder'
5
7
import { call } from '@redux-saga/core/effects'
6
8
import * as matchers from 'redux-saga-test-plan/matchers'
7
9
import { expectSaga } from 'redux-saga-test-plan'
8
10
import { throwError } from 'redux-saga-test-plan/providers'
9
- import { select } from 'redux-saga-test-plan/matchers'
11
+ import { select , take } from 'redux-saga-test-plan/matchers'
10
12
import { AuthIdentity , Authenticator , AuthLinkType } from '@dcl/crypto'
11
13
import { ToastType } from 'decentraland-ui'
12
14
import { SHOW_TOAST } from 'decentraland-dapps/dist/modules/toast/actions'
@@ -55,14 +57,13 @@ import {
55
57
ThirdPartyError
56
58
} from 'modules/collection/utils'
57
59
import { updateThirdPartyActionProgress } from 'modules/ui/thirdparty/action'
60
+ import { FETCH_COLLECTION_SUCCESS , fetchCollectionRequest } from 'modules/collection/actions'
58
61
import { PublishThirdPartyCollectionModalStep , ThirdPartyAction } from 'modules/ui/thirdparty/types'
59
62
import { Item } from 'modules/item/types'
63
+ import { PublishButtonAction } from 'components/ThirdPartyCollectionDetailPage/CollectionPublishButton/CollectionPublishButton.types'
60
64
import { thirdPartySaga } from './sagas'
61
65
import { getPublishItemsSignature } from './utils'
62
66
import { getThirdParty } from './selectors'
63
- import { ContractData , ContractName , getContract } from 'decentraland-transactions'
64
- import { ChainId , Network } from '@dcl/schemas'
65
- import { PublishButtonAction } from 'components/ThirdPartyCollectionDetailPage/CollectionPublishButton/CollectionPublishButton.types'
66
67
67
68
jest . mock ( 'modules/item/export' )
68
69
jest . mock ( '@dcl/crypto' )
@@ -313,7 +314,7 @@ describe('when pushing changes to third party items', () => {
313
314
let item : Item
314
315
let itemCurations : ItemCuration [ ]
315
316
beforeEach ( ( ) => {
316
- collection = { name : 'valid collection name' , id : uuidv4 ( ) } as Collection
317
+ collection = { name : 'valid collection name' , id : uuidv4 ( ) , isMappingComplete : true } as Collection
317
318
item = {
318
319
...mockedItem ,
319
320
collectionId : collection . id
@@ -338,6 +339,7 @@ describe('when pushing changes to third party items', () => {
338
339
return expectSaga ( thirdPartySaga , mockBuilder , mockCatalystClient )
339
340
. provide ( [
340
341
[ select ( getItemCurations , item . collectionId ) , itemCurations ] ,
342
+ [ select ( getCollection , item . collectionId ) , collection ] ,
341
343
[ call ( [ mockBuilder , mockBuilder . updateItemCurationStatus ] , item . id , itemCurations [ 0 ] . status ) , throwError ( new Error ( 'Error' ) ) ]
342
344
] )
343
345
. put ( pushChangesThirdPartyItemsFailure ( 'Some item curations were not pushed' ) )
@@ -352,7 +354,7 @@ describe('when pushing changes to third party items', () => {
352
354
describe ( 'when both api requests succeed' , ( ) => {
353
355
let updatedItemCurations : ItemCuration [ ]
354
356
beforeEach ( ( ) => {
355
- collection = { name : 'valid collection name' , id : uuidv4 ( ) } as Collection
357
+ collection = { name : 'valid collection name' , id : uuidv4 ( ) , isMappingComplete : true } as Collection
356
358
itemCurations = [
357
359
{
358
360
id : 'id' ,
@@ -393,10 +395,32 @@ describe('when pushing changes to third party items', () => {
393
395
; ( mockBuilder . pushItemCuration as jest . Mock ) . mockResolvedValue ( updatedItemCurations [ 1 ] )
394
396
} )
395
397
398
+ describe ( 'and the collection does not have its mapping complete' , ( ) => {
399
+ beforeEach ( ( ) => {
400
+ collection = { name : 'valid collection name' , id : uuidv4 ( ) , isMappingComplete : false } as Collection
401
+ } )
402
+
403
+ it ( 'should put an action to re fetch the collection' , ( ) => {
404
+ const anotherItem = { ...mockedItem , id : 'anotherItemId' }
405
+ return expectSaga ( thirdPartySaga , mockBuilder , mockCatalystClient )
406
+ . provide ( [
407
+ [ select ( getItemCurations , item . collectionId ) , itemCurations ] ,
408
+ [ select ( getCollection , item . collectionId ) , collection ] ,
409
+ [ take ( FETCH_COLLECTION_SUCCESS ) , undefined ]
410
+ ] )
411
+ . put ( fetchCollectionRequest ( item . collectionId ?? '' ) )
412
+ . dispatch ( pushChangesThirdPartyItemsRequest ( [ item , anotherItem ] ) )
413
+ . run ( { silenceTimeout : true } )
414
+ } )
415
+ } )
416
+
396
417
it ( 'should put the push changes success action with the updated item curations, open the PublishThirdPartyCollectionModal modal with the success step and reset the progress' , ( ) => {
397
418
const anotherItem = { ...mockedItem , id : 'anotherItemId' }
398
419
return expectSaga ( thirdPartySaga , mockBuilder , mockCatalystClient )
399
- . provide ( [ [ select ( getItemCurations , item . collectionId ) , itemCurations ] ] )
420
+ . provide ( [
421
+ [ select ( getItemCurations , item . collectionId ) , itemCurations ] ,
422
+ [ select ( getCollection , item . collectionId ) , collection ]
423
+ ] )
400
424
. put ( updateThirdPartyActionProgress ( 100 , ThirdPartyAction . PUSH_CHANGES ) )
401
425
. put ( updateThirdPartyActionProgress ( 0 , ThirdPartyAction . PUSH_CHANGES ) ) // resets the progress
402
426
. put ( pushChangesThirdPartyItemsSuccess ( item . collectionId ! , updatedItemCurations ) )
@@ -426,7 +450,7 @@ describe('when publishing & pushing changes to third party items', () => {
426
450
let salt : string
427
451
let qty : number
428
452
beforeEach ( ( ) => {
429
- collection = { name : 'valid collection name' , id : uuidv4 ( ) } as Collection
453
+ collection = { name : 'valid collection name' , id : uuidv4 ( ) , isMappingComplete : true } as Collection
430
454
item = {
431
455
...mockedItem ,
432
456
collectionId : collection . id
@@ -462,7 +486,8 @@ describe('when publishing & pushing changes to third party items', () => {
462
486
[
463
487
call ( [ mockBuilder , mockBuilder . publishTPCollection ] , item . collectionId ! , [ item . id ] , { signature, qty, salt } ) ,
464
488
throwError ( new Error ( errorMessage ) )
465
- ]
489
+ ] ,
490
+ [ select ( getCollection , item . collectionId ) , collection ]
466
491
] )
467
492
. put ( closeModal ( 'PublishThirdPartyCollectionModal' ) )
468
493
. put . like ( { action : { type : SHOW_TOAST , payload : { toast : { type : ToastType . ERROR } } } } )
@@ -482,7 +507,8 @@ describe('when publishing & pushing changes to third party items', () => {
482
507
return expectSaga ( thirdPartySaga , mockBuilder , mockCatalystClient )
483
508
. provide ( [
484
509
[ call ( getPublishItemsSignature , thirdParty . id , 1 ) , { signature, salt } ] ,
485
- [ select ( getItemCurations , item . collectionId ) , itemCurations ]
510
+ [ select ( getItemCurations , item . collectionId ) , itemCurations ] ,
511
+ [ select ( getCollection , item . collectionId ) , collection ]
486
512
] )
487
513
. put ( publishAndPushChangesThirdPartyItemsFailure ( errorMessage ) )
488
514
. dispatch ( publishAndPushChangesThirdPartyItemsRequest ( thirdParty , itemsToPublish , [ itemWithChanges ] ) )
@@ -507,11 +533,31 @@ describe('when publishing & pushing changes to third party items', () => {
507
533
; ( mockBuilder . pushItemCuration as jest . Mock ) . mockResolvedValue ( updatedItemCurations [ 0 ] )
508
534
} )
509
535
536
+ describe ( 'and the collection does not have its mapping complete' , ( ) => {
537
+ beforeEach ( ( ) => {
538
+ collection = { name : 'valid collection name' , id : uuidv4 ( ) , isMappingComplete : false } as Collection
539
+ } )
540
+
541
+ it ( 'should put an action to re fetch the collection' , ( ) => {
542
+ return expectSaga ( thirdPartySaga , mockBuilder , mockCatalystClient )
543
+ . provide ( [
544
+ [ call ( getPublishItemsSignature , thirdParty . id , 1 ) , { signature, salt } ] ,
545
+ [ select ( getItemCurations , item . collectionId ) , itemCurations ] ,
546
+ [ select ( getCollection , item . collectionId ) , collection ] ,
547
+ [ take ( FETCH_COLLECTION_SUCCESS ) , undefined ]
548
+ ] )
549
+ . put ( fetchCollectionRequest ( item . collectionId ?? '' ) )
550
+ . dispatch ( publishAndPushChangesThirdPartyItemsRequest ( thirdParty , itemsToPublish , [ itemWithChanges ] ) )
551
+ . run ( { silenceTimeout : true } )
552
+ } )
553
+ } )
554
+
510
555
it ( 'should put the publish & push changes success action, the fetch available slots request and reset the progress' , ( ) => {
511
556
return expectSaga ( thirdPartySaga , mockBuilder , mockCatalystClient )
512
557
. provide ( [
513
558
[ call ( getPublishItemsSignature , thirdParty . id , 1 ) , { signature, salt } ] ,
514
- [ select ( getItemCurations , item . collectionId ) , itemCurations ]
559
+ [ select ( getItemCurations , item . collectionId ) , itemCurations ] ,
560
+ [ select ( getCollection , item . collectionId ) , collection ]
515
561
] )
516
562
. put ( updateThirdPartyActionProgress ( 100 , ThirdPartyAction . PUSH_CHANGES ) ) // resets the progress
517
563
. put ( publishAndPushChangesThirdPartyItemsSuccess ( item . collectionId ! , publishResponse , [ ...itemCurations , updatedItemCurations [ 0 ] ] ) )
0 commit comments