adjusted sample
This commit is contained in:
@ -5,7 +5,6 @@ import NoteFieldModel from '../models/note_field';
|
||||
import TestHelper from "../test/helper";
|
||||
// TODO: generate sample number
|
||||
// TODO: think again which parameters are required at POST
|
||||
// TODO: status
|
||||
|
||||
describe('/sample', () => {
|
||||
let server;
|
||||
@ -23,7 +22,7 @@ describe('/sample', () => {
|
||||
}).end((err, res) => {
|
||||
if (err) return done(err);
|
||||
const json = require('../test/db.json');
|
||||
should(res.body).have.lengthOf(json.collections.samples.length);
|
||||
should(res.body).have.lengthOf(json.collections.samples.filter(e => e.status === 10).length);
|
||||
should(res.body).matchEach(material => {
|
||||
should(material).have.only.keys('_id', 'number', 'type', 'color', 'batch', 'material_id', 'note_id', 'user_id');
|
||||
should(material).have.property('_id').be.type('string');
|
||||
@ -47,7 +46,7 @@ describe('/sample', () => {
|
||||
}).end((err, res) => {
|
||||
if (err) return done(err);
|
||||
const json = require('../test/db.json');
|
||||
should(res.body).have.lengthOf(json.collections.samples.length);
|
||||
should(res.body).have.lengthOf(json.collections.samples.filter(e => e.status === 10).length);
|
||||
should(res.body).matchEach(material => {
|
||||
should(material).have.only.keys('_id', 'number', 'type', 'color', 'batch', 'material_id', 'note_id', 'user_id');
|
||||
should(material).have.property('_id').be.type('string');
|
||||
@ -88,8 +87,41 @@ describe('/sample', () => {
|
||||
url: '/sample/400000000000000000000001',
|
||||
auth: {basic: 'janedoe'},
|
||||
httpStatus: 200,
|
||||
req: {number: '1', type: 'granulate', color: 'black', batch: '', material_id: '100000000000000000000004', notes: {}},
|
||||
res: {_id: '400000000000000000000001', number: '1', type: 'granulate', color: 'black', batch: '', material_id: '100000000000000000000004', note_id: null, user_id: '000000000000000000000002'}
|
||||
req: {number: '1', type: 'granulate', color: 'black', batch: '', material_id: '100000000000000000000004', notes: {}}
|
||||
}).end((err, res) => {
|
||||
if (err) return done(err);
|
||||
should(res.body).be.eql({_id: '400000000000000000000001', number: '1', type: 'granulate', color: 'black', batch: '', material_id: '100000000000000000000004', note_id: null, user_id: '000000000000000000000002'});
|
||||
SampleModel.findById('400000000000000000000001').lean().exec((err, data: any) => {
|
||||
if (err) return done (err);
|
||||
should(data).have.only.keys('_id', 'number', 'color', 'type', 'batch', 'material_id', 'note_id', 'user_id', 'status', '__v');
|
||||
should(data).have.property('_id');
|
||||
should(data).have.property('number', '1');
|
||||
should(data).have.property('color', 'black');
|
||||
should(data).have.property('type', 'granulate');
|
||||
should(data).have.property('batch', '');
|
||||
should(data.material_id.toString()).be.eql('100000000000000000000004');
|
||||
should(data.user_id.toString()).be.eql('000000000000000000000002');
|
||||
should(data).have.property('status', 10);
|
||||
should(data).have.property('note_id', null);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
it('keeps only one unchanged parameter', done => {
|
||||
TestHelper.request(server, done, {
|
||||
method: 'put',
|
||||
url: '/sample/400000000000000000000001',
|
||||
auth: {basic: 'janedoe'},
|
||||
httpStatus: 200,
|
||||
req: {type: 'granulate'}
|
||||
}).end((err, res) => {
|
||||
if (err) return done(err);
|
||||
should(res.body).be.eql({_id: '400000000000000000000001', number: '1', type: 'granulate', color: 'black', batch: '', material_id: '100000000000000000000004', note_id: null, user_id: '000000000000000000000002'});
|
||||
SampleModel.findById('400000000000000000000001').lean().exec((err, data: any) => {
|
||||
if (err) return done (err);
|
||||
should(data).have.property('status', 10);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
it('changes the given properties', done => {
|
||||
@ -103,15 +135,15 @@ describe('/sample', () => {
|
||||
if (err) return done (err);
|
||||
SampleModel.findById('400000000000000000000001').lean().exec((err, data: any) => {
|
||||
if (err) return done (err);
|
||||
should(data).have.only.keys('_id', 'number', 'color', 'type', 'batch', 'validated', 'material_id', 'note_id', 'user_id', '__v');
|
||||
should(data).have.only.keys('_id', 'number', 'color', 'type', 'batch', 'material_id', 'note_id', 'user_id', 'status', '__v');
|
||||
should(data).have.property('_id');
|
||||
should(data).have.property('number', '10');
|
||||
should(data).have.property('color', 'signalviolet');
|
||||
should(data).have.property('type', 'part');
|
||||
should(data).have.property('batch', '114531');
|
||||
should(data).have.property('validated').be.type('boolean');
|
||||
should(data.material_id.toString()).be.eql('100000000000000000000002');
|
||||
should(data.user_id.toString()).be.eql('000000000000000000000002');
|
||||
should(data).have.property('status', 0);
|
||||
should(data).have.property('note_id');
|
||||
NoteModel.findById(data.note_id).lean().exec((err, data: any) => {
|
||||
if (err) return done (err);
|
||||
@ -123,7 +155,7 @@ describe('/sample', () => {
|
||||
should(data.sample_references[0]).have.property('relation', 'part to this sample');
|
||||
done();
|
||||
});
|
||||
})
|
||||
});
|
||||
});
|
||||
});
|
||||
it('adjusts the note_fields correctly', done => {
|
||||
@ -315,7 +347,7 @@ describe('/sample', () => {
|
||||
});
|
||||
|
||||
describe('DELETE /sample/{id}', () => {
|
||||
it('deletes the sample', done => {
|
||||
it('sets the status to deleted', done => {
|
||||
TestHelper.request(server, done, {
|
||||
method: 'delete',
|
||||
url: '/sample/400000000000000000000001',
|
||||
@ -324,14 +356,23 @@ describe('/sample', () => {
|
||||
}).end((err, res) => {
|
||||
if (err) return done(err);
|
||||
should(res.body).be.eql({status: 'OK'});
|
||||
SampleModel.findById('400000000000000000000001').lean().exec((err, data) => {
|
||||
SampleModel.findById('400000000000000000000001').lean().exec((err, data: any) => {
|
||||
if (err) return done(err);
|
||||
should(data).be.null();
|
||||
should(data).have.only.keys('_id', 'number', 'color', 'type', 'batch', 'material_id', 'note_id', 'user_id', 'status', '__v');
|
||||
should(data).have.property('_id');
|
||||
should(data).have.property('number', '1');
|
||||
should(data).have.property('color', 'black');
|
||||
should(data).have.property('type', 'granulate');
|
||||
should(data).have.property('batch', '');
|
||||
should(data.material_id.toString()).be.eql('100000000000000000000004');
|
||||
should(data.user_id.toString()).be.eql('000000000000000000000002');
|
||||
should(data).have.property('status', -1);
|
||||
should(data).have.property('note_id', null);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
it('deletes the notes of the sample', done => {
|
||||
it('keeps the notes of the sample', done => {
|
||||
TestHelper.request(server, done, {
|
||||
method: 'delete',
|
||||
url: '/sample/400000000000000000000002',
|
||||
@ -342,7 +383,9 @@ describe('/sample', () => {
|
||||
should(res.body).be.eql({status: 'OK'});
|
||||
NoteModel.findById('500000000000000000000001').lean().exec((err, data) => {
|
||||
if (err) return done(err);
|
||||
should(data).be.null();
|
||||
should(data).have.only.keys('_id', 'comment', 'sample_references', '__v');
|
||||
should(data).have.property('comment', 'Stoff gesperrt');
|
||||
should(data).have.property('sample_references').with.lengthOf(0);
|
||||
done();
|
||||
});
|
||||
});
|
||||
@ -367,7 +410,7 @@ describe('/sample', () => {
|
||||
});
|
||||
});
|
||||
});
|
||||
it('resets references to this sample', done => {
|
||||
it('keeps references to this sample', done => {
|
||||
TestHelper.request(server, done, {
|
||||
method: 'delete',
|
||||
url: '/sample/400000000000000000000003',
|
||||
@ -377,10 +420,12 @@ describe('/sample', () => {
|
||||
if (err) return done(err);
|
||||
should(res.body).be.eql({status: 'OK'});
|
||||
setTimeout(() => { // background action takes some time before we can check
|
||||
NoteModel.findById('500000000000000000000003').lean().exec((err, data) => {
|
||||
NoteModel.findById('500000000000000000000003').lean().exec((err, data: any) => {
|
||||
if (err) return done(err);
|
||||
console.log(data);
|
||||
should(data).have.property('sample_references').with.lengthOf(0);
|
||||
should(data).have.property('sample_references').with.lengthOf(1);
|
||||
should(data.sample_references[0].id.toString()).be.eql('400000000000000000000003');
|
||||
should(data.sample_references[0]).have.property('relation', 'part to sample');
|
||||
done();
|
||||
});
|
||||
}, 100);
|
||||
@ -398,7 +443,7 @@ describe('/sample', () => {
|
||||
should(res.body).be.eql({status: 'OK'});
|
||||
SampleModel.findById('400000000000000000000001').lean().exec((err, data) => {
|
||||
if (err) return done(err);
|
||||
should(data).be.null();
|
||||
should(data).have.property('status', -1);
|
||||
done();
|
||||
});
|
||||
});
|
||||
@ -486,7 +531,7 @@ describe('/sample', () => {
|
||||
SampleModel.find({number: 'Rng172'}).lean().exec((err, data: any) => {
|
||||
if (err) return done (err);
|
||||
should(data).have.lengthOf(1);
|
||||
should(data[0]).have.only.keys('_id', 'number', 'color', 'type', 'batch', 'material_id', 'note_id', 'user_id', '__v');
|
||||
should(data[0]).have.only.keys('_id', 'number', 'color', 'type', 'batch', 'material_id', 'note_id', 'user_id', 'status', '__v');
|
||||
should(data[0]).have.property('_id');
|
||||
should(data[0]).have.property('number', 'Rng172');
|
||||
should(data[0]).have.property('color', 'black');
|
||||
@ -494,6 +539,7 @@ describe('/sample', () => {
|
||||
should(data[0]).have.property('batch', '1560237365');
|
||||
should(data[0].material_id.toString()).be.eql('100000000000000000000001');
|
||||
should(data[0].user_id.toString()).be.eql('000000000000000000000002');
|
||||
should(data[0]).have.property('status', 0);
|
||||
should(data[0]).have.property('note_id');
|
||||
NoteModel.findById(data[0].note_id).lean().exec((err, data: any) => {
|
||||
if (err) return done (err);
|
||||
|
Reference in New Issue
Block a user