Forked from ipfs-service-provider

This commit is contained in:
Chris Troutner
2021-07-13 12:34:51 -07:00
commit 677e82a689
111 changed files with 58318 additions and 0 deletions
+50
View File
@@ -0,0 +1,50 @@
/*
Mocks for the Adapter library.
*/
const ipfs = {
ipfsAdapter: {
ipfs: {}
},
ipfsCoordAdapter: {
ipfsCoord: {}
}
}
const localdb = {
Users: class Users {
static findById () {}
static find () {}
static findOne () {
return {
validatePassword: localdb.validatePassword
}
}
async save () {
return {}
}
generateToken () {
return '123'
}
toJSON () {
return {}
}
async remove () {
return true
}
async validatePassword () {
return true
}
},
validatePassword: () => {
return true
}
}
module.exports = { ipfs, localdb }
+9
View File
@@ -0,0 +1,9 @@
/*
Mocks for Koa 'app' object.
*/
const app = {
use: () => {}
}
module.exports = app
+50
View File
@@ -0,0 +1,50 @@
// Ripped from https://github.com/koajs/koa/blob/master/test/helpers/context.js
// Solution courtesy of user @fl0w. See: https://github.com/koajs/koa/issues/999#issuecomment-309270599
// Take from this gist: https://gist.github.com/emmanuelnk/f1254eed8f947a81e8d715476d9cc92c
// if you want more comprehensive Koa Context object to test stuff like Cookies etc
// then use https://www.npmjs.com/package/@shopify/jest-koa-mocks (requires Jest)
// INSTRUCTIONS:
// Import in test file as below:
//
// const mockContext = require('./mocks/ctx-mock').context
// const ctx = mockContext()
// ...
const Stream = require('stream')
const Koa = require('koa')
const context = (req, res, app) => {
const socket = new Stream.Duplex()
req = Object.assign(
{ headers: {}, socket },
Stream.Readable.prototype,
req || {}
)
res = Object.assign(
{ _headers: {}, socket },
Stream.Writable.prototype,
res || {}
)
req.socket.remoteAddress = req.socket.remoteAddress || '127.0.0.1'
app = app || new Koa()
res.getHeader = k => res._headers[k.toLowerCase()]
res.setHeader = (k, v) => (res._headers[k.toLowerCase()] = v)
res.removeHeader = (k, v) => delete res._headers[k.toLowerCase()]
const retApp = app.createContext(req, res)
return retApp
}
const request = (req, res, app) => context(req, res, app).request
const response = (req, res, app) => context(req, res, app).response
module.exports = {
context,
request,
response
}
+13
View File
@@ -0,0 +1,13 @@
/*
Mocks for the ipfs-coord library
*/
class IPFSCoord {
async isReady () {
return true
}
async start () {}
}
module.exports = IPFSCoord
+31
View File
@@ -0,0 +1,31 @@
/*
Mocks for the js-ipfs
*/
class IPFS {
constructor () {
this.ipfs = {}
}
static create () {
const mockIpfs = new MockIpfsInstance()
return mockIpfs
}
async start () {}
}
class MockIpfsInstance {
constructor () {
this.config = {
profiles: {
apply: () => {}
}
}
}
stop () {}
}
module.exports = IPFS
+28
View File
@@ -0,0 +1,28 @@
// Mocks representing an array of logs for the
// Unit tests of logapi
const data = [
{
message: 'Error in lib/nodemailer.js/validateEmailArray()',
level: 'error',
timestamp: '2020-11-14T12:15:55.230Z'
},
{
message: 'Error in lib/nodemailer.js/validateEmailArray()',
level: 'error',
timestamp: '2020-11-14T12:15:55.231Z'
},
{
message: 'Error in lib/nodemailer.js/validateEmailArray()',
level: 'error',
timestamp: '2020-11-14T12:15:55.230Z'
},
{
message: 'Error in lib/nodemailer.js/validateEmailArray()',
level: 'error',
timestamp: '2020-11-14T12:15:55.231Z'
}
]
module.exports = {
data
}
+42
View File
@@ -0,0 +1,42 @@
/*
Mocks for the use cases.
*/
/* eslint-disable */
class UserUseCaseMock {
async createUser(userObj) {
return {}
}
async getAllUsers() {
return true
}
async getUser(params) {
return true
}
async updateUser(existingUser, newData) {
return true
}
async deleteUser(user) {
return true
}
async authUser(login, passwd) {
return {
generateToken: () => {}
}
}
}
class UseCasesMock {
constuctor(localConfig = {}) {
// this.user = new UserUseCaseMock(localConfig)
}
user = new UserUseCaseMock()
}
module.exports = UseCasesMock