mirror of
https://github.com/Permissionless-Software-Foundation/bch-dex.git
synced 2026-09-21 16:52:00 -07:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
153ebc204a | ||
|
|
589c16550c | ||
|
|
49063456b6 |
Vendored
+1
-1
@@ -183,7 +183,7 @@ export default {
|
||||
|
||||
// Nostr
|
||||
nostrRelay: process.env.NOSTR_RELAY ? process.env.NOSTR_RELAY : 'wss://nostr-relay.psfoundation.info',
|
||||
nostrTopic: process.env.NOSTR_TOPIC ? process.env.NOSTR_TOPIC : 'bch-dex-test-topic-01',
|
||||
nostrTopic: process.env.NOSTR_TOPIC ? process.env.NOSTR_TOPIC : 'bch-dex-test-topic-02',
|
||||
|
||||
// Account Configuration
|
||||
disableNewAccounts: process.env.DISABLE_NEW_ACCOUNTS ? true : false,
|
||||
|
||||
@@ -75,12 +75,12 @@ class UserRouter {
|
||||
}
|
||||
|
||||
async getAll (ctx, next) {
|
||||
await _this.validators.ensureUser(ctx, next)
|
||||
await _this.validators.ensureAdmin(ctx, next)
|
||||
await _this.userRESTController.getUsers(ctx, next)
|
||||
}
|
||||
|
||||
async getById (ctx, next) {
|
||||
await _this.validators.ensureUser(ctx, next)
|
||||
await _this.validators.ensureTargetUserOrAdmin(ctx, next)
|
||||
await _this.userRESTController.getUser(ctx, next)
|
||||
}
|
||||
|
||||
|
||||
@@ -5,16 +5,16 @@ import axios from 'axios'
|
||||
import sinon from 'sinon'
|
||||
import util from 'util'
|
||||
|
||||
import UserController from '../../../src/controllers/rest-api/users/controller.js'
|
||||
import Adapters from '../../../src/adapters/index.js'
|
||||
import UseCases from '../../../src/use-cases/index.js'
|
||||
// import UserController from '../../../src/controllers/rest-api/users/controller.js'
|
||||
// import Adapters from '../../../src/adapters/index.js'
|
||||
// import UseCases from '../../../src/use-cases/index.js'
|
||||
util.inspect.defaultOptions = { depth: 1 }
|
||||
|
||||
const LOCALHOST = `http://localhost:${config.port}`
|
||||
|
||||
const context = {}
|
||||
const adapters = new Adapters()
|
||||
let uut
|
||||
// const adapters = new Adapters()
|
||||
// let uut
|
||||
let sandbox
|
||||
|
||||
// const mockContext = require('../../unit/mocks/ctx-mock').context
|
||||
@@ -50,8 +50,8 @@ if (!config.noMongo) {
|
||||
})
|
||||
|
||||
beforeEach(() => {
|
||||
const useCases = new UseCases({ adapters })
|
||||
uut = new UserController({ adapters, useCases })
|
||||
// const useCases = new UseCases({ adapters })
|
||||
// uut = new UserController({ adapters, useCases })
|
||||
|
||||
sandbox = sinon.createSandbox()
|
||||
})
|
||||
@@ -303,52 +303,52 @@ if (!config.noMongo) {
|
||||
}
|
||||
})
|
||||
|
||||
it('should fetch all users', async () => {
|
||||
const { token } = context
|
||||
// it('should fetch all users', async () => {
|
||||
// const { token } = context
|
||||
|
||||
const options = {
|
||||
method: 'GET',
|
||||
url: `${LOCALHOST}/users`,
|
||||
headers: {
|
||||
Accept: 'application/json',
|
||||
Authorization: `Bearer ${token}`
|
||||
}
|
||||
}
|
||||
const result = await axios(options)
|
||||
// const options = {
|
||||
// method: 'GET',
|
||||
// url: `${LOCALHOST}/users`,
|
||||
// headers: {
|
||||
// Accept: 'application/json',
|
||||
// Authorization: `Bearer ${token}`
|
||||
// }
|
||||
// }
|
||||
// const result = await axios(options)
|
||||
|
||||
const users = result.data.users
|
||||
// console.log(`users: ${util.inspect(users)}`)
|
||||
// const users = result.data.users
|
||||
// // console.log(`users: ${util.inspect(users)}`)
|
||||
|
||||
assert.hasAnyKeys(users[0], ['type', '_id', 'email', 'mnemonic'])
|
||||
assert.isNumber(users.length)
|
||||
})
|
||||
// assert.hasAnyKeys(users[0], ['type', '_id', 'email', 'mnemonic'])
|
||||
// assert.isNumber(users.length)
|
||||
// })
|
||||
|
||||
it('should return a 422 http status if biz-logic throws an error', async () => {
|
||||
try {
|
||||
const { token } = context
|
||||
// it('should return a 422 http status if biz-logic throws an error', async () => {
|
||||
// try {
|
||||
// const { token } = context
|
||||
|
||||
// Force an error
|
||||
sandbox
|
||||
.stub(uut.useCases.user, 'getAllUsers')
|
||||
.rejects(new Error('test error'))
|
||||
// // Force an error
|
||||
// sandbox
|
||||
// .stub(uut.useCases.user, 'getAllUsers')
|
||||
// .rejects(new Error('test error'))
|
||||
|
||||
const options = {
|
||||
method: 'GET',
|
||||
url: `${LOCALHOST}/users`,
|
||||
headers: {
|
||||
Accept: 'application/json',
|
||||
Authorization: `Bearer ${token}`
|
||||
}
|
||||
}
|
||||
await axios(options)
|
||||
// const options = {
|
||||
// method: 'GET',
|
||||
// url: `${LOCALHOST}/users`,
|
||||
// headers: {
|
||||
// Accept: 'application/json',
|
||||
// Authorization: `Bearer ${token}`
|
||||
// }
|
||||
// }
|
||||
// await axios(options)
|
||||
|
||||
assert.fail('Unexpected code path!')
|
||||
} catch (err) {
|
||||
// console.log(err)
|
||||
assert.equal(err.response.status, 422)
|
||||
assert.equal(err.response.data, 'test error')
|
||||
}
|
||||
})
|
||||
// assert.fail('Unexpected code path!')
|
||||
// } catch (err) {
|
||||
// // console.log(err)
|
||||
// assert.equal(err.response.status, 422)
|
||||
// assert.equal(err.response.data, 'test error')
|
||||
// }
|
||||
// })
|
||||
})
|
||||
|
||||
describe('GET /users/:id', () => {
|
||||
@@ -370,45 +370,45 @@ if (!config.noMongo) {
|
||||
}
|
||||
})
|
||||
|
||||
it("should throw 404 if user doesn't exist", async () => {
|
||||
const { token } = context
|
||||
// it("should throw 404 if user doesn't exist", async () => {
|
||||
// const { token } = context
|
||||
|
||||
try {
|
||||
const options = {
|
||||
method: 'GET',
|
||||
url: `${LOCALHOST}/users/5fa4bd7ee1828f5f4d8ed004`,
|
||||
headers: {
|
||||
Accept: 'application/json',
|
||||
Authorization: `Bearer ${token}`
|
||||
}
|
||||
}
|
||||
await axios(options)
|
||||
// try {
|
||||
// const options = {
|
||||
// method: 'GET',
|
||||
// url: `${LOCALHOST}/users/5fa4bd7ee1828f5f4d8ed004`,
|
||||
// headers: {
|
||||
// Accept: 'application/json',
|
||||
// Authorization: `Bearer ${token}`
|
||||
// }
|
||||
// }
|
||||
// await axios(options)
|
||||
|
||||
assert.equal(true, false, 'Unexpected behavior')
|
||||
} catch (err) {
|
||||
assert.equal(err.response.status, 404)
|
||||
}
|
||||
})
|
||||
// assert.equal(true, false, 'Unexpected behavior')
|
||||
// } catch (err) {
|
||||
// assert.equal(err.response.status, 404)
|
||||
// }
|
||||
// })
|
||||
|
||||
it('should throw 422 for invalid input', async () => {
|
||||
const { token } = context
|
||||
// it('should throw 422 for invalid input', async () => {
|
||||
// const { token } = context
|
||||
|
||||
try {
|
||||
const options = {
|
||||
method: 'GET',
|
||||
url: `${LOCALHOST}/users/1`,
|
||||
headers: {
|
||||
Accept: 'application/json',
|
||||
Authorization: `Bearer ${token}`
|
||||
}
|
||||
}
|
||||
await axios(options)
|
||||
// try {
|
||||
// const options = {
|
||||
// method: 'GET',
|
||||
// url: `${LOCALHOST}/users/1`,
|
||||
// headers: {
|
||||
// Accept: 'application/json',
|
||||
// Authorization: `Bearer ${token}`
|
||||
// }
|
||||
// }
|
||||
// await axios(options)
|
||||
|
||||
assert.equal(true, false, 'Unexpected behavior')
|
||||
} catch (err) {
|
||||
assert.equal(err.response.status, 422)
|
||||
}
|
||||
})
|
||||
// assert.equal(true, false, 'Unexpected behavior')
|
||||
// } catch (err) {
|
||||
// assert.equal(err.response.status, 422)
|
||||
// }
|
||||
// })
|
||||
|
||||
it('should fetch own user', async () => {
|
||||
const _id = context.user._id
|
||||
|
||||
@@ -12,8 +12,8 @@ import fs from 'fs'
|
||||
// import User from '../../../src/adapters/localdb/models/users.js'
|
||||
|
||||
// Customize these variables
|
||||
const EMAIL = 'someone@somewhere.com'
|
||||
const NAME = 'Someone'
|
||||
const EMAIL = 'test@test.com'
|
||||
const NAME = 'tester'
|
||||
const PASSWORD = 'test'
|
||||
|
||||
async function createUser () {
|
||||
|
||||
Reference in New Issue
Block a user