const chai = require('chai'); const chaiHttp = require('chai-http'); const express = require('express'); const models = require('../../../models'); import { SetupApp } from '../../../app'; import { expect } from 'chai'; async function init() { chai.use(chaiHttp); const app = express(); SetupApp(app); await models.sequelize.sync({ force: true }); return app; } describe('POST /song/query with no songs', () => { it('should give empty list', done => { init().then((app) => { chai .request(app) .post('/song/query') .send({ 'query': {} }) .end((err, res) => { expect(err).to.be.null; expect(res).to.have.status(200); expect(res.body).to.deep.equal({ ids: [] }); done(); }); }); }); }); describe('POST /song/query with several songs', () => { it('should give empty list', done => { init().then((app) => { async function createSong(req) { await req .post('/song') .send({ title: "Song" }) .then((res) => { expect(res).to.have.status(200); }); } async function checkSongs(req) { await req .post('/song/query') .send({ "query": {} }) .then((res) => { expect(res).to.have.status(200); expect(res.body).to.deep.equal({ ids: [1, 2, 3] }); }); } var req = chai.request(app).keepOpen(); createSong(req) .then(() => createSong(req)) .then(() => createSong(req)) .then(() => checkSongs(req)) .then(() => req.close()) .then(done) }); }); });