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.
97 lines
3.0 KiB
97 lines
3.0 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 /album with no name', () => { |
|
it('should fail', done => { |
|
init().then((app) => { |
|
chai |
|
.request(app) |
|
.post('/album') |
|
.send({}) |
|
.then((res) => { |
|
expect(res).to.have.status(400); |
|
done(); |
|
}); |
|
}); |
|
}); |
|
}); |
|
|
|
describe('POST /album with a correct request', () => { |
|
it('should succeed', done => { |
|
init().then((app) => { |
|
chai |
|
.request(app) |
|
.post('/album') |
|
.send({ |
|
name: "MyAlbum" |
|
}) |
|
.then((res) => { |
|
expect(res).to.have.status(200); |
|
expect(res.body).to.deep.equal({ |
|
id: 1 |
|
}); |
|
done(); |
|
}); |
|
}); |
|
}); |
|
}); |
|
|
|
|
|
describe('PUT /album on nonexistent album', () => { |
|
it('should fail', done => { |
|
init().then((app) => { |
|
chai |
|
.request(app) |
|
.put('/album/1') |
|
.send({ |
|
id: 1, |
|
name: "NewAlbumName" |
|
}) |
|
.then((res) => { |
|
expect(res).to.have.status(400); |
|
done(); |
|
}) |
|
}) |
|
}); |
|
}); |
|
|
|
describe('PUT /album with an existing album', () => { |
|
it('should succeed', done => { |
|
init().then((app) => { |
|
var req = chai.request(app).keepOpen(); |
|
helpers.createAlbum(req, { name: "MyAlbum" }, 200, { id: 1 }) |
|
.then(() => helpers.modifyAlbum(req, 1, { name: "MyNewAlbum" }, 200)) |
|
.then(() => helpers.checkAlbum(req, 1, 200, { name: "MyNewAlbum", storeLinks: [], tagIds: [], songIds: [], artistIds: [] })) |
|
.then(req.close) |
|
.then(done); |
|
}); |
|
}); |
|
}); |
|
|
|
describe('POST /album 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.createAlbum(req, { name: "MyAlbum", tagIds: [ 1, 2 ] }, 200, { id: 1 })) |
|
.then(() => helpers.checkAlbum(req, 1, 200, { name: "MyAlbum", storeLinks: [], tagIds: [ 1, 2 ], songIds: [], artistIds: [] })) |
|
.then(req.close) |
|
.then(done); |
|
}); |
|
}); |
|
}); |
|
|
|
|