mirror of
https://github.com/wassname/talk.git
synced 2026-07-21 12:51:03 +08:00
108 lines
2.6 KiB
JavaScript
108 lines
2.6 KiB
JavaScript
/* eslint-env node, mocha */
|
|
const Asset = require('../models/asset');
|
|
|
|
const expect = require('chai').expect;
|
|
let chai = require('chai');
|
|
let chaiHttp = require('chai-http');
|
|
let server = require('../app');
|
|
let should = chai.should();
|
|
should; // nullop to satisfy linting
|
|
|
|
chai.use(chaiHttp);
|
|
|
|
var fixture = {
|
|
'url': 'simple',
|
|
'type': 'article',
|
|
'headline': 'The Total Perspective Vortex',
|
|
'summary': 'You are an insignificant dot on an insignificant dot.',
|
|
'section': 'Everything',
|
|
'authors': ['Ford Prefect']
|
|
};
|
|
|
|
|
|
describe('Asset', () => {
|
|
|
|
beforeEach((done) => {
|
|
|
|
// TODO: implement asset remove
|
|
Asset.removeAll({})
|
|
.then(() => {
|
|
done();
|
|
});
|
|
|
|
Asset; // nullop to satisfy linting.
|
|
|
|
});
|
|
|
|
describe('/GET Asset', () => {
|
|
describe.only('#get', () => {
|
|
it('It should get an empty array when there are no assets.', (done) => {
|
|
|
|
chai.request(server)
|
|
.get('/api/v1/asset')
|
|
.end((err, res) => {
|
|
|
|
if (err) {
|
|
throw new Error(err);
|
|
}
|
|
|
|
res.should.have.status(200);
|
|
res.body.should.be.a('array');
|
|
res.body.length.should.be.eql(0);
|
|
done();
|
|
});
|
|
|
|
});
|
|
});
|
|
});
|
|
|
|
// This test checks PUT and read
|
|
describe('/PUT Asset', () => {
|
|
describe.only('#put', () => {
|
|
it('It should save an asset and load it again.', (done) => {
|
|
|
|
chai.request(server)
|
|
.put('/api/v1/asset')
|
|
.send(fixture)
|
|
.end((err, res) => {
|
|
|
|
if (err) {
|
|
throw new Error(err);
|
|
}
|
|
|
|
res.should.have.status(200);
|
|
res.body.should.be.a('object');
|
|
|
|
// Id should be generated by the model if absent.
|
|
res.body.should.have.property('id');
|
|
|
|
// Save the asset id to compare with GET result.
|
|
let assetId = res.body.id;
|
|
|
|
// Load the asset to make sure it's really there.
|
|
chai.request(server)
|
|
.get('/api/v1/asset/url/' + fixture.url)
|
|
.end((err, res) => {
|
|
|
|
if (err) {
|
|
throw new Error(err);
|
|
}
|
|
|
|
res.should.have.status(200);
|
|
res.body.should.be.a('object');
|
|
res.body.should.have.property('id');
|
|
|
|
// Ensure the asset has the same id as above.
|
|
// This tests the single url per Id concept.
|
|
expect(assetId).to.equal(res.body.id);
|
|
|
|
done();
|
|
|
|
});
|
|
});
|
|
});
|
|
});
|
|
}); // End describe /PUT Asset
|
|
|
|
});
|