mirror of
https://github.com/Permissionless-Software-Foundation/bch-dex.git
synced 2026-09-21 16:52:00 -07:00
feat(offer): Added tokenData to offer model
This commit is contained in:
@@ -46,6 +46,7 @@ const Offer = new mongoose.Schema({
|
|||||||
immutableDataCid: { type: String, default: null },
|
immutableDataCid: { type: String, default: null },
|
||||||
mutableDataCid: { type: String, default: null },
|
mutableDataCid: { type: String, default: null },
|
||||||
tokenIconUrl: { type: String, default: null },
|
tokenIconUrl: { type: String, default: null },
|
||||||
|
tokenData: { type: Object },
|
||||||
tokenCategories: { type: Array, default: [] },
|
tokenCategories: { type: Array, default: [] },
|
||||||
tokenTags: { type: Array, default: [] },
|
tokenTags: { type: Array, default: [] },
|
||||||
userDataStr: { type: String }, // Token user data
|
userDataStr: { type: String }, // Token user data
|
||||||
|
|||||||
@@ -148,6 +148,7 @@ class OfferUseCases {
|
|||||||
const immutableDataCid = tokenData.immutableData
|
const immutableDataCid = tokenData.immutableData
|
||||||
offerEntity.mutableDataCid = mutableDataCid
|
offerEntity.mutableDataCid = mutableDataCid
|
||||||
offerEntity.immutableDataCid = immutableDataCid
|
offerEntity.immutableDataCid = immutableDataCid
|
||||||
|
offerEntity.tokenData = tokenData
|
||||||
|
|
||||||
// Get the mutable data from the cid if it exists.
|
// Get the mutable data from the cid if it exists.
|
||||||
if (mutableDataCid && typeof mutableDataCid === 'string') {
|
if (mutableDataCid && typeof mutableDataCid === 'string') {
|
||||||
@@ -1000,6 +1001,7 @@ class OfferUseCases {
|
|||||||
const immutableDataCid = tokenData.immutableData
|
const immutableDataCid = tokenData.immutableData
|
||||||
offer.mutableDataCid = mutableDataCid
|
offer.mutableDataCid = mutableDataCid
|
||||||
offer.immutableDataCid = immutableDataCid
|
offer.immutableDataCid = immutableDataCid
|
||||||
|
offer.tokenData = tokenData
|
||||||
|
|
||||||
// Get the mutable data from the cid if it exists.
|
// Get the mutable data from the cid if it exists.
|
||||||
if (mutableDataCid && typeof mutableDataCid === 'string') {
|
if (mutableDataCid && typeof mutableDataCid === 'string') {
|
||||||
|
|||||||
@@ -107,14 +107,14 @@ describe('#offer-use-case', () => {
|
|||||||
const result = await uut.createOffer(offerObj)
|
const result = await uut.createOffer(offerObj)
|
||||||
assert.isFalse(result)
|
assert.isFalse(result)
|
||||||
})
|
})
|
||||||
|
it('should create offer with token data', async () => {
|
||||||
it('should create offer with mutable data', async () => {
|
|
||||||
const tokenDataMock = mockData.nftTokenData01
|
const tokenDataMock = mockData.nftTokenData01
|
||||||
const offerObj = mockData.offerMockData
|
const offerObj = mockData.offerMockData
|
||||||
const mutableDataMock = mockData.mutableDataMock
|
const mutableDataMock = mockData.mutableDataMock
|
||||||
|
const offerEntityMock = Object.assign({}, mockData.offerMockData.data)
|
||||||
|
|
||||||
// Mock dependencies
|
// 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, 'findOfferByTxid').throws(new Error('offer not found'))
|
||||||
sandbox.stub(uut.retryQueue, 'addToQueue')
|
sandbox.stub(uut.retryQueue, 'addToQueue')
|
||||||
.onCall(0).resolves({}) // Utxo Status call
|
.onCall(0).resolves({}) // Utxo Status call
|
||||||
@@ -123,6 +123,31 @@ describe('#offer-use-case', () => {
|
|||||||
|
|
||||||
const result = await uut.createOffer(offerObj)
|
const result = await uut.createOffer(offerObj)
|
||||||
assert.isTrue(result)
|
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 () => {
|
it('should skip userData stringify error', async () => {
|
||||||
@@ -1106,6 +1131,12 @@ describe('#offer-use-case', () => {
|
|||||||
const offer = await uut.syncOfferMutableData('tokenId')
|
const offer = await uut.syncOfferMutableData('tokenId')
|
||||||
assert.isObject(offer)
|
assert.isObject(offer)
|
||||||
assert.isNumber(offer.lastUpdatedTokenData)
|
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 () => {
|
it('should skip userData stringify error', async () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user