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.
 
 
 
 

119 lines
3.8 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';
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('POST /song with no title', () => {
it('should fail', done => {
init().then((app) => {
chai
.request(app)
.post('/song')
.send({})
.then((res) => {
expect(res).to.have.status(400);
done();
});
})
});
});
describe('POST /song with only a title', () => {
it('should return the first available id', done => {
init().then(async(app) => {
chai
.request(app)
.post('/song')
.send({
title: "MySong"
})
.then((res) => {
expect(res).to.have.status(200);
expect(res.body).to.deep.equal({
id: 1
});
done();
});
})
});
});
describe('POST /song with a nonexistent artist Id', () => {
it('should fail', done => {
init().then(async (app) => {
chai
.request(app)
.post('/song')
.send({
title: "MySong",
artistIds: [1]
})
.then((res) => {
expect(res).to.have.status(400);
done();
});
})
});
});
describe('POST /song with an existing artist Id', () => {
it('should succeed', done => {
init().then((app) => {
var req = chai.request(app).keepOpen();
helpers.createArtist(req, { name: "MyArtist" }, 200, { id: 1 })
.then(() => helpers.createSong(req, { title: "MySong", artistIds: [ 1 ] }, 200, { id: 1 }) )
.then(req.close)
.then(done);
});
});
});
describe('POST /song with two existing artist Ids', () => {
it('should succeed', done => {
init().then((app) => {
var req = chai.request(app).keepOpen();
helpers.createArtist(req, { name: "Artist1" }, 200, { id: 1 })
.then(() => helpers.createArtist(req, { name: "Artist2" }, 200, { id: 2 }) )
.then(() => helpers.createSong(req, { title: "MySong", artistIds: [1, 2] }, 200, { id: 1 }) )
.then(req.close)
.then(done);
});
});
});
describe('POST /song with an existent and a nonexistent artist Id', () => {
it('should fail', done => {
init().then((app) => {
var req = chai.request(app).keepOpen();
helpers.createArtist(req, { name: "Artist1" }, 200, { id: 1 })
.then(() => helpers.createSong(req, { title: "MySong", artistIds: [1, 2] }, 400) )
.then(req.close)
.then(done);
});
});
});
describe('POST /song 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.createSong(req, { title: "Song", tagIds: [ 1, 2 ] }, 200, { id: 1 }))
.then(() => helpers.checkSong(req, 1, 200, { title: "Song", storeLinks: [], tagIds: [ 1, 2 ], albumIds: [], artistIds: [] }))
.then(req.close)
.then(done);
});
});
});