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 /artist/modify on nonexistent artist', () => { it('should fail', done => { init().then((app) => { chai .request(app) .post('/artist/modify') .send({ id: 1, name: "NewArtistName" }) .then((res) => { expect(res).to.have.status(400); }) .then(done) }); }); }); describe('POST /artist/modify with an existing artist', () => { it('should succeed', done => { init().then((app) => { async function createArtist() { await chai.request(app) .post('/artist/create') .send({ name: "MyArtist" }) .then((res) => { expect(res).to.have.status(200); expect(res.body).to.deep.equal({ id: 1 }); }); } async function modifyArtist() { chai.request(app) .post('/artist/modify') .send({ name: "MyNewArtist", id: 1 }) .then((res) => { expect(res).to.have.status(200); }); } // TODO: Check artist init() .then(createArtist) .then(modifyArtist) .then(done); }); }); });