diff --git a/src/adapters/localdb/models/offer.js b/src/adapters/localdb/models/offer.js index cbf8e96..280e87c 100644 --- a/src/adapters/localdb/models/offer.js +++ b/src/adapters/localdb/models/offer.js @@ -46,6 +46,7 @@ const Offer = new mongoose.Schema({ immutableDataCid: { type: String, default: null }, mutableDataCid: { type: String, default: null }, tokenIconUrl: { type: String, default: null }, + tokenData: { type: Object }, tokenCategories: { type: Array, default: [] }, tokenTags: { type: Array, default: [] }, userDataStr: { type: String }, // Token user data diff --git a/src/use-cases/offer/index.js b/src/use-cases/offer/index.js index a1a8f72..26806ac 100644 --- a/src/use-cases/offer/index.js +++ b/src/use-cases/offer/index.js @@ -148,6 +148,7 @@ class OfferUseCases { const immutableDataCid = tokenData.immutableData offerEntity.mutableDataCid = mutableDataCid offerEntity.immutableDataCid = immutableDataCid + offerEntity.tokenData = tokenData // Get the mutable data from the cid if it exists. if (mutableDataCid && typeof mutableDataCid === 'string') { @@ -1000,6 +1001,7 @@ class OfferUseCases { const immutableDataCid = tokenData.immutableData offer.mutableDataCid = mutableDataCid offer.immutableDataCid = immutableDataCid + offer.tokenData = tokenData // Get the mutable data from the cid if it exists. if (mutableDataCid && typeof mutableDataCid === 'string') { diff --git a/test/unit/use-cases/offer.use-case.unit.js b/test/unit/use-cases/offer.use-case.unit.js index 5491a0a..04f44a2 100644 --- a/test/unit/use-cases/offer.use-case.unit.js +++ b/test/unit/use-cases/offer.use-case.unit.js @@ -107,14 +107,14 @@ describe('#offer-use-case', () => { const result = await uut.createOffer(offerObj) assert.isFalse(result) }) - - it('should create offer with mutable data', async () => { + it('should create offer with token data', async () => { const tokenDataMock = mockData.nftTokenData01 const offerObj = mockData.offerMockData const mutableDataMock = mockData.mutableDataMock + const offerEntityMock = Object.assign({}, mockData.offerMockData.data) // Mock dependencies - // sandbox.stub(uut.adapters.wallet.bchWallet, 'utxoIsValid').resolves(false) + sandbox.stub(uut.offerEntity, 'validate').returns(offerEntityMock) sandbox.stub(uut, 'findOfferByTxid').throws(new Error('offer not found')) sandbox.stub(uut.retryQueue, 'addToQueue') .onCall(0).resolves({}) // Utxo Status call @@ -123,6 +123,31 @@ describe('#offer-use-case', () => { const result = await uut.createOffer(offerObj) assert.isTrue(result) + console.log('offerEntityMock', offerEntityMock) + assert.property(offerEntityMock, 'tokenData') + }) + it('should create offer with mutable data', async () => { + const tokenDataMock = mockData.nftTokenData01 + const offerObj = mockData.offerMockData + const mutableDataMock = mockData.mutableDataMock + const offerEntityMock = Object.assign({}, mockData.offerMockData.data) + + // Mock dependencies + sandbox.stub(uut.offerEntity, 'validate').returns(offerEntityMock) + sandbox.stub(uut, 'findOfferByTxid').throws(new Error('offer not found')) + sandbox.stub(uut.retryQueue, 'addToQueue') + .onCall(0).resolves({}) // Utxo Status call + .onCall(1).resolves(tokenDataMock) // Token Data call + .onCall(2).resolves(mutableDataMock) + + const result = await uut.createOffer(offerObj) + assert.isTrue(result) + console.log('offerEntityMock', offerEntityMock) + + assert.property(offerEntityMock, 'tokenIconUrl') + assert.property(offerEntityMock, 'tokenCategories') + assert.property(offerEntityMock, 'tokenTags') + assert.property(offerEntityMock, 'lastUpdatedTokenData') }) it('should skip userData stringify error', async () => { @@ -1106,6 +1131,12 @@ describe('#offer-use-case', () => { const offer = await uut.syncOfferMutableData('tokenId') assert.isObject(offer) assert.isNumber(offer.lastUpdatedTokenData) + + assert.property(offer, 'tokenData') + assert.property(offer, 'tokenIconUrl') + assert.property(offer, 'tokenCategories') + assert.property(offer, 'tokenTags') + assert.property(offer, 'lastUpdatedTokenData') }) it('should skip userData stringify error', async () => {