mirror of
https://github.com/Permissionless-Software-Foundation/psf-memo-db.git
synced 2026-09-21 16:52:02 -07:00
first commit
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
Unit tests for level REST controller.
|
||||
*/
|
||||
|
||||
import { assert } from 'chai'
|
||||
import sinon from 'sinon'
|
||||
import LevelRESTControllerLib from '../../../src/controllers/rest-api/level/controller.js'
|
||||
|
||||
describe('#LevelRESTController', () => {
|
||||
let uut
|
||||
let sandbox
|
||||
const mockDb = {
|
||||
get: sinon.stub().resolves({ text: 'hello' }),
|
||||
put: sinon.stub().resolves(),
|
||||
del: sinon.stub().resolves()
|
||||
}
|
||||
|
||||
beforeEach(() => {
|
||||
sandbox = sinon.createSandbox()
|
||||
uut = new LevelRESTControllerLib({
|
||||
adapters: {
|
||||
level: { postsDb: mockDb, statusDb: mockDb },
|
||||
dbBackup: { zipDb: sandbox.stub().resolves(true) }
|
||||
},
|
||||
useCases: {}
|
||||
})
|
||||
})
|
||||
|
||||
afterEach(() => sandbox.restore())
|
||||
|
||||
it('should get status', async () => {
|
||||
const ctx = { params: { statusKey: 'status' }, body: null }
|
||||
await uut.getStatus(ctx)
|
||||
assert.deepEqual(ctx.body, { text: 'hello' })
|
||||
})
|
||||
|
||||
it('should create a post via entity handler', async () => {
|
||||
const ctx = {
|
||||
params: {},
|
||||
request: { body: { txid: 'abc', postData: { addr: '1', text: 'hi' } } },
|
||||
body: null
|
||||
}
|
||||
await uut.entityHandlers.post.create(ctx)
|
||||
assert.equal(ctx.body.success, true)
|
||||
assert.equal(ctx.body.txid, 'abc')
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
Unit tests for bin/server.js
|
||||
*/
|
||||
|
||||
import { assert } from 'chai'
|
||||
import sinon from 'sinon'
|
||||
import Server from '../../../bin/server.js'
|
||||
|
||||
describe('#server', () => {
|
||||
let uut
|
||||
let sandbox
|
||||
|
||||
beforeEach(() => {
|
||||
sandbox = sinon.createSandbox()
|
||||
uut = new Server()
|
||||
})
|
||||
|
||||
afterEach(() => sandbox.restore())
|
||||
|
||||
describe('#startServer', () => {
|
||||
it('should start the server', async () => {
|
||||
sandbox.stub(uut.controllers, 'initAdapters').resolves()
|
||||
sandbox.stub(uut.controllers, 'initUseCases').resolves()
|
||||
sandbox.stub(uut.controllers, 'attachRESTControllers').resolves()
|
||||
sandbox.stub(uut.controllers, 'attachControllers').resolves()
|
||||
uut.config.env = 'dev'
|
||||
uut.config.port = 5041
|
||||
|
||||
const result = await uut.startServer()
|
||||
|
||||
assert.property(result, 'env')
|
||||
uut.server.close()
|
||||
uut.config.env = 'test'
|
||||
})
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user