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'; import * as helpers from './helpers'; async function init() { chai.use(chaiHttp); const app = express(); SetupApp(app); await models.sequelize.sync({ force: true }); return app; } describe('PUT /artist on nonexistent artist', () => { it('should fail', done => { init().then((app) => { chai .request(app) .put('/artist/1') .send({ id: 1, name: "NewArtistName" }) .then((res) => { expect(res).to.have.status(400); done(); }) }) }); }); describe('PUT /artist with an existing artist', () => { it('should succeed', done => { init().then((app) => { var req = chai.request(app).keepOpen(); helpers.createArtist(req, { name: "MyArtist" }, 200, { id: 1 }) .then(() => { helpers.modifyArtist(req, 1, { name: "MyNewArtist" }, 200) }) .then(() => { helpers.checkArtist(req, 1, 200, { name: "MyNewArtist" } )}) .then(req.close) .then(done); }); }); });