first commit

This commit is contained in:
Chris Troutner
2026-06-02 16:44:51 -07:00
commit 02128422af
27 changed files with 7994 additions and 0 deletions
@@ -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')
})
})
+36
View File
@@ -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'
})
})
})