mirror of
https://github.com/Permissionless-Software-Foundation/bch-dex.git
synced 2026-09-21 16:52:00 -07:00
feat(update): Added Update button REST endpoint
This commit is contained in:
@@ -852,6 +852,18 @@ describe('#offer-use-case', () => {
|
||||
assert.equal(result, 'N/A')
|
||||
})
|
||||
|
||||
it('should return N/A on axios error', async () => {
|
||||
// Mock dependencies
|
||||
const mock = Object.assign({}, mockData.offerMockData.data)
|
||||
sandbox.stub(uut.orderUseCase, 'findOrderByUtxo').resolves(mock)
|
||||
// sandbox.stub(uut.adapters.wallet.bchWallet, 'utxoIsValid').throws(new Error('test error'))
|
||||
const axiosErr = new Error('axios err')
|
||||
axiosErr.isAxiosError = true
|
||||
sandbox.stub(uut.retryQueue, 'addToQueue').throws(axiosErr)
|
||||
|
||||
const result = await uut.acceptCounterOffer({ data: { /** .... */ } })
|
||||
assert.equal(result, 'N/A')
|
||||
})
|
||||
it('should return if utxo can not be validated', async () => {
|
||||
// Mock dependencies
|
||||
const mock = Object.assign({}, mockData.offerMockData.data)
|
||||
@@ -1010,4 +1022,110 @@ describe('#offer-use-case', () => {
|
||||
assert.notEqual('N/A')
|
||||
})
|
||||
})
|
||||
|
||||
describe('#syncOfferMutableData', () => {
|
||||
it('should throw error if tokenId is not provided!', async () => {
|
||||
try {
|
||||
await uut.syncOfferMutableData()
|
||||
assert.fail('unexpected code path')
|
||||
} catch (err) {
|
||||
assert.include(err.message, 'tokenId must be a string!')
|
||||
}
|
||||
})
|
||||
it('should throw error if tokenId is not found!', async () => {
|
||||
try {
|
||||
// Mock dependencies
|
||||
sandbox.stub(uut.OfferModel, 'findOne').resolves(null)
|
||||
|
||||
await uut.syncOfferMutableData('tokenId')
|
||||
assert.fail('unexpected code path')
|
||||
} catch (err) {
|
||||
assert.include(err.message, 'Associated offer not found!')
|
||||
}
|
||||
})
|
||||
|
||||
it('should return current data if lastUpdatedTokenData is less than 5 minutes', async () => {
|
||||
// Mock dependencies
|
||||
const lastUpdatedTokenData = new Date().getTime()
|
||||
const offerMock = Object.assign({}, mockData.offerMockData)
|
||||
offerMock.lastUpdatedTokenData = lastUpdatedTokenData
|
||||
// stub
|
||||
sandbox.stub(uut.OfferModel, 'findOne').returns(offerMock)
|
||||
const spy = sandbox.stub(uut.retryQueue, 'addToQueue').resolves(true)
|
||||
|
||||
const offer = await uut.syncOfferMutableData('tokenId')
|
||||
|
||||
assert.isObject(offer)
|
||||
assert.isTrue(spy.notCalled, 'it should not call retryQueue functions.')
|
||||
})
|
||||
it('should sync offer', async () => {
|
||||
// create a timestamp 6 minutes in the past
|
||||
|
||||
// Create offer mock
|
||||
const offerMock = Object.assign({}, mockData.offerMockData)
|
||||
offerMock.save = () => { }
|
||||
|
||||
// Stub functions
|
||||
sandbox.stub(uut.OfferModel, 'findOne').returns(offerMock)
|
||||
sandbox.stub(uut.retryQueue, 'addToQueue')
|
||||
.onCall(0).resolves(mockData.simpleNftTokenData01) // Token Data call
|
||||
.onCall(1).resolves(mockData.mutableDataMock)
|
||||
|
||||
const offer = await uut.syncOfferMutableData('tokenId')
|
||||
assert.isObject(offer)
|
||||
assert.isNumber(offer.lastUpdatedTokenData)
|
||||
})
|
||||
|
||||
it('should skip userData stringify error', async () => {
|
||||
// create mutable data mock
|
||||
const mutableDataMock = mockData.mutableDataMock
|
||||
mutableDataMock.userData = { n: 10n }
|
||||
|
||||
// create offer mock
|
||||
const offerMock = Object.assign({}, mockData.offerMockData)
|
||||
offerMock.save = () => { }
|
||||
|
||||
// Stub functions
|
||||
sandbox.stub(uut.OfferModel, 'findOne').returns(offerMock)
|
||||
sandbox.stub(uut.retryQueue, 'addToQueue')
|
||||
.onCall(0).resolves(mockData.simpleNftTokenData01) // Token Data call
|
||||
.onCall(1).resolves(mutableDataMock)
|
||||
|
||||
const offer = await uut.syncOfferMutableData('tokenId')
|
||||
|
||||
assert.isObject(offer)
|
||||
assert.isNumber(offer.lastUpdatedTokenData)
|
||||
})
|
||||
|
||||
it('should handle error getting token data', async () => {
|
||||
// create offer mock
|
||||
const offerMock = Object.assign({}, mockData.offerMockData)
|
||||
offerMock.save = () => { }
|
||||
|
||||
// Stub functions
|
||||
sandbox.stub(uut.OfferModel, 'findOne').returns(offerMock)
|
||||
sandbox.stub(uut.retryQueue, 'addToQueue')
|
||||
.onCall(0).throws(new Error('tokendata error')) // Token Data call
|
||||
.onCall(1).resolves(mockData.mutableDataMock)
|
||||
|
||||
const offer = await uut.syncOfferMutableData('tokenId')
|
||||
assert.isObject(offer)
|
||||
})
|
||||
|
||||
it('should handle error getting mutable data', async () => {
|
||||
// create offer mock
|
||||
const offerMock = Object.assign({}, mockData.offerMockData)
|
||||
offerMock.save = () => { }
|
||||
|
||||
// Stub functions
|
||||
sandbox.stub(uut.OfferModel, 'findOne').returns(offerMock)
|
||||
sandbox.stub(uut.retryQueue, 'addToQueue')
|
||||
.onCall(0).resolves(mockData.simpleNftTokenData01) // Token Data call
|
||||
.onCall(1).throws(new Error('mutable data error'))
|
||||
|
||||
const offer = await uut.syncOfferMutableData('tokenId')
|
||||
assert.isObject(offer)
|
||||
assert.isNumber(offer.lastUpdatedTokenData)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user