Skip to content

Commit 2a7e16b

Browse files
feat: Update collection when migration is incomplete (#3167)
* feat: Update collection when migration is incomplete * fix: Remove comments
1 parent 9d1c884 commit 2a7e16b

File tree

2 files changed

+73
-13
lines changed

2 files changed

+73
-13
lines changed

src/modules/thirdParty/sagas.spec.ts

+57-11
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
import uuidv4 from 'uuid/v4'
2+
import { ContractData, ContractName, getContract } from 'decentraland-transactions'
3+
import { ChainId, Network } from '@dcl/schemas'
24
import { MerkleDistributorInfo } from '@dcl/content-hash-tree/dist/types'
35
import { CatalystClient } from 'dcl-catalyst-client'
46
import { DeploymentPreparationData } from 'dcl-catalyst-client/dist/client/utils/DeploymentBuilder'
57
import { call } from '@redux-saga/core/effects'
68
import * as matchers from 'redux-saga-test-plan/matchers'
79
import { expectSaga } from 'redux-saga-test-plan'
810
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'
1012
import { AuthIdentity, Authenticator, AuthLinkType } from '@dcl/crypto'
1113
import { ToastType } from 'decentraland-ui'
1214
import { SHOW_TOAST } from 'decentraland-dapps/dist/modules/toast/actions'
@@ -55,14 +57,13 @@ import {
5557
ThirdPartyError
5658
} from 'modules/collection/utils'
5759
import { updateThirdPartyActionProgress } from 'modules/ui/thirdparty/action'
60+
import { FETCH_COLLECTION_SUCCESS, fetchCollectionRequest } from 'modules/collection/actions'
5861
import { PublishThirdPartyCollectionModalStep, ThirdPartyAction } from 'modules/ui/thirdparty/types'
5962
import { Item } from 'modules/item/types'
63+
import { PublishButtonAction } from 'components/ThirdPartyCollectionDetailPage/CollectionPublishButton/CollectionPublishButton.types'
6064
import { thirdPartySaga } from './sagas'
6165
import { getPublishItemsSignature } from './utils'
6266
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'
6667

6768
jest.mock('modules/item/export')
6869
jest.mock('@dcl/crypto')
@@ -313,7 +314,7 @@ describe('when pushing changes to third party items', () => {
313314
let item: Item
314315
let itemCurations: ItemCuration[]
315316
beforeEach(() => {
316-
collection = { name: 'valid collection name', id: uuidv4() } as Collection
317+
collection = { name: 'valid collection name', id: uuidv4(), isMappingComplete: true } as Collection
317318
item = {
318319
...mockedItem,
319320
collectionId: collection.id
@@ -338,6 +339,7 @@ describe('when pushing changes to third party items', () => {
338339
return expectSaga(thirdPartySaga, mockBuilder, mockCatalystClient)
339340
.provide([
340341
[select(getItemCurations, item.collectionId), itemCurations],
342+
[select(getCollection, item.collectionId), collection],
341343
[call([mockBuilder, mockBuilder.updateItemCurationStatus], item.id, itemCurations[0].status), throwError(new Error('Error'))]
342344
])
343345
.put(pushChangesThirdPartyItemsFailure('Some item curations were not pushed'))
@@ -352,7 +354,7 @@ describe('when pushing changes to third party items', () => {
352354
describe('when both api requests succeed', () => {
353355
let updatedItemCurations: ItemCuration[]
354356
beforeEach(() => {
355-
collection = { name: 'valid collection name', id: uuidv4() } as Collection
357+
collection = { name: 'valid collection name', id: uuidv4(), isMappingComplete: true } as Collection
356358
itemCurations = [
357359
{
358360
id: 'id',
@@ -393,10 +395,32 @@ describe('when pushing changes to third party items', () => {
393395
;(mockBuilder.pushItemCuration as jest.Mock).mockResolvedValue(updatedItemCurations[1])
394396
})
395397

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+
396417
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', () => {
397418
const anotherItem = { ...mockedItem, id: 'anotherItemId' }
398419
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+
])
400424
.put(updateThirdPartyActionProgress(100, ThirdPartyAction.PUSH_CHANGES))
401425
.put(updateThirdPartyActionProgress(0, ThirdPartyAction.PUSH_CHANGES)) // resets the progress
402426
.put(pushChangesThirdPartyItemsSuccess(item.collectionId!, updatedItemCurations))
@@ -426,7 +450,7 @@ describe('when publishing & pushing changes to third party items', () => {
426450
let salt: string
427451
let qty: number
428452
beforeEach(() => {
429-
collection = { name: 'valid collection name', id: uuidv4() } as Collection
453+
collection = { name: 'valid collection name', id: uuidv4(), isMappingComplete: true } as Collection
430454
item = {
431455
...mockedItem,
432456
collectionId: collection.id
@@ -462,7 +486,8 @@ describe('when publishing & pushing changes to third party items', () => {
462486
[
463487
call([mockBuilder, mockBuilder.publishTPCollection], item.collectionId!, [item.id], { signature, qty, salt }),
464488
throwError(new Error(errorMessage))
465-
]
489+
],
490+
[select(getCollection, item.collectionId), collection]
466491
])
467492
.put(closeModal('PublishThirdPartyCollectionModal'))
468493
.put.like({ action: { type: SHOW_TOAST, payload: { toast: { type: ToastType.ERROR } } } })
@@ -482,7 +507,8 @@ describe('when publishing & pushing changes to third party items', () => {
482507
return expectSaga(thirdPartySaga, mockBuilder, mockCatalystClient)
483508
.provide([
484509
[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]
486512
])
487513
.put(publishAndPushChangesThirdPartyItemsFailure(errorMessage))
488514
.dispatch(publishAndPushChangesThirdPartyItemsRequest(thirdParty, itemsToPublish, [itemWithChanges]))
@@ -507,11 +533,31 @@ describe('when publishing & pushing changes to third party items', () => {
507533
;(mockBuilder.pushItemCuration as jest.Mock).mockResolvedValue(updatedItemCurations[0])
508534
})
509535

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+
510555
it('should put the publish & push changes success action, the fetch available slots request and reset the progress', () => {
511556
return expectSaga(thirdPartySaga, mockBuilder, mockCatalystClient)
512557
.provide([
513558
[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]
515561
])
516562
.put(updateThirdPartyActionProgress(100, ThirdPartyAction.PUSH_CHANGES)) // resets the progress
517563
.put(publishAndPushChangesThirdPartyItemsSuccess(item.collectionId!, publishResponse, [...itemCurations, updatedItemCurations[0]]))

src/modules/thirdParty/sagas.ts

+16-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import PQueue from 'p-queue'
22
import { channel } from 'redux-saga'
3-
import { takeLatest, takeEvery, call, put, select } from 'redux-saga/effects'
3+
import { takeLatest, takeEvery, call, put, select, race, take } from 'redux-saga/effects'
44
import { Contract, providers } from 'ethers'
55
import { Authenticator, AuthIdentity } from '@dcl/crypto'
66
import { ChainId, Network } from '@dcl/schemas'
@@ -31,7 +31,9 @@ import { CurationStatus } from 'modules/curations/types'
3131
import { getIdentity } from 'modules/identity/utils'
3232
import { buildTPItemEntity } from 'modules/item/export'
3333
import { waitForTx } from 'modules/transaction/utils'
34-
import { PublishThirdPartyCollectionModalStep, ThirdPartyAction } from 'modules/ui/thirdparty/types'
34+
import { ThirdPartyAction, PublishThirdPartyCollectionModalStep } from 'modules/ui/thirdparty/types'
35+
import { getCollection } from 'modules/collection/selectors'
36+
import { FETCH_COLLECTION_FAILURE, FETCH_COLLECTION_SUCCESS, fetchCollectionRequest } from 'modules/collection/actions'
3537
import {
3638
FETCH_THIRD_PARTIES_REQUEST,
3739
fetchThirdPartiesRequest,
@@ -241,7 +243,13 @@ export function* thirdPartySaga(builder: BuilderAPI, catalystClient: CatalystCli
241243
const { items } = action.payload
242244
try {
243245
const collectionId = getCollectionId(items)
246+
const collection: ReturnType<typeof getCollection> = yield select(getCollection, collectionId)
244247
const newItemsCurations: ItemCuration[] = yield call(pushChangesToThirdPartyItems, items)
248+
// Update collections that are not complete
249+
if (!collection?.isMappingComplete) {
250+
yield put(fetchCollectionRequest(collectionId))
251+
yield race({ success: take(FETCH_COLLECTION_SUCCESS), failure: take(FETCH_COLLECTION_FAILURE) })
252+
}
245253
yield put(pushChangesThirdPartyItemsSuccess(collectionId, newItemsCurations))
246254
yield put(
247255
openModal('PublishThirdPartyCollectionModal', {
@@ -261,6 +269,7 @@ export function* thirdPartySaga(builder: BuilderAPI, catalystClient: CatalystCli
261269
function* handlePublishAndPushChangesThirdPartyItemRequest(action: PublishAndPushChangesThirdPartyItemsRequestAction) {
262270
const { thirdParty, itemsToPublish, itemsWithChanges } = action.payload
263271
const collectionId = getCollectionId(itemsToPublish)
272+
const collection: ReturnType<typeof getCollection> = yield select(getCollection, collectionId)
264273
// We need to execute these two methods in sequence, because the push changes will create a new curation if there was one already approved.
265274
// It will create them with status PENDING, so the publish will fail if it's executed after that event.
266275
// Publish items
@@ -274,6 +283,11 @@ export function* thirdPartySaga(builder: BuilderAPI, catalystClient: CatalystCli
274283
const resultFromPushChanges: ItemCuration[] = yield call(pushChangesToThirdPartyItems, itemsWithChanges)
275284
const newItemCurations = [...resultFromPublish.newItemCurations, ...resultFromPushChanges]
276285

286+
// Update collections that are not complete
287+
if (!collection?.isMappingComplete) {
288+
yield put(fetchCollectionRequest(collectionId))
289+
yield race({ success: take(FETCH_COLLECTION_SUCCESS), failure: take(FETCH_COLLECTION_FAILURE) })
290+
}
277291
yield put(publishAndPushChangesThirdPartyItemsSuccess(collectionId, resultFromPublish.newItems, newItemCurations))
278292
yield put(fetchThirdPartyAvailableSlotsRequest(thirdParty.id)) // re-fetch available slots after publishing
279293
yield put(

0 commit comments

Comments
 (0)