You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
84 lines
2.4 KiB
84 lines
2.4 KiB
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('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); |
|
}) |
|
.then(done) |
|
}); |
|
}); |
|
}); |
|
|
|
describe('PUT /artist with an existing artist', () => { |
|
it('should succeed', done => { |
|
init().then((app) => { |
|
async function createArtist(req) { |
|
await req |
|
.post('/artist') |
|
.send({ |
|
name: "MyArtist" |
|
}) |
|
.then((res) => { |
|
expect(res).to.have.status(200); |
|
expect(res.body).to.deep.equal({ |
|
id: 1 |
|
}); |
|
}); |
|
} |
|
|
|
async function modifyArtist(req) { |
|
await req |
|
.put('/artist/1') |
|
.send({ |
|
name: "MyNewArtist", |
|
id: 1 |
|
}) |
|
.then((res) => { |
|
expect(res).to.have.status(200); |
|
}); |
|
} |
|
|
|
async function checkArtist(req) { |
|
await req |
|
.get('/artist/1') |
|
.then((res) => { |
|
expect(res).to.have.status(200); |
|
expect(res.body).to.deep.equal({ |
|
name: "MyNewArtist" |
|
}); |
|
}) |
|
} |
|
|
|
var req = chai.request(app).keepOpen(); |
|
|
|
init() |
|
.then(() => createArtist(req)) |
|
.then(() => modifyArtist(req)) |
|
.then(() => checkArtist(req)) |
|
.then(() => req.close()) |
|
.then(done); |
|
}); |
|
}); |
|
});
|
|
|