mirror of
https://github.com/Permissionless-Software-Foundation/bch-dex.git
synced 2026-09-22 09:11:59 -07:00
feat(order pagination): Adding pagination when calling getAll() orders
This commit is contained in:
Generated
+9498
-5565
File diff suppressed because it is too large
Load Diff
+7
-8
@@ -23,14 +23,13 @@
|
||||
},
|
||||
"repository": "christroutner/ipfs-swap-service",
|
||||
"dependencies": {
|
||||
"@chris.troutner/ipfs": "2.0.2",
|
||||
"@chris.troutner/ipfs": "^1.55.4",
|
||||
"@psf/bch-js": "4.20.26",
|
||||
"axios": "0.21.1",
|
||||
"axios": "^0.21.4",
|
||||
"bch-message-lib": "1.13.9",
|
||||
"bcryptjs": "2.4.3",
|
||||
"glob": "7.1.6",
|
||||
"@chris.troutner/ipfs": "2.0.2",
|
||||
"ipfs-coord": "6.7.4",
|
||||
"ipfs-coord": "^6.5.3",
|
||||
"jsonrpc-lite": "2.2.0",
|
||||
"jsonwebtoken": "8.5.1",
|
||||
"jwt-bch-lib": "1.3.0",
|
||||
@@ -47,7 +46,7 @@
|
||||
"koa2-ratelimit": "0.9.0",
|
||||
"line-reader": "0.4.0",
|
||||
"minimal-slp-wallet": "3.4.7",
|
||||
"mongoose": "5.11.15",
|
||||
"mongoose": "^5.13.13",
|
||||
"node-fetch": "npm:@achingbrain/node-fetch@2.6.7",
|
||||
"nodemailer": "6.4.17",
|
||||
"passport-local": "1.0.0",
|
||||
@@ -57,7 +56,7 @@
|
||||
"devDependencies": {
|
||||
"apidoc": "0.26.0",
|
||||
"chai": "4.3.0",
|
||||
"coveralls": "3.1.0",
|
||||
"coveralls": "^2.11.4",
|
||||
"eslint": "7.19.0",
|
||||
"eslint-config-prettier": "7.2.0",
|
||||
"eslint-config-standard": "16.0.2",
|
||||
@@ -65,11 +64,11 @@
|
||||
"eslint-plugin-prettier": "3.3.1",
|
||||
"eslint-plugin-standard": "4.0.0",
|
||||
"husky": "4.3.8",
|
||||
"mocha": "8.2.1",
|
||||
"mocha": "^8.4.0",
|
||||
"nyc": "15.1.0",
|
||||
"semantic-release": "17.4.4",
|
||||
"sinon": "9.2.4",
|
||||
"standard": "16.0.3",
|
||||
"standard": "^16.0.4",
|
||||
"uuid": "8.3.2"
|
||||
},
|
||||
"release": {
|
||||
|
||||
@@ -15,12 +15,10 @@ class OrderPagination {
|
||||
}
|
||||
|
||||
// Read all entries in the P2WDB.
|
||||
async readAll (page) {
|
||||
async readAll (page = 0) {
|
||||
try {
|
||||
const ENTRIES_PER_PAGE = 20
|
||||
|
||||
if (!page) page = 0
|
||||
|
||||
// Pull data from MongoDB.
|
||||
// Get all entries in the database.
|
||||
const data = await this.Order.find({})
|
||||
|
||||
@@ -47,9 +47,6 @@ class OfferLib {
|
||||
console.log('burn txid: ', txid)
|
||||
console.log(`https://simpleledger.info/tx/${txid}`)
|
||||
|
||||
// TODO: Move tokens to holding address, which will generate the UTXO to
|
||||
// use in the Offer.
|
||||
|
||||
// generate signature.
|
||||
const now = new Date()
|
||||
const message = now.toISOString()
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
Use Case library for Orders.
|
||||
Order are created by a webhook trigger from the P2WDB. Orders are a result of
|
||||
Orders are created by a webhook trigger from the P2WDB. Orders are a result of
|
||||
new data in P2WDB. They differ from Offers, which are generated by a local
|
||||
user.
|
||||
An Order is created to match a local Offer, but it's created indirectly, as
|
||||
|
||||
@@ -8,13 +8,48 @@
|
||||
// Public npm libraries.
|
||||
const assert = require('chai').assert
|
||||
const sinon = require('sinon')
|
||||
const mongoose = require('mongoose')
|
||||
|
||||
// Local libraries.
|
||||
const OrderPagination = require('../../../src/adapters/localdb/order-pagination')
|
||||
const Order = require('../../../src/adapters/localdb/models/order')
|
||||
const config = require('../../../config')
|
||||
|
||||
describe('#P2wdbAdapter', () => {
|
||||
describe('#OrderPagination', () => {
|
||||
let uut, sandbox
|
||||
|
||||
before(async () => {
|
||||
// Connect to the Mongo Database.
|
||||
console.log(`Connecting to database: ${config.database}`)
|
||||
mongoose.Promise = global.Promise
|
||||
mongoose.set('useCreateIndex', true) // Stop deprecation warning.
|
||||
|
||||
await mongoose.connect(config.database, {
|
||||
useUnifiedTopology: true,
|
||||
useNewUrlParser: true
|
||||
})
|
||||
|
||||
const order = new Order({
|
||||
lokadId: 'lokadId',
|
||||
messageType: 1,
|
||||
messageClass: 1,
|
||||
tokenId: 'tokenId',
|
||||
buyOrSell: 'buy',
|
||||
rateInSats: 'rateInSats',
|
||||
minSatsToExchange: '100',
|
||||
signature: 'signature',
|
||||
sigMsg: 'sigMsg',
|
||||
utxoTxid: 'utxoTxid',
|
||||
utxoVout: 1,
|
||||
numTokens: 1,
|
||||
timestamp: 'timestamp',
|
||||
localTimestamp: 'localTimestamp',
|
||||
txid: 'txid',
|
||||
p2wdbHash: 'p2wdbHash'
|
||||
})
|
||||
await order.save()
|
||||
})
|
||||
|
||||
beforeEach(() => {
|
||||
uut = new OrderPagination()
|
||||
sandbox = sinon.createSandbox()
|
||||
@@ -22,6 +57,10 @@ describe('#P2wdbAdapter', () => {
|
||||
|
||||
afterEach(() => sandbox.restore())
|
||||
|
||||
after(() => {
|
||||
mongoose.connection.close()
|
||||
})
|
||||
|
||||
describe('#readAll', () => {
|
||||
it('should get the first page of Order entries', async () => {
|
||||
const data = await uut.readAll()
|
||||
@@ -30,19 +69,17 @@ describe('#P2wdbAdapter', () => {
|
||||
assert.isArray(data)
|
||||
})
|
||||
|
||||
// it('should catch and throw an error', async () => {
|
||||
// try {
|
||||
// // sandbox.stub(uut.orbit, 'readAll').throws(new Error('test error'))
|
||||
//
|
||||
// // Force and error.
|
||||
// sandbox.stub(uut.KeyValue, 'find').rejects(new Error('test error'))
|
||||
//
|
||||
// await uut.readAll()
|
||||
//
|
||||
// assert.fail('unexpected code path')
|
||||
// } catch (err) {
|
||||
// assert.include(err.message, 'is not a function')
|
||||
// }
|
||||
// })
|
||||
it('should catch and throw an error', async () => {
|
||||
try {
|
||||
// Force and error.
|
||||
sandbox.stub(uut.Order, 'find').rejects(new Error('test error'))
|
||||
|
||||
await uut.readAll()
|
||||
|
||||
assert.fail('unexpected code path')
|
||||
} catch (err) {
|
||||
assert.include(err.message, 'is not a function')
|
||||
}
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user