'use strict' import { build } from './app.ts' import { use, expect } from "chai" import sinonChai from 'sinon-chai' use(sinonChai) describe('app', function () { const app = build({}, 'postgres://') describe('/', function () { it('GET', async function () { const response = await app.inject({ method: 'GET', url: '/' }) expect(response.statusCode).to.equal(200) expect(JSON.parse(response.body)).to.have.property('version') }) }) xdescribe('/api/records', function () { it('GET -- list the records', async function () { const response = await app.inject({ method: 'GET', url: '/api/records' }) expect(response.statusCode).to.equal(200) const body = JSON.parse(response.body) expect(body).to.have.property('data') expect(body.data).to.be.an.instanceof(Array); }) it('DELETE -- delete all records', async function () { const response = await app.inject({ method: 'DELETE', url: '/api/records' }) expect(response.statusCode).to.equal(200) const body = JSON.parse(response.body) expect(body).to.have.property('data') expect(body.data).to.be.lengthOf(0); }) }) describe('/api/record', function () { describe('POST', function () { it('should create', async function () { let url = 'https://example.com/my-cool-stream' const response = await app.inject({ method: 'POST', url: '/api/record', body: { url } }) expect(response.statusCode).to.equal(200) const body = JSON.parse(response.body) expect(body).to.have.property('id') expect(body).to.have.property('url', url) }) it('should return 400 if url is missing', async function () { const response = await app.inject({ method: 'POST', url: '/api/record', }) expect(response.statusCode).to.equal(400) }) }) xit('GET -- list a record', async function () { const response = await app.inject({ method: 'GET', url: '/api/record' }) expect(response.statusCode).to.equal(200) expect(JSON.parse(response.body)).to.have.property('id') expect(JSON.parse(response.body)).to.have.property('sourceUrl') expect(JSON.parse(response.body)).to.have.property('fileSize') expect(JSON.parse(response.body)).to.have.property('outputUrl') }) it('DELETE -- delete a record', async function () { const response = await app.inject({ method: 'DELETE', url: '/api/record' }) expect(response.statusCode).to.equal(200) expect(JSON.parse(response.body)).to.have.property('id') }) }) })