only allowed latest template version and allowed admin to set sample number
This commit is contained in:
@ -454,6 +454,16 @@ describe('/sample', () => {
|
||||
res: {status: 'Color not available for material'}
|
||||
});
|
||||
});
|
||||
it('rejects an undefined color for the same material', done => {
|
||||
TestHelper.request(server, done, {
|
||||
method: 'put',
|
||||
url: '/sample/400000000000000000000001',
|
||||
auth: {basic: 'janedoe'},
|
||||
httpStatus: 400,
|
||||
req: {type: 'part', color: 'signalviolet', batch: '114531', notes: {comment: 'Testcomment', sample_references: [{sample_id: '400000000000000000000003', relation: 'part to this sample'}]}},
|
||||
res: {status: 'Color not available for material'}
|
||||
});
|
||||
});
|
||||
it('rejects an unknown material id', done => {
|
||||
TestHelper.request(server, done, {
|
||||
method: 'put',
|
||||
@ -573,6 +583,26 @@ describe('/sample', () => {
|
||||
res: {_id: '400000000000000000000006', number: 'Rng36', type: 'granulate', color: 'black', batch: '', condition: {}, material_id: '100000000000000000000004', note_id: null, user_id: '000000000000000000000002'}
|
||||
});
|
||||
});
|
||||
it('rejects an old version of a condition template', done => {
|
||||
TestHelper.request(server, done, {
|
||||
method: 'put',
|
||||
url: '/sample/400000000000000000000001',
|
||||
auth: {basic: 'janedoe'},
|
||||
httpStatus: 400,
|
||||
req: {condition: {p1: 36, condition_template: '200000000000000000000004'}},
|
||||
res: {status: 'Old template version not allowed'}
|
||||
});
|
||||
});
|
||||
it('allows keeping an old version of a condition template', done => {
|
||||
TestHelper.request(server, done, {
|
||||
method: 'put',
|
||||
url: '/sample/400000000000000000000004',
|
||||
auth: {basic: 'admin'},
|
||||
httpStatus: 200,
|
||||
req: {condition: {p1: 36, condition_template: '200000000000000000000004'}},
|
||||
res: {_id: '400000000000000000000004', number: '32', type: 'granulate', color: 'black', batch: '1653000308', condition: {p1: 36, condition_template: '200000000000000000000004'}, material_id: '100000000000000000000005', note_id: '500000000000000000000003', user_id: '000000000000000000000003'}
|
||||
});
|
||||
});
|
||||
it('rejects an changing back to an empty condition', done => {
|
||||
TestHelper.request(server, done, {
|
||||
method: 'put',
|
||||
@ -1108,7 +1138,7 @@ describe('/sample', () => {
|
||||
res: {status: 'Material not available'}
|
||||
});
|
||||
});
|
||||
it('rejects a sample number', done => {
|
||||
it('rejects a sample number for a write user', done => {
|
||||
TestHelper.request(server, done, {
|
||||
method: 'post',
|
||||
url: '/sample/new',
|
||||
@ -1118,6 +1148,38 @@ describe('/sample', () => {
|
||||
res: {status: 'Invalid body format', details: '"number" is not allowed'}
|
||||
});
|
||||
});
|
||||
it('allows a sample number for an admin user', done => {
|
||||
TestHelper.request(server, done, {
|
||||
method: 'post',
|
||||
url: '/sample/new',
|
||||
auth: {basic: 'admin'},
|
||||
httpStatus: 200,
|
||||
req: {number: 'Rng34', color: 'black', type: 'granulate', batch: '1560237365', material_id: '100000000000000000000001', notes: {comment: 'Testcomment', sample_references: [{sample_id: '400000000000000000000003', relation: 'part to this sample'}]}},
|
||||
}).end((err, res) => {
|
||||
if (err) return done (err);
|
||||
should(res.body).have.only.keys('_id', 'number', 'color', 'type', 'batch', 'condition', 'material_id', 'note_id', 'user_id');
|
||||
should(res.body).have.property('_id').be.type('string');
|
||||
should(res.body).have.property('number', 'Rng34');
|
||||
should(res.body).have.property('color', 'black');
|
||||
should(res.body).have.property('type', 'granulate');
|
||||
should(res.body).have.property('batch', '1560237365');
|
||||
should(res.body).have.property('condition', {});
|
||||
should(res.body).have.property('material_id', '100000000000000000000001');
|
||||
should(res.body).have.property('note_id').be.type('string');
|
||||
should(res.body).have.property('user_id', '000000000000000000000003');
|
||||
done();
|
||||
});
|
||||
});
|
||||
it('rejects an existing sample number for an admin user', done => {
|
||||
TestHelper.request(server, done, {
|
||||
method: 'post',
|
||||
url: '/sample/new',
|
||||
auth: {basic: 'admin'},
|
||||
httpStatus: 400,
|
||||
req: {number: 'Rng33', color: 'black', type: 'granulate', batch: '1560237365', material_id: '100000000000000000000001', notes: {comment: 'Testcomment', sample_references: [{sample_id: '400000000000000000000003', relation: 'part to this sample'}]}},
|
||||
res: {status: 'Sample number already taken'}
|
||||
});
|
||||
});
|
||||
it('rejects an invalid sample reference', done => {
|
||||
TestHelper.request(server, done, {
|
||||
method: 'post',
|
||||
@ -1208,6 +1270,16 @@ describe('/sample', () => {
|
||||
res: {status: 'Condition template not available'}
|
||||
});
|
||||
});
|
||||
it('rejects an old version of a condition template', done => {
|
||||
TestHelper.request(server, done, {
|
||||
method: 'post',
|
||||
url: '/sample/new',
|
||||
auth: {basic: 'janedoe'},
|
||||
httpStatus: 400,
|
||||
req: {color: 'black', type: 'granulate', batch: '1560237365', condition: {p1: 36, condition_template: '200000000000000000000004'}, material_id: '100000000000000000000001', notes: {comment: 'Testcomment', sample_references: [{sample_id: '400000000000000000000003', relation: 'part to this sample'}]}},
|
||||
res: {status: 'Old template version not allowed'}
|
||||
});
|
||||
});
|
||||
it('rejects a missing color', done => {
|
||||
TestHelper.request(server, done, {
|
||||
method: 'post',
|
||||
|
Reference in New Issue
Block a user