mirror of
https://github.com/wassname/talk.git
synced 2026-07-13 14:47:33 +08:00
111 lines
2.7 KiB
JavaScript
111 lines
2.7 KiB
JavaScript
/* eslint-env node, mocha */
|
|
const Asset = require('../models/asset');
|
|
|
|
const expect = require('chai').expect;
|
|
const chai = require('chai');
|
|
const chaiHttp = require('chai-http');
|
|
const server = require('../app');
|
|
const should = chai.should();
|
|
should; // nullop to satisfy linting
|
|
|
|
chai.use(chaiHttp);
|
|
|
|
var fixture = {
|
|
'url': 'http://hhgg.com/total-perspective-vortex',
|
|
'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.an('array');
|
|
|
|
let asset = res.body[0];
|
|
|
|
expect(asset).to.have.property('id');
|
|
|
|
// Ensure the asset has the same id as above.
|
|
// This tests the single url per Id concept.
|
|
expect(assetId).to.equal(asset.id);
|
|
|
|
done();
|
|
|
|
});
|
|
});
|
|
});
|
|
});
|
|
}); // End describe /PUT Asset
|
|
|
|
});
|