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.
 
 
 
 

86 lines
2.8 KiB

const chai = require('chai');
const chaiHttp = require('chai-http');
const express = require('express');
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 helpers.initTestDB(), '');
return app;
}
describe('POST /artist with no name', () => {
it('should fail', done => {
init().then((app) => {
chai
.request(app)
.post('/artist')
.send({})
.then((res) => {
expect(res).to.have.status(400);
done();
});
});
});
});
describe('POST /artist with a correct request', () => {
it('should succeed', done => {
init().then((app) => {
var req = chai.request(app).keepOpen();
helpers.createArtist(req, { name: "MyArtist" }, 200, { id: 1 })
.then(() => helpers.checkArtist(req, 1, 200, { name: "MyArtist", storeLinks: [], tagIds: [] }))
.then(req.close)
.then(done);
});
});
});
describe('PUT /artist on nonexistent artist', () => {
it('should fail', done => {
init().then((app) => {
chai
.request(app)
.put('/artist/0')
.send({
id: 0,
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", storeLinks: [], tagIds: [] }))
.then(req.close)
.then(done);
});
});
});
describe('POST /artist with tags', () => {
it('should succeed', done => {
init().then((app) => {
var req = chai.request(app).keepOpen();
helpers.createTag(req, { name: "Root" }, 200, { id: 1 })
.then(() => helpers.createTag(req, { name: "Leaf", parentId: 1 }, 200, { id: 2 }))
.then(() => helpers.createArtist(req, { name: "MyArtist", tagIds: [ 1, 2 ] }, 200, { id: 1 }))
.then(() => helpers.checkArtist(req, 1, 200, { name: "MyArtist", storeLinks: [], tagIds: [ 1, 2 ] }))
.then(req.close)
.then(done);
});
});
});