mirror of
https://github.com/Permissionless-Software-Foundation/ipfs-bch-wallet-consumer.git
synced 2026-09-21 16:52:03 -07:00
fixed merge conflicts. Some tests are broken
This commit is contained in:
@@ -3,11 +3,12 @@
|
||||
*/
|
||||
|
||||
// Global npm libraries
|
||||
const assert = require('chai').assert
|
||||
const sinon = require('sinon')
|
||||
import { assert } from 'chai'
|
||||
|
||||
import sinon from 'sinon'
|
||||
|
||||
// Local libraries
|
||||
const Adapters = require('../../../src/adapters')
|
||||
import Adapters from '../../../src/adapters/index.js'
|
||||
|
||||
describe('#adapters', () => {
|
||||
let uut, sandbox
|
||||
@@ -26,6 +27,8 @@ describe('#adapters', () => {
|
||||
it('should start the async adapters', async () => {
|
||||
// Mock dependencies
|
||||
uut.config.getJwtAtStartup = true
|
||||
uut.config.useIpfs = true
|
||||
uut.config.env = 'not-a-test'
|
||||
sandbox.stub(uut.fullStackJwt, 'getJWT').resolves()
|
||||
sandbox.stub(uut.fullStackJwt, 'instanceBchjs').resolves()
|
||||
sandbox.stub(uut.ipfs, 'start').resolves()
|
||||
|
||||
@@ -5,19 +5,20 @@
|
||||
*/
|
||||
|
||||
// Public npm libraries
|
||||
const assert = require('chai').assert
|
||||
const sinon = require('sinon')
|
||||
const EventEmitter = require('events')
|
||||
const cloneDeep = require('lodash.clonedeep')
|
||||
import { assert } from 'chai'
|
||||
import sinon from 'sinon'
|
||||
import EventEmitter from 'events'
|
||||
import cloneDeep from 'lodash.clonedeep'
|
||||
|
||||
// Local support libraries
|
||||
// const testUtils = require('../../utils/test-utils')
|
||||
|
||||
// Unit under test (uut)
|
||||
const BchAdapter = require('../../../src/adapters/bch')
|
||||
const adapters = require('../mocks/adapters')
|
||||
import BchAdapter from '../../../src/adapters/bch/index.js'
|
||||
import adapters from '../mocks/adapters/index.js'
|
||||
import mockDataLib from '../mocks/use-cases/rest-api-mocks.js'
|
||||
|
||||
const eventEmitter = new EventEmitter()
|
||||
const mockDataLib = require('../mocks/use-cases/rest-api-mocks')
|
||||
|
||||
describe('#bch-use-case', () => {
|
||||
let uut
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
const assert = require('chai').assert
|
||||
const sinon = require('sinon')
|
||||
|
||||
const ContactLib = require('../../../src/adapters/contact')
|
||||
import { assert } from 'chai'
|
||||
import sinon from 'sinon'
|
||||
import ContactLib from '../../../src/adapters/contact.js'
|
||||
let uut
|
||||
let sandbox
|
||||
|
||||
|
||||
@@ -3,10 +3,10 @@
|
||||
|
||||
*/
|
||||
|
||||
const assert = require('chai').assert
|
||||
const sinon = require('sinon')
|
||||
import { assert } from 'chai'
|
||||
|
||||
const FullStackJWT = require('../../../src/adapters/fullstack-jwt')
|
||||
import sinon from 'sinon'
|
||||
import FullStackJWT from '../../../src/adapters/fullstack-jwt.js'
|
||||
|
||||
describe('#FullStackJWT', () => {
|
||||
let sandbox
|
||||
|
||||
@@ -2,15 +2,15 @@
|
||||
Unit tests for the IPFS Adapter.
|
||||
*/
|
||||
|
||||
const assert = require('chai').assert
|
||||
const sinon = require('sinon')
|
||||
const cloneDeep = require('lodash.clonedeep')
|
||||
|
||||
const IPFSCoordAdapter = require('../../../src/adapters/ipfs/ipfs-coord')
|
||||
const IPFSMock = require('../mocks/ipfs-mock')
|
||||
const IPFSCoordMock = require('../mocks/ipfs-coord-mock')
|
||||
const config = require('../../../config')
|
||||
const mockDataLib = require('../mocks/adapters/ipfs-coord-mocks')
|
||||
import { assert } from 'chai'
|
||||
import sinon from 'sinon'
|
||||
import cloneDeep from 'lodash.clonedeep'
|
||||
import IPFSCoordAdapter from '../../../src/adapters/ipfs/ipfs-coord.js'
|
||||
// import IPFSMock from '../mocks/ipfs-mock.js'
|
||||
import create from '../mocks/ipfs-mock.js'
|
||||
import IPFSCoordMock from '../mocks/ipfs-coord-mock.js'
|
||||
import config from '../../../config/index.js'
|
||||
import mockDataLib from '../mocks/adapters/ipfs-coord-mocks.js'
|
||||
|
||||
describe('#IPFS', () => {
|
||||
let uut
|
||||
@@ -18,7 +18,7 @@ describe('#IPFS', () => {
|
||||
let mockData
|
||||
|
||||
beforeEach(() => {
|
||||
const ipfs = IPFSMock.create()
|
||||
const ipfs = create()
|
||||
uut = new IPFSCoordAdapter({ ipfs })
|
||||
|
||||
sandbox = sinon.createSandbox()
|
||||
@@ -76,7 +76,7 @@ describe('#IPFS', () => {
|
||||
it('should get the public IP address if this node is a Circuit Relay', async () => {
|
||||
// Mock dependencies.
|
||||
uut.IpfsCoord = IPFSCoordMock
|
||||
sandbox.stub(uut.publicIp, 'v4').returns('123')
|
||||
sandbox.stub(uut.publicIp, 'v4').resolves('123')
|
||||
|
||||
// Force Circuit Relay
|
||||
uut.config.isCircuitRelay = true
|
||||
@@ -86,6 +86,21 @@ describe('#IPFS', () => {
|
||||
|
||||
assert.equal(result, true)
|
||||
})
|
||||
|
||||
it('should exit quietly if this node is a Circuit Relay and there is an issue getting the IP address', async () => {
|
||||
// Mock dependencies.
|
||||
uut.IpfsCoord = IPFSCoordMock
|
||||
sandbox.stub(uut.publicIp, 'v4').rejects(new Error('test error'))
|
||||
|
||||
// Force Circuit Relay
|
||||
uut.config.isCircuitRelay = true
|
||||
|
||||
const result = await uut.start()
|
||||
// console.log('result: ', result)
|
||||
|
||||
assert.equal(result, true)
|
||||
})
|
||||
|
||||
it('should return a promise that resolves into an instance of IPFS in production mode', async () => {
|
||||
uut.config.isProduction = true
|
||||
// Mock dependencies.
|
||||
|
||||
@@ -2,20 +2,22 @@
|
||||
Unit tests for the index.js file for the IPFS and ipfs-coord libraries.
|
||||
*/
|
||||
|
||||
const assert = require('chai').assert
|
||||
const sinon = require('sinon')
|
||||
import { assert } from 'chai'
|
||||
|
||||
const IPFSLib = require('../../../src/adapters/ipfs')
|
||||
const IPFSMock = require('../mocks/ipfs-mock')
|
||||
const IPFSCoordMock = require('../mocks/ipfs-coord-mock')
|
||||
const EventEmitter = require('events')
|
||||
import sinon from 'sinon'
|
||||
import IPFSLib from '../../../src/adapters/ipfs/index.js'
|
||||
// import IPFSMock from '../mocks/ipfs-mock.js'
|
||||
// import create from '../mocks/ipfs-mock.js'
|
||||
import IPFSCoordMock from '../mocks/ipfs-coord-mock.js'
|
||||
// import EventEmiter from 'events'
|
||||
|
||||
describe('#IPFS-adapter-index', () => {
|
||||
let uut
|
||||
let sandbox
|
||||
|
||||
beforeEach(() => {
|
||||
uut = new IPFSLib({ eventEmitter: new EventEmitter() })
|
||||
// uut = new IPFSLib({ eventEmitter: new EventEmitter() })
|
||||
uut = new IPFSLib({ })
|
||||
|
||||
sandbox = sinon.createSandbox()
|
||||
})
|
||||
@@ -25,7 +27,9 @@ describe('#IPFS-adapter-index', () => {
|
||||
describe('#start', () => {
|
||||
it('should return a promise that resolves into an instance of IPFS.', async () => {
|
||||
// Mock dependencies.
|
||||
uut.ipfsAdapter = new IPFSMock()
|
||||
uut.ipfsAdapter = {
|
||||
start: async () => {}
|
||||
}
|
||||
uut.IpfsCoordAdapter = IPFSCoordMock
|
||||
|
||||
const result = await uut.start()
|
||||
|
||||
@@ -2,11 +2,12 @@
|
||||
Unit tests for the IPFS Adapter.
|
||||
*/
|
||||
|
||||
const assert = require('chai').assert
|
||||
const sinon = require('sinon')
|
||||
const IPFSLib = require('../../../src/adapters/ipfs/ipfs')
|
||||
const IPFSMock = require('../mocks/ipfs-mock')
|
||||
const config = require('../../../config')
|
||||
import { assert } from 'chai'
|
||||
|
||||
import sinon from 'sinon'
|
||||
import IPFSLib from '../../../src/adapters/ipfs/ipfs.js'
|
||||
import create from '../mocks/ipfs-mock.js'
|
||||
import config from '../../../config/index.js'
|
||||
|
||||
// config.isProduction = true;
|
||||
describe('#IPFS-adapter', () => {
|
||||
@@ -44,7 +45,7 @@ describe('#IPFS-adapter', () => {
|
||||
describe('#start', () => {
|
||||
it('should return a promise that resolves into an instance of IPFS.', async () => {
|
||||
// Mock dependencies.
|
||||
uut.IPFS = IPFSMock
|
||||
uut.create = create
|
||||
|
||||
const result = await uut.start()
|
||||
// console.log('result: ', result)
|
||||
@@ -56,7 +57,7 @@ describe('#IPFS-adapter', () => {
|
||||
|
||||
it('should return a promise that resolves into an instance of IPFS in production mode.', async () => {
|
||||
// Mock dependencies.
|
||||
uut.IPFS = IPFSMock
|
||||
uut.create = create
|
||||
uut.config.isProduction = true
|
||||
const result = await uut.start()
|
||||
// console.log('result: ', result)
|
||||
@@ -69,7 +70,7 @@ describe('#IPFS-adapter', () => {
|
||||
it('should catch and throw an error', async () => {
|
||||
try {
|
||||
// Force an error
|
||||
sandbox.stub(uut.IPFS, 'create').rejects(new Error('test error'))
|
||||
sandbox.stub(uut, 'create').rejects(new Error('test error'))
|
||||
|
||||
await uut.start()
|
||||
|
||||
|
||||
@@ -1,11 +1,15 @@
|
||||
const assert = require('chai').assert
|
||||
const fs = require('fs')
|
||||
const sinon = require('sinon')
|
||||
import { assert } from 'chai'
|
||||
import fs from 'fs'
|
||||
import sinon from 'sinon'
|
||||
import util from 'util'
|
||||
|
||||
const util = require('util')
|
||||
import JsonFiles from '../../../src/adapters/json-files.js'
|
||||
|
||||
// Hack to get __dirname back.
|
||||
// https://blog.logrocket.com/alternatives-dirname-node-js-es-modules/
|
||||
import * as url from 'url'
|
||||
util.inspect.defaultOptions = { depth: 1 }
|
||||
|
||||
const JsonFiles = require('../../../src/adapters/json-files')
|
||||
const __dirname = url.fileURLToPath(new URL('.', import.meta.url))
|
||||
|
||||
const JSON_FILE = 'test-json-file.json'
|
||||
const JSON_PATH = `${__dirname.toString()}/${JSON_FILE}`
|
||||
|
||||
@@ -1,12 +1,15 @@
|
||||
const assert = require('chai').assert
|
||||
import { assert } from 'chai'
|
||||
import sinon from 'sinon'
|
||||
import util from 'util'
|
||||
|
||||
const sinon = require('sinon')
|
||||
import LogsApiLib from '../../../src/adapters/logapi.js'
|
||||
import mockData from '../mocks/log-api-mock.js'
|
||||
|
||||
const util = require('util')
|
||||
// Hack to get __dirname back.
|
||||
// https://blog.logrocket.com/alternatives-dirname-node-js-es-modules/
|
||||
import * as url from 'url'
|
||||
util.inspect.defaultOptions = { depth: 1 }
|
||||
|
||||
const LogsApiLib = require('../../../src/adapters/logapi')
|
||||
const mockData = require('../mocks/log-api-mock')
|
||||
const __dirname = url.fileURLToPath(new URL('.', import.meta.url))
|
||||
|
||||
const context = {}
|
||||
let sandbox
|
||||
|
||||
@@ -3,10 +3,10 @@
|
||||
*/
|
||||
|
||||
// Public npm libraries
|
||||
const assert = require('chai').assert
|
||||
const sinon = require('sinon')
|
||||
import { assert } from 'chai'
|
||||
|
||||
const NodeMailer = require('../../../src/adapters/nodemailer')
|
||||
import sinon from 'sinon'
|
||||
import NodeMailer from '../../../src/adapters/nodemailer.js'
|
||||
|
||||
let sandbox
|
||||
let uut
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
const assert = require('chai').assert
|
||||
const PassportLib = require('../../../src/adapters/passport')
|
||||
|
||||
const sinon = require('sinon')
|
||||
import { assert } from 'chai'
|
||||
import PassportLib from '../../../src/adapters/passport.js'
|
||||
import sinon from 'sinon'
|
||||
|
||||
let uut
|
||||
let sandbox
|
||||
|
||||
@@ -2,16 +2,17 @@
|
||||
Unit tests for the users Mongoose model.
|
||||
*/
|
||||
|
||||
const assert = require('chai').assert
|
||||
const sinon = require('sinon')
|
||||
const mongoose = require('mongoose')
|
||||
import { assert } from 'chai'
|
||||
|
||||
import sinon from 'sinon'
|
||||
import mongoose from 'mongoose'
|
||||
|
||||
import User from '../../../src/adapters/localdb/models/users.js'
|
||||
import config from '../../../config/index.js'
|
||||
|
||||
// Set the environment variable to signal this is a test.
|
||||
process.env.SVC_ENV = 'test'
|
||||
|
||||
const User = require('../../../src/adapters/localdb/models/users')
|
||||
const config = require('../../../config')
|
||||
|
||||
describe('#User-Adapter', () => {
|
||||
// let uut
|
||||
let sandbox
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
const assert = require('chai').assert
|
||||
const { Wlogger } = require('../../../src/adapters/wlogger')
|
||||
|
||||
const sinon = require('sinon')
|
||||
import { assert } from 'chai'
|
||||
import { Wlogger } from '../../../src/adapters/wlogger.js'
|
||||
import sinon from 'sinon'
|
||||
|
||||
let uut
|
||||
let sandbox
|
||||
|
||||
@@ -4,9 +4,9 @@
|
||||
|
||||
// Public npm libraries
|
||||
// const assert = require('chai').assert
|
||||
const sinon = require('sinon')
|
||||
import sinon from 'sinon'
|
||||
|
||||
const Controllers = require('../../../src/controllers')
|
||||
import Controllers from '../../../src/controllers/index.js'
|
||||
|
||||
describe('#Controllers', () => {
|
||||
let uut
|
||||
@@ -28,6 +28,9 @@ describe('#Controllers', () => {
|
||||
attachRPCRouter: () => {}
|
||||
}
|
||||
|
||||
// Mock the timer controllers
|
||||
sandbox.stub(uut.timerControllers, 'startTimers').returns()
|
||||
|
||||
const app = {
|
||||
use: () => {}
|
||||
}
|
||||
|
||||
@@ -3,19 +3,21 @@
|
||||
*/
|
||||
|
||||
// Public npm libraries
|
||||
const assert = require('chai').assert
|
||||
const jsonrpc = require('jsonrpc-lite')
|
||||
const sinon = require('sinon')
|
||||
const { v4: uid } = require('uuid')
|
||||
import { assert } from 'chai'
|
||||
|
||||
import jsonrpc from 'jsonrpc-lite'
|
||||
import sinon from 'sinon'
|
||||
import { v4 as uid } from 'uuid'
|
||||
|
||||
// Local libraries.
|
||||
import JSONRPC from '../../../../src/controllers/json-rpc/index.js'
|
||||
|
||||
import adapters from '../../mocks/adapters/index.js'
|
||||
import UseCasesMock from '../../mocks/use-cases/index.js'
|
||||
|
||||
// Set the environment variable to signal this is a test.
|
||||
process.env.SVC_ENV = 'test'
|
||||
|
||||
// Local libraries.
|
||||
const JSONRPC = require('../../../../src/controllers/json-rpc')
|
||||
const adapters = require('../../mocks/adapters')
|
||||
const UseCasesMock = require('../../mocks/use-cases')
|
||||
|
||||
describe('#JSON RPC', () => {
|
||||
let uut
|
||||
let sandbox
|
||||
|
||||
@@ -5,18 +5,20 @@
|
||||
*/
|
||||
|
||||
// Public npm libraries
|
||||
const jsonrpc = require('jsonrpc-lite')
|
||||
const sinon = require('sinon')
|
||||
const assert = require('chai').assert
|
||||
const { v4: uid } = require('uuid')
|
||||
import jsonrpc from 'jsonrpc-lite'
|
||||
|
||||
import sinon from 'sinon'
|
||||
import { assert } from 'chai'
|
||||
import { v4 as uid } from 'uuid'
|
||||
|
||||
// Local libraries
|
||||
import Validators from '../../../../src/controllers/json-rpc/validators.js'
|
||||
|
||||
import adapters from '../../mocks/adapters/index.js'
|
||||
|
||||
// Set the environment variable to signal this is a test.
|
||||
process.env.SVC_ENV = 'test'
|
||||
|
||||
// Local libraries
|
||||
const Validators = require('../../../../src/controllers/json-rpc/validators')
|
||||
const adapters = require('../../mocks/adapters')
|
||||
|
||||
describe('#validators', () => {
|
||||
let uut
|
||||
let sandbox
|
||||
|
||||
@@ -5,15 +5,16 @@
|
||||
*/
|
||||
|
||||
// Public npm libraries
|
||||
const sinon = require('sinon')
|
||||
const assert = require('chai').assert
|
||||
import sinon from 'sinon'
|
||||
|
||||
import { assert } from 'chai'
|
||||
|
||||
// Local libraries
|
||||
import RateLimit from '../../../../src/controllers/json-rpc/rate-limit.js'
|
||||
|
||||
// Set the environment variable to signal this is a test.
|
||||
process.env.SVC_ENV = 'test'
|
||||
|
||||
// Local libraries
|
||||
const RateLimit = require('../../../../src/controllers/json-rpc/rate-limit')
|
||||
|
||||
describe('#rate-limit', () => {
|
||||
let uut
|
||||
let sandbox
|
||||
|
||||
@@ -3,11 +3,12 @@
|
||||
*/
|
||||
|
||||
// Public npm libraries
|
||||
const sinon = require('sinon')
|
||||
const assert = require('chai').assert
|
||||
import sinon from 'sinon'
|
||||
|
||||
import { assert } from 'chai'
|
||||
|
||||
// Local libraries
|
||||
const AboutRPC = require('../../../../src/controllers/json-rpc/about')
|
||||
import AboutRPC from '../../../../src/controllers/json-rpc/about/index.js'
|
||||
|
||||
describe('#AboutRPC', () => {
|
||||
let uut
|
||||
|
||||
@@ -3,20 +3,22 @@
|
||||
*/
|
||||
|
||||
// Public npm libraries
|
||||
const jsonrpc = require('jsonrpc-lite')
|
||||
const sinon = require('sinon')
|
||||
const assert = require('chai').assert
|
||||
const { v4: uid } = require('uuid')
|
||||
import jsonrpc from 'jsonrpc-lite'
|
||||
|
||||
import sinon from 'sinon'
|
||||
import { assert } from 'chai'
|
||||
import { v4 as uid } from 'uuid'
|
||||
|
||||
// Local libraries
|
||||
import AuthRPC from '../../../../src/controllers/json-rpc/auth/index.js'
|
||||
|
||||
import RateLimit from '../../../../src/controllers/json-rpc/rate-limit.js'
|
||||
import adapters from '../../mocks/adapters/index.js'
|
||||
import UseCasesMock from '../../mocks/use-cases/index.js'
|
||||
|
||||
// Set the environment variable to signal this is a test.
|
||||
process.env.SVC_ENV = 'test'
|
||||
|
||||
// Local libraries
|
||||
const AuthRPC = require('../../../../src/controllers/json-rpc/auth')
|
||||
const RateLimit = require('../../../../src/controllers/json-rpc/rate-limit')
|
||||
const adapters = require('../../mocks/adapters')
|
||||
const UseCasesMock = require('../../mocks/use-cases')
|
||||
|
||||
describe('#AuthRPC', () => {
|
||||
let uut
|
||||
let sandbox
|
||||
|
||||
@@ -3,19 +3,21 @@
|
||||
*/
|
||||
|
||||
// Public npm libraries
|
||||
const jsonrpc = require('jsonrpc-lite')
|
||||
const sinon = require('sinon')
|
||||
const assert = require('chai').assert
|
||||
const { v4: uid } = require('uuid')
|
||||
import jsonrpc from 'jsonrpc-lite'
|
||||
|
||||
import sinon from 'sinon'
|
||||
import { assert } from 'chai'
|
||||
import { v4 as uid } from 'uuid'
|
||||
|
||||
// Local libraries
|
||||
import UserRPC from '../../../../src/controllers/json-rpc/users/index.js'
|
||||
|
||||
import adapters from '../../mocks/adapters/index.js'
|
||||
import UseCasesMock from '../../mocks/use-cases/index.js'
|
||||
|
||||
// Set the environment variable to signal this is a test.
|
||||
process.env.SVC_ENV = 'test'
|
||||
|
||||
// Local libraries
|
||||
const UserRPC = require('../../../../src/controllers/json-rpc/users')
|
||||
const adapters = require('../../mocks/adapters')
|
||||
const UseCasesMock = require('../../mocks/use-cases')
|
||||
|
||||
describe('#UserRPC', () => {
|
||||
let uut
|
||||
let sandbox
|
||||
|
||||
@@ -3,21 +3,25 @@
|
||||
*/
|
||||
|
||||
// Public npm libraries
|
||||
const assert = require('chai').assert
|
||||
const sinon = require('sinon')
|
||||
import { assert } from 'chai'
|
||||
|
||||
import sinon from 'sinon'
|
||||
|
||||
// Local support libraries
|
||||
const adapters = require('../../../mocks/adapters')
|
||||
const UseCasesMock = require('../../../mocks/use-cases')
|
||||
import adapters from '../../../mocks/adapters/index.js'
|
||||
|
||||
import UseCasesMock from '../../../mocks/use-cases/index.js'
|
||||
|
||||
// const app = require('../../../mocks/app-mock')
|
||||
|
||||
const AuthRESTController = require('../../../../../src/controllers/rest-api/auth/controller')
|
||||
import AuthRESTController from '../../../../../src/controllers/rest-api/auth/controller.js'
|
||||
|
||||
import { context as mockContext } from '../../../../unit/mocks/ctx-mock.js'
|
||||
|
||||
let uut
|
||||
let sandbox
|
||||
let ctx
|
||||
|
||||
const mockContext = require('../../../../unit/mocks/ctx-mock').context
|
||||
|
||||
describe('#Auth-REST-Router', () => {
|
||||
// const testUser = {}
|
||||
|
||||
|
||||
@@ -3,15 +3,19 @@
|
||||
*/
|
||||
|
||||
// Public npm libraries
|
||||
const assert = require('chai').assert
|
||||
const sinon = require('sinon')
|
||||
import { assert } from 'chai'
|
||||
|
||||
import sinon from 'sinon'
|
||||
|
||||
// Local support libraries
|
||||
const adapters = require('../../../mocks/adapters')
|
||||
const UseCasesMock = require('../../../mocks/use-cases')
|
||||
import adapters from '../../../mocks/adapters/index.js'
|
||||
|
||||
import UseCasesMock from '../../../mocks/use-cases/index.js'
|
||||
|
||||
// const app = require('../../../mocks/app-mock')
|
||||
|
||||
const AuthRouter = require('../../../../../src/controllers/rest-api/auth')
|
||||
import AuthRouter from '../../../../../src/controllers/rest-api/auth/index.js'
|
||||
|
||||
let uut
|
||||
let sandbox
|
||||
// let ctx
|
||||
|
||||
@@ -3,20 +3,21 @@
|
||||
*/
|
||||
|
||||
// Public npm libraries
|
||||
const assert = require('chai').assert
|
||||
const sinon = require('sinon')
|
||||
import { assert } from 'chai'
|
||||
import sinon from 'sinon'
|
||||
|
||||
// Local support libraries
|
||||
const adapters = require('../../../mocks/adapters')
|
||||
const UseCasesMock = require('../../../mocks/use-cases')
|
||||
import adapters from '../../../mocks/adapters/index.js'
|
||||
import UseCasesMock from '../../../mocks/use-cases/index.js'
|
||||
|
||||
const BchController = require('../../../../../src/controllers/rest-api/bch/controller')
|
||||
import BchController from '../../../../../src/controllers/rest-api/bch/controller.js'
|
||||
// import { context } from '../../../../unit/mocks/ctx-mock.js'
|
||||
// import blah '../../../../unit/mocks/ctx-mock.js'
|
||||
// console.log('blah: ', blah)
|
||||
let uut
|
||||
let sandbox
|
||||
let ctx
|
||||
|
||||
const mockContext = require('../../../../unit/mocks/ctx-mock').context
|
||||
|
||||
describe('#BCH-REST-Controller', () => {
|
||||
// const testUser = {}
|
||||
|
||||
@@ -27,7 +28,7 @@ describe('#BCH-REST-Controller', () => {
|
||||
sandbox = sinon.createSandbox()
|
||||
|
||||
// Mock the context object.
|
||||
ctx = mockContext()
|
||||
// ctx = mockContext()
|
||||
})
|
||||
|
||||
afterEach(() => sandbox.restore())
|
||||
|
||||
@@ -3,15 +3,15 @@
|
||||
*/
|
||||
|
||||
// Public npm libraries
|
||||
const assert = require('chai').assert
|
||||
const sinon = require('sinon')
|
||||
import { assert } from 'chai'
|
||||
import sinon from 'sinon'
|
||||
|
||||
// Local support libraries
|
||||
const adapters = require('../../../mocks/adapters')
|
||||
const UseCasesMock = require('../../../mocks/use-cases')
|
||||
import adapters from '../../../mocks/adapters/index.js'
|
||||
import UseCasesMock from '../../../mocks/use-cases/index.js'
|
||||
// const app = require('../../../mocks/app-mock')
|
||||
|
||||
const BchRouter = require('../../../../../src/controllers/rest-api/bch')
|
||||
import BchRouter from '../../../../../src/controllers/rest-api/bch/index.js'
|
||||
let uut
|
||||
let sandbox
|
||||
// let ctx
|
||||
|
||||
@@ -3,16 +3,16 @@
|
||||
*/
|
||||
|
||||
// Public npm libraries
|
||||
const assert = require('chai').assert
|
||||
const sinon = require('sinon')
|
||||
import { assert } from 'chai'
|
||||
|
||||
const ContactController = require('../../../../../src/controllers/rest-api/contact/controller')
|
||||
import sinon from 'sinon'
|
||||
import ContactController from '../../../../../src/controllers/rest-api/contact/controller.js'
|
||||
|
||||
import { context as mockContext } from '../../../../unit/mocks/ctx-mock.js'
|
||||
let uut
|
||||
let sandbox
|
||||
let ctx
|
||||
|
||||
const mockContext = require('../../../../unit/mocks/ctx-mock').context
|
||||
|
||||
describe('Contact', () => {
|
||||
before(async () => {
|
||||
})
|
||||
|
||||
@@ -3,15 +3,19 @@
|
||||
*/
|
||||
|
||||
// Public npm libraries
|
||||
const assert = require('chai').assert
|
||||
const sinon = require('sinon')
|
||||
import { assert } from 'chai'
|
||||
|
||||
import sinon from 'sinon'
|
||||
|
||||
// Local support libraries
|
||||
const adapters = require('../../../mocks/adapters')
|
||||
const UseCasesMock = require('../../../mocks/use-cases')
|
||||
import adapters from '../../../mocks/adapters/index.js'
|
||||
|
||||
import UseCasesMock from '../../../mocks/use-cases/index.js'
|
||||
|
||||
// const app = require('../../../mocks/app-mock')
|
||||
|
||||
const ContactRouter = require('../../../../../src/controllers/rest-api/contact')
|
||||
import ContactRouter from '../../../../../src/controllers/rest-api/contact/index.js'
|
||||
|
||||
let uut
|
||||
let sandbox
|
||||
// let ctx
|
||||
|
||||
@@ -3,16 +3,16 @@
|
||||
*/
|
||||
|
||||
// Public npm libraries
|
||||
const assert = require('chai').assert
|
||||
const sinon = require('sinon')
|
||||
import { assert } from 'chai'
|
||||
|
||||
const LogsApiController = require('../../../../../src/controllers/rest-api/logs/controller')
|
||||
import sinon from 'sinon'
|
||||
import LogsApiController from '../../../../../src/controllers/rest-api/logs/controller.js'
|
||||
|
||||
import { context as mockContext } from '../../../../unit/mocks/ctx-mock.js'
|
||||
let uut
|
||||
let sandbox
|
||||
let ctx
|
||||
|
||||
const mockContext = require('../../../../unit/mocks/ctx-mock').context
|
||||
|
||||
describe('Logapi', () => {
|
||||
before(async () => {
|
||||
})
|
||||
|
||||
@@ -3,15 +3,19 @@
|
||||
*/
|
||||
|
||||
// Public npm libraries
|
||||
const assert = require('chai').assert
|
||||
const sinon = require('sinon')
|
||||
import { assert } from 'chai'
|
||||
|
||||
import sinon from 'sinon'
|
||||
|
||||
// Local support libraries
|
||||
const adapters = require('../../../mocks/adapters')
|
||||
const UseCasesMock = require('../../../mocks/use-cases')
|
||||
import adapters from '../../../mocks/adapters/index.js'
|
||||
|
||||
import UseCasesMock from '../../../mocks/use-cases/index.js'
|
||||
|
||||
// const app = require('../../../mocks/app-mock')
|
||||
|
||||
const LogsRouter = require('../../../../../src/controllers/rest-api/logs')
|
||||
import LogsRouter from '../../../../../src/controllers/rest-api/logs/index.js'
|
||||
|
||||
let uut
|
||||
let sandbox
|
||||
// let ctx
|
||||
|
||||
@@ -0,0 +1,306 @@
|
||||
/*
|
||||
Unit tests for the REST API middleware that validates users.
|
||||
*/
|
||||
|
||||
// Public npm libraries
|
||||
import { assert } from 'chai'
|
||||
import sinon from 'sinon'
|
||||
|
||||
// Local libraries
|
||||
import Validators from '../../../../../src/controllers/rest-api/middleware/validators.js'
|
||||
import { context as mockContext } from '../../../../unit/mocks/ctx-mock.js'
|
||||
|
||||
describe('#Validators', () => {
|
||||
let uut
|
||||
let ctx
|
||||
let sandbox
|
||||
|
||||
beforeEach(() => {
|
||||
uut = new Validators()
|
||||
|
||||
// Mock the context object.
|
||||
ctx = mockContext()
|
||||
|
||||
sandbox = sinon.createSandbox()
|
||||
})
|
||||
|
||||
afterEach(() => sandbox.restore())
|
||||
|
||||
describe('#getToken', () => {
|
||||
it('should return null if no header is provided', () => {
|
||||
const result = uut.getToken(ctx)
|
||||
|
||||
assert.equal(result, null)
|
||||
})
|
||||
|
||||
it('should return null if header is not in two parts', () => {
|
||||
ctx.request.header.authorization = 'Bearer'
|
||||
|
||||
const result = uut.getToken(ctx)
|
||||
|
||||
assert.equal(result, null)
|
||||
})
|
||||
|
||||
it('should return null if first part of header does not container the word bearer', () => {
|
||||
ctx.request.header.authorization = 'some thing'
|
||||
|
||||
const result = uut.getToken(ctx)
|
||||
|
||||
assert.equal(result, null)
|
||||
})
|
||||
|
||||
it('should return the JWT token from the header', () => {
|
||||
const jwt = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjYzMjNiNTUwNzgxYWYzNTc4YzI0ZmU5YiIsImlhdCI6MTY2MzQ0NDczNCwiZXhwIjoxNjYzNTMxMTM0fQ.BY5sOfXc4z5axS98CdTfyqnO9y2wijOlwnv52rcvxHA'
|
||||
ctx.request.header.authorization = `Bearer ${jwt}`
|
||||
|
||||
const result = uut.getToken(ctx)
|
||||
|
||||
assert.equal(result, jwt)
|
||||
})
|
||||
})
|
||||
|
||||
describe('#ensureUser', () => {
|
||||
it('should throw error if token is not provided', async () => {
|
||||
try {
|
||||
// Mock dependencies and force desired code path
|
||||
sandbox.stub(uut, 'getToken').returns()
|
||||
|
||||
await uut.ensureUser(ctx)
|
||||
|
||||
assert.fail('Unexpected result')
|
||||
} catch (err) {
|
||||
assert.equal(ctx.status, 401)
|
||||
}
|
||||
})
|
||||
|
||||
it('should throw error if token can not be verified', async () => {
|
||||
try {
|
||||
// Mock dependencies and force desired code path
|
||||
sandbox.stub(uut, 'getToken').returns('fake-jwt')
|
||||
sandbox.stub(uut.jwt, 'verify').throws(new Error('test error'))
|
||||
|
||||
await uut.ensureUser(ctx)
|
||||
|
||||
assert.fail('Unexpected result')
|
||||
} catch (err) {
|
||||
assert.equal(ctx.status, 401)
|
||||
}
|
||||
})
|
||||
|
||||
it('should throw error if user can not be found in database', async () => {
|
||||
try {
|
||||
// Mock dependencies and force desired code path
|
||||
sandbox.stub(uut, 'getToken').returns('fake-jwt')
|
||||
sandbox.stub(uut.jwt, 'verify').returns({})
|
||||
sandbox.stub(uut.User, 'findById').resolves(false)
|
||||
|
||||
await uut.ensureUser(ctx)
|
||||
|
||||
assert.fail('Unexpected result')
|
||||
} catch (err) {
|
||||
assert.equal(ctx.status, 401)
|
||||
}
|
||||
})
|
||||
|
||||
it('should return true if the user is verified', async () => {
|
||||
// Mock dependencies and force desired code path
|
||||
sandbox.stub(uut, 'getToken').returns('fake-jwt')
|
||||
sandbox.stub(uut.jwt, 'verify').returns({})
|
||||
sandbox.stub(uut.User, 'findById').resolves({ user: 'alice' })
|
||||
|
||||
const result = await uut.ensureUser(ctx)
|
||||
|
||||
assert.equal(result, true)
|
||||
})
|
||||
})
|
||||
|
||||
describe('#ensureUser', () => {
|
||||
it('should throw error if token is not provided', async () => {
|
||||
try {
|
||||
// Mock dependencies and force desired code path
|
||||
sandbox.stub(uut, 'getToken').returns()
|
||||
|
||||
await uut.ensureAdmin(ctx)
|
||||
|
||||
assert.fail('Unexpected result')
|
||||
} catch (err) {
|
||||
assert.equal(ctx.status, 401)
|
||||
}
|
||||
})
|
||||
|
||||
it('should throw error if token can not be verified', async () => {
|
||||
try {
|
||||
// Mock dependencies and force desired code path
|
||||
sandbox.stub(uut, 'getToken').returns('fake-jwt')
|
||||
sandbox.stub(uut.jwt, 'verify').throws(new Error('test error'))
|
||||
|
||||
await uut.ensureAdmin(ctx)
|
||||
|
||||
assert.fail('Unexpected result')
|
||||
} catch (err) {
|
||||
assert.equal(ctx.status, 401)
|
||||
}
|
||||
})
|
||||
|
||||
it('should throw error if user can not be found in database', async () => {
|
||||
try {
|
||||
// Mock dependencies and force desired code path
|
||||
sandbox.stub(uut, 'getToken').returns('fake-jwt')
|
||||
sandbox.stub(uut.jwt, 'verify').returns({})
|
||||
sandbox.stub(uut.User, 'findById').resolves(false)
|
||||
|
||||
await uut.ensureAdmin(ctx)
|
||||
|
||||
assert.fail('Unexpected result')
|
||||
} catch (err) {
|
||||
assert.equal(ctx.status, 401)
|
||||
}
|
||||
})
|
||||
|
||||
it('should throw error if user is not an admin', async () => {
|
||||
try {
|
||||
// Mock dependencies and force desired code path
|
||||
sandbox.stub(uut, 'getToken').returns('fake-jwt')
|
||||
sandbox.stub(uut.jwt, 'verify').returns({})
|
||||
sandbox.stub(uut.User, 'findById').resolves({ type: 'user' })
|
||||
|
||||
await uut.ensureAdmin(ctx)
|
||||
|
||||
assert.fail('Unexpected result')
|
||||
} catch (err) {
|
||||
assert.equal(ctx.status, 401)
|
||||
}
|
||||
})
|
||||
|
||||
it('should return true if the user is an admin', async () => {
|
||||
// Mock dependencies and force desired code path
|
||||
sandbox.stub(uut, 'getToken').returns('fake-jwt')
|
||||
sandbox.stub(uut.jwt, 'verify').returns({})
|
||||
sandbox.stub(uut.User, 'findById').resolves({ type: 'admin' })
|
||||
|
||||
const result = await uut.ensureAdmin(ctx)
|
||||
|
||||
assert.equal(result, true)
|
||||
})
|
||||
})
|
||||
|
||||
describe('#ensureTargetUserOrAdmin', () => {
|
||||
it('should throw error if token is not provided', async () => {
|
||||
try {
|
||||
// Mock dependencies and force desired code path
|
||||
sandbox.stub(uut, 'getToken').returns()
|
||||
|
||||
await uut.ensureTargetUserOrAdmin(ctx)
|
||||
|
||||
assert.fail('Unexpected result')
|
||||
} catch (err) {
|
||||
assert.equal(ctx.status, 401)
|
||||
}
|
||||
})
|
||||
|
||||
it('should throw error if token can not be verified', async () => {
|
||||
try {
|
||||
// Mock dependencies and force desired code path
|
||||
sandbox.stub(uut, 'getToken').returns('fake-jwt')
|
||||
sandbox.stub(uut.jwt, 'verify').throws(new Error('test error'))
|
||||
|
||||
ctx.params = {
|
||||
id: '456'
|
||||
}
|
||||
|
||||
await uut.ensureTargetUserOrAdmin(ctx)
|
||||
|
||||
assert.fail('Unexpected result')
|
||||
} catch (err) {
|
||||
assert.equal(ctx.status, 401)
|
||||
}
|
||||
})
|
||||
|
||||
it('should throw error if user can not be found in database', async () => {
|
||||
try {
|
||||
// Mock dependencies and force desired code path
|
||||
sandbox.stub(uut, 'getToken').returns('fake-jwt')
|
||||
sandbox.stub(uut.jwt, 'verify').returns({})
|
||||
sandbox.stub(uut.User, 'findById').resolves(false)
|
||||
|
||||
ctx.params = {
|
||||
id: '456'
|
||||
}
|
||||
|
||||
await uut.ensureTargetUserOrAdmin(ctx)
|
||||
|
||||
assert.fail('Unexpected result')
|
||||
} catch (err) {
|
||||
assert.equal(ctx.status, 401)
|
||||
}
|
||||
})
|
||||
|
||||
it('should throw error if user is not an admin', async () => {
|
||||
try {
|
||||
// Mock dependencies and force desired code path
|
||||
sandbox.stub(uut, 'getToken').returns('fake-jwt')
|
||||
sandbox.stub(uut.jwt, 'verify').returns({})
|
||||
sandbox.stub(uut.User, 'findById').resolves({ type: 'user' })
|
||||
|
||||
ctx.params = {
|
||||
id: '456'
|
||||
}
|
||||
|
||||
await uut.ensureTargetUserOrAdmin(ctx)
|
||||
|
||||
assert.fail('Unexpected result')
|
||||
} catch (err) {
|
||||
assert.equal(ctx.status, 401)
|
||||
}
|
||||
})
|
||||
|
||||
it('should throw error is user is not admin or target user', async () => {
|
||||
try {
|
||||
// Mock dependencies and force desired code path
|
||||
sandbox.stub(uut, 'getToken').returns('fake-jwt')
|
||||
sandbox.stub(uut.jwt, 'verify').returns({})
|
||||
sandbox.stub(uut.User, 'findById').resolves({ type: 'user', _id: '123' })
|
||||
|
||||
ctx.params = {
|
||||
id: '456'
|
||||
}
|
||||
|
||||
await uut.ensureTargetUserOrAdmin(ctx)
|
||||
|
||||
assert.fail('Unexpected result')
|
||||
} catch (err) {
|
||||
assert.equal(ctx.status, 401)
|
||||
}
|
||||
})
|
||||
|
||||
it('should return true if the user is an admin', async () => {
|
||||
// Mock dependencies and force desired code path
|
||||
sandbox.stub(uut, 'getToken').returns('fake-jwt')
|
||||
sandbox.stub(uut.jwt, 'verify').returns({})
|
||||
sandbox.stub(uut.User, 'findById').resolves({ type: 'admin', _id: '123' })
|
||||
|
||||
ctx.params = {
|
||||
id: '456'
|
||||
}
|
||||
|
||||
const result = await uut.ensureTargetUserOrAdmin(ctx)
|
||||
|
||||
assert.equal(result, true)
|
||||
})
|
||||
|
||||
it('should return true if the user is the target user', async () => {
|
||||
// Mock dependencies and force desired code path
|
||||
sandbox.stub(uut, 'getToken').returns('fake-jwt')
|
||||
sandbox.stub(uut.jwt, 'verify').returns({})
|
||||
sandbox.stub(uut.User, 'findById').resolves({ type: 'user', _id: '123' })
|
||||
|
||||
ctx.params = {
|
||||
id: '123'
|
||||
}
|
||||
|
||||
const result = await uut.ensureTargetUserOrAdmin(ctx)
|
||||
|
||||
assert.equal(result, true)
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -3,14 +3,17 @@
|
||||
*/
|
||||
|
||||
// Public npm libraries
|
||||
const assert = require('chai').assert
|
||||
const sinon = require('sinon')
|
||||
import { assert } from 'chai'
|
||||
|
||||
import sinon from 'sinon'
|
||||
|
||||
// Local libraries
|
||||
const RESTControllers = require('../../../../src/controllers/rest-api/')
|
||||
import RESTControllers from '../../../../src/controllers/rest-api/index.js'
|
||||
|
||||
// const mockContext = require('../../../unit/mocks/ctx-mock').context
|
||||
const adapters = require('../../mocks/adapters')
|
||||
const UseCasesMock = require('../../mocks/use-cases')
|
||||
import adapters from '../../mocks/adapters/index.js'
|
||||
|
||||
import UseCasesMock from '../../mocks/use-cases/index.js'
|
||||
|
||||
describe('#RESTControllers', () => {
|
||||
let uut
|
||||
|
||||
@@ -3,20 +3,19 @@
|
||||
*/
|
||||
|
||||
// Public npm libraries
|
||||
const assert = require('chai').assert
|
||||
const sinon = require('sinon')
|
||||
import { assert } from 'chai'
|
||||
import sinon from 'sinon'
|
||||
|
||||
// Local support libraries
|
||||
const adapters = require('../../../mocks/adapters')
|
||||
const UseCasesMock = require('../../../mocks/use-cases')
|
||||
import adapters from '../../../mocks/adapters/index.js'
|
||||
import UseCasesMock from '../../../mocks/use-cases/index.js'
|
||||
import UserController from '../../../../../src/controllers/rest-api/users/controller.js'
|
||||
|
||||
const UserController = require('../../../../../src/controllers/rest-api/users/controller')
|
||||
import { context as mockContext } from '../../../../unit/mocks/ctx-mock.js'
|
||||
let uut
|
||||
let sandbox
|
||||
let ctx
|
||||
|
||||
const mockContext = require('../../../../unit/mocks/ctx-mock').context
|
||||
|
||||
describe('#Users-REST-Controller', () => {
|
||||
// const testUser = {}
|
||||
|
||||
|
||||
@@ -3,15 +3,19 @@
|
||||
*/
|
||||
|
||||
// Public npm libraries
|
||||
const assert = require('chai').assert
|
||||
const sinon = require('sinon')
|
||||
import { assert } from 'chai'
|
||||
|
||||
import sinon from 'sinon'
|
||||
|
||||
// Local support libraries
|
||||
const adapters = require('../../../mocks/adapters')
|
||||
const UseCasesMock = require('../../../mocks/use-cases')
|
||||
import adapters from '../../../mocks/adapters/index.js'
|
||||
|
||||
import UseCasesMock from '../../../mocks/use-cases/index.js'
|
||||
|
||||
// const app = require('../../../mocks/app-mock')
|
||||
|
||||
const UserRouter = require('../../../../../src/controllers/rest-api/users')
|
||||
import UserRouter from '../../../../../src/controllers/rest-api/users/index.js'
|
||||
|
||||
let uut
|
||||
let sandbox
|
||||
// let ctx
|
||||
|
||||
@@ -0,0 +1,82 @@
|
||||
/*
|
||||
Unit tests for the timer-controller.js Controller library
|
||||
*/
|
||||
|
||||
// Public npm libraries
|
||||
import { assert } from 'chai'
|
||||
import sinon from 'sinon'
|
||||
|
||||
// Local libraries
|
||||
import TimerControllers from '../../../src/controllers/timer-controllers.js'
|
||||
import adapters from '../mocks/adapters/index.js'
|
||||
import UseCasesMock from '../mocks/use-cases/index.js'
|
||||
|
||||
describe('#Timer-Controllers', () => {
|
||||
let uut
|
||||
let sandbox
|
||||
|
||||
beforeEach(() => {
|
||||
sandbox = sinon.createSandbox()
|
||||
|
||||
const useCases = new UseCasesMock()
|
||||
uut = new TimerControllers({ adapters, useCases })
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
sandbox.restore()
|
||||
|
||||
uut.stopTimers()
|
||||
})
|
||||
|
||||
describe('#constructor', () => {
|
||||
it('should throw an error if adapters are not passed in', () => {
|
||||
try {
|
||||
uut = new TimerControllers()
|
||||
|
||||
assert.fail('Unexpected code path')
|
||||
} catch (err) {
|
||||
assert.include(
|
||||
err.message,
|
||||
'Instance of Adapters library required when instantiating Timer Controller libraries.'
|
||||
)
|
||||
}
|
||||
})
|
||||
|
||||
it('should throw an error if useCases are not passed in', () => {
|
||||
try {
|
||||
uut = new TimerControllers({ adapters })
|
||||
|
||||
assert.fail('Unexpected code path')
|
||||
} catch (err) {
|
||||
assert.include(
|
||||
err.message,
|
||||
'Instance of Use Cases library required when instantiating Timer Controller libraries.'
|
||||
)
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
describe('#startTimers', () => {
|
||||
it('should start the timers', () => {
|
||||
const result = uut.startTimers()
|
||||
|
||||
uut.stopTimers()
|
||||
|
||||
assert.equal(result, true)
|
||||
})
|
||||
})
|
||||
|
||||
describe('#exampleTimerFunc', () => {
|
||||
it('should kick off the Use Case', async () => {
|
||||
const result = await uut.exampleTimerFunc()
|
||||
|
||||
assert.equal(result, true)
|
||||
})
|
||||
|
||||
it('should return false on error', async () => {
|
||||
const result = await uut.exampleTimerFunc(true)
|
||||
|
||||
assert.equal(result, false)
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -2,10 +2,10 @@
|
||||
Unit tests for the User entity library.
|
||||
*/
|
||||
|
||||
const assert = require('chai').assert
|
||||
const sinon = require('sinon')
|
||||
import { assert } from 'chai'
|
||||
|
||||
const User = require('../../../src/entities/user')
|
||||
import sinon from 'sinon'
|
||||
import User from '../../../src/entities/user.js'
|
||||
|
||||
let sandbox
|
||||
let uut
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
Unit tests for the config directory
|
||||
*/
|
||||
|
||||
import { assert } from 'chai'
|
||||
|
||||
let currentEnv
|
||||
|
||||
describe('#config', () => {
|
||||
before(() => {
|
||||
// Backup the current environment setting.
|
||||
currentEnv = process.env.SVC_ENV
|
||||
})
|
||||
|
||||
after(() => {
|
||||
// Restore the environment setting before starting these tests.
|
||||
process.env.SVC_ENV = currentEnv
|
||||
})
|
||||
|
||||
it('Should return development environment config by default', async () => {
|
||||
const importedConfig = await import('../../../config/index.js')
|
||||
const config = importedConfig.default
|
||||
// console.log('config: ', config)
|
||||
|
||||
assert.equal(config.env, 'dev')
|
||||
})
|
||||
|
||||
it('Should return test environment config', async () => {
|
||||
// Hack to dynamically import a library multiple times:
|
||||
// https://github.com/denoland/deno/issues/6946
|
||||
|
||||
process.env.SVC_ENV = 'test'
|
||||
|
||||
const importedConfig2 = await import('../../../config/index.js?foo=bar1')
|
||||
const config = importedConfig2.default
|
||||
// console.log('config: ', config)
|
||||
|
||||
assert.equal(config.env, 'test')
|
||||
})
|
||||
|
||||
it('Should return test environment config', async () => {
|
||||
process.env.SVC_ENV = 'prod'
|
||||
|
||||
const importedConfig3 = await import('../../../config/index.js?foo=bar2')
|
||||
const config = importedConfig3.default
|
||||
// console.log('config: ', config)
|
||||
|
||||
assert.equal(config.env, 'prod')
|
||||
})
|
||||
})
|
||||
@@ -3,13 +3,15 @@
|
||||
*/
|
||||
|
||||
// Public npm libraries
|
||||
// const assert = require('chai').assert
|
||||
const sinon = require('sinon')
|
||||
import { assert } from 'chai'
|
||||
import sinon from 'sinon'
|
||||
import passport from 'koa-passport'
|
||||
|
||||
// Local libraries
|
||||
const User = require('../../../src/adapters/localdb/models/users')
|
||||
const { passport, passportCallback } = require('../../../config/passport')
|
||||
const adaptersMock = require('../mocks/adapters')
|
||||
import User from '../../../src/adapters/localdb/models/users.js'
|
||||
|
||||
import { applyPassportMods, passportCallback } from '../../../config/passport.js'
|
||||
import adaptersMock from '../mocks/adapters/index.js'
|
||||
|
||||
describe('#passport', () => {
|
||||
let sandbox
|
||||
@@ -25,33 +27,6 @@ describe('#passport', () => {
|
||||
|
||||
afterEach(() => sandbox.restore())
|
||||
|
||||
describe('#serializeUser', () => {
|
||||
it('should serialize a user', () => {
|
||||
const user = {
|
||||
id: 'abc123'
|
||||
}
|
||||
const done = () => {}
|
||||
|
||||
passport.serializeUser(user, done)
|
||||
})
|
||||
})
|
||||
|
||||
describe('#deserializeUser', () => {
|
||||
it('should deserialize a user', () => {
|
||||
// Mock Users model.
|
||||
sandbox.stub(User, 'findById').resolves({ id })
|
||||
|
||||
passport.deserializeUser(id, done)
|
||||
})
|
||||
|
||||
it('should catch and handle errors', () => {
|
||||
// Force an error
|
||||
sandbox.stub(User, 'findById').rejects(new Error('test error'))
|
||||
|
||||
passport.deserializeUser(id, done)
|
||||
})
|
||||
})
|
||||
|
||||
describe('#passportCallback', () => {
|
||||
it('should return if user is found', () => {
|
||||
// Mock Users model.
|
||||
@@ -74,4 +49,45 @@ describe('#passport', () => {
|
||||
passportCallback(id, 'password', done)
|
||||
})
|
||||
})
|
||||
|
||||
describe('#applyPassportMods', () => {
|
||||
it('should apply modifications to default passport behavior', () => {
|
||||
const result = applyPassportMods(passport)
|
||||
|
||||
assert.equal(result, true)
|
||||
})
|
||||
})
|
||||
|
||||
describe('#serializeUser', () => {
|
||||
it('should serialize a user', () => {
|
||||
const user = {
|
||||
id: 'abc123'
|
||||
}
|
||||
const done = () => {}
|
||||
|
||||
applyPassportMods(passport)
|
||||
|
||||
passport.serializeUser(user, done)
|
||||
})
|
||||
})
|
||||
|
||||
describe('#deserializeUser', () => {
|
||||
it('should deserialize a user', () => {
|
||||
// Mock Users model.
|
||||
sandbox.stub(User, 'findById').resolves({ id })
|
||||
|
||||
applyPassportMods(passport)
|
||||
|
||||
passport.deserializeUser(id, done)
|
||||
})
|
||||
|
||||
it('should catch and handle errors', () => {
|
||||
// Force an error
|
||||
sandbox.stub(User, 'findById').rejects(new Error('test error'))
|
||||
|
||||
applyPassportMods(passport)
|
||||
|
||||
passport.deserializeUser(id, done)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -3,11 +3,11 @@
|
||||
*/
|
||||
|
||||
// Public npm libraries
|
||||
const assert = require('chai').assert
|
||||
const sinon = require('sinon')
|
||||
import { assert } from 'chai'
|
||||
import sinon from 'sinon'
|
||||
|
||||
// Local libraries
|
||||
const Server = require('../../../bin/server')
|
||||
import Server from '../../../bin/server.js'
|
||||
|
||||
describe('#server', () => {
|
||||
let uut, sandbox
|
||||
|
||||
@@ -131,4 +131,4 @@ class BchUseCaseMock {
|
||||
}
|
||||
const bch = new BchUseCaseMock()
|
||||
|
||||
module.exports = { ipfs, localdb, bch }
|
||||
export default { ipfs, localdb, bch }
|
||||
|
||||
@@ -113,7 +113,8 @@ const peerData = [
|
||||
}
|
||||
]
|
||||
|
||||
module.exports = {
|
||||
// module.exports = {
|
||||
export default {
|
||||
peers,
|
||||
peerData
|
||||
}
|
||||
|
||||
@@ -6,4 +6,4 @@ const app = {
|
||||
use: () => {}
|
||||
}
|
||||
|
||||
module.exports = app
|
||||
export default app;
|
||||
|
||||
@@ -12,8 +12,9 @@
|
||||
// const ctx = mockContext()
|
||||
// ...
|
||||
|
||||
const Stream = require('stream')
|
||||
const Koa = require('koa')
|
||||
import Stream from 'stream';
|
||||
|
||||
import Koa from 'koa';
|
||||
|
||||
const context = (req, res, app) => {
|
||||
const socket = new Stream.Duplex()
|
||||
@@ -43,8 +44,8 @@ const request = (req, res, app) => context(req, res, app).request
|
||||
|
||||
const response = (req, res, app) => context(req, res, app).response
|
||||
|
||||
module.exports = {
|
||||
export {
|
||||
context,
|
||||
request,
|
||||
response
|
||||
}
|
||||
};
|
||||
|
||||
@@ -12,4 +12,4 @@ class IPFSCoord {
|
||||
async subscribeToChat() {}
|
||||
}
|
||||
|
||||
module.exports = IPFSCoord
|
||||
export default IPFSCoord;
|
||||
|
||||
@@ -2,18 +2,24 @@
|
||||
Mocks for the js-ipfs
|
||||
*/
|
||||
|
||||
class IPFS {
|
||||
constructor () {
|
||||
this.ipfs = {}
|
||||
}
|
||||
// class IPFS {
|
||||
// constructor () {
|
||||
// this.ipfs = {}
|
||||
// }
|
||||
//
|
||||
// static create () {
|
||||
// const mockIpfs = new MockIpfsInstance()
|
||||
//
|
||||
// return mockIpfs
|
||||
// }
|
||||
//
|
||||
// async start () {}
|
||||
// }
|
||||
|
||||
static create () {
|
||||
const mockIpfs = new MockIpfsInstance()
|
||||
function create () {
|
||||
const mockIpfs = new MockIpfsInstance()
|
||||
|
||||
return mockIpfs
|
||||
}
|
||||
|
||||
async start () {}
|
||||
return mockIpfs
|
||||
}
|
||||
|
||||
class MockIpfsInstance {
|
||||
@@ -28,4 +34,4 @@ class MockIpfsInstance {
|
||||
stop () {}
|
||||
}
|
||||
|
||||
module.exports = IPFS
|
||||
export default create;
|
||||
|
||||
@@ -23,6 +23,7 @@ const data = [
|
||||
timestamp: '2020-11-14T12:15:55.231Z'
|
||||
}
|
||||
]
|
||||
module.exports = {
|
||||
|
||||
export default {
|
||||
data
|
||||
}
|
||||
};
|
||||
|
||||
@@ -60,4 +60,4 @@ class UseCasesMock {
|
||||
bch = new BchUseCaseMock()
|
||||
}
|
||||
|
||||
module.exports = UseCasesMock
|
||||
export default UseCasesMock;
|
||||
|
||||
@@ -206,7 +206,8 @@ const ipfsMockPeers = [
|
||||
}
|
||||
]
|
||||
|
||||
module.exports = {
|
||||
// module.exports = {
|
||||
export default {
|
||||
rpcData,
|
||||
mockRelayData,
|
||||
mockPeerData,
|
||||
|
||||
@@ -3,16 +3,18 @@
|
||||
*/
|
||||
|
||||
// Public npm libraries
|
||||
const assert = require('chai').assert
|
||||
const sinon = require('sinon')
|
||||
const EventEmitter = require('events')
|
||||
import { assert } from 'chai'
|
||||
|
||||
import sinon from 'sinon'
|
||||
import EventEmitter from 'events'
|
||||
|
||||
// Local support libraries
|
||||
// const testUtils = require('../../utils/test-utils')
|
||||
|
||||
// Unit under test (uut)
|
||||
const UseCases = require('../../../src/use-cases')
|
||||
const adapters = require('../mocks/adapters')
|
||||
import UseCases from '../../../src/use-cases/index.js'
|
||||
|
||||
import adapters from '../mocks/adapters/index.js'
|
||||
|
||||
describe('#use-cases', () => {
|
||||
let uut
|
||||
|
||||
@@ -5,15 +5,16 @@
|
||||
*/
|
||||
|
||||
// Public npm libraries
|
||||
const assert = require('chai').assert
|
||||
const sinon = require('sinon')
|
||||
import { assert } from 'chai'
|
||||
import sinon from 'sinon'
|
||||
|
||||
// Local support libraries
|
||||
// const testUtils = require('../../utils/test-utils')
|
||||
|
||||
// Unit under test (uut)
|
||||
const UserLib = require('../../../src/use-cases/user')
|
||||
const adapters = require('../mocks/adapters')
|
||||
import UserLib from '../../../src/use-cases/user.js'
|
||||
|
||||
import adapters from '../mocks/adapters/index.js'
|
||||
|
||||
describe('#users-use-case', () => {
|
||||
let uut
|
||||
@@ -329,22 +330,23 @@ describe('#users-use-case', () => {
|
||||
}
|
||||
})
|
||||
|
||||
// it('should update the user model', async () => {
|
||||
// const newData = {
|
||||
// email: 'test@test.com',
|
||||
// password: 'password',
|
||||
// name: 'testy tester'
|
||||
// }
|
||||
//
|
||||
// const result = await uut.updateUser(testUser, newData)
|
||||
//
|
||||
// // Assert that expected properties and values exist.
|
||||
// assert.property(result, '_id')
|
||||
// assert.property(result, 'email')
|
||||
// assert.equal(result.email, 'test@test.com')
|
||||
// assert.property(result, 'name')
|
||||
// assert.equal(result.name, 'testy tester')
|
||||
// })
|
||||
it('should update the user model', async () => {
|
||||
const newData = {
|
||||
email: 'test@test.com',
|
||||
password: 'password',
|
||||
name: 'testy tester'
|
||||
}
|
||||
testUser.save = async () => {}
|
||||
|
||||
const result = await uut.updateUser(testUser, newData)
|
||||
|
||||
// Assert that expected properties and values exist.
|
||||
assert.property(result, '_id')
|
||||
assert.property(result, 'email')
|
||||
assert.equal(result.email, 'test@test.com')
|
||||
assert.property(result, 'name')
|
||||
assert.equal(result.name, 'testy tester')
|
||||
})
|
||||
|
||||
// TODO: verify that an admin can change the type of a user
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user