changed status and returned status for /samples
This commit is contained in:
@ -4,7 +4,6 @@ import NoteModel from '../models/note';
|
||||
import NoteFieldModel from '../models/note_field';
|
||||
import MeasurementModel from '../models/measurement';
|
||||
import TestHelper from "../test/helper";
|
||||
import globals from '../globals';
|
||||
import mongoose from 'mongoose';
|
||||
|
||||
|
||||
@ -31,7 +30,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.filter(e => e.status ===globals.status.validated).length);
|
||||
should(res.body).have.lengthOf(json.collections.samples.filter(e => e.status ==='validated').length);
|
||||
should(res.body).matchEach(sample => {
|
||||
should(sample).have.only.keys('_id', 'number', 'type', 'color', 'batch', 'condition', 'material_id', 'note_id', 'user_id', 'added');
|
||||
should(sample).have.property('_id').be.type('string');
|
||||
@ -58,7 +57,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.filter(e => e.status ===globals.status.validated).length);
|
||||
should(res.body).have.lengthOf(json.collections.samples.filter(e => e.status ==='validated').length);
|
||||
should(res.body).matchEach(sample => {
|
||||
should(sample).have.only.keys('_id', 'number', 'type', 'color', 'batch', 'condition', 'material_id', 'note_id', 'user_id', 'added');
|
||||
should(sample).have.property('_id').be.type('string');
|
||||
@ -85,7 +84,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.filter(e => e.status ===globals.status.new).length);
|
||||
should(res.body).have.lengthOf(json.collections.samples.filter(e => e.status ==='new').length);
|
||||
should(res.body).matchEach(sample => {
|
||||
should(sample).have.only.keys('_id', 'number', 'type', 'color', 'batch', 'condition', 'material_id', 'note_id', 'user_id', 'added');
|
||||
should(sample).have.property('_id').be.type('string');
|
||||
@ -245,6 +244,19 @@ describe('/sample', () => {
|
||||
done();
|
||||
});
|
||||
});
|
||||
it('adds the status if specified', done => {
|
||||
TestHelper.request(server, done, {
|
||||
method: 'get',
|
||||
url: '/samples?status=all&fields[]=number&fields[]=status',
|
||||
auth: {basic: 'janedoe'},
|
||||
httpStatus: 200
|
||||
}).end((err, res) => {
|
||||
if (err) return done(err);
|
||||
should(res.body.find(e => e.number === '1')).have.property('status', 'validated');
|
||||
should(res.body.find(e => e.number === 'Rng36')).have.property('status', 'new');
|
||||
done();
|
||||
});
|
||||
});
|
||||
it('adds the specified measurements', done => {
|
||||
TestHelper.request(server, done, {
|
||||
method: 'get',
|
||||
@ -549,9 +561,9 @@ describe('/sample', () => {
|
||||
if (err) return done(err);
|
||||
const json = require('../test/db.json');
|
||||
let asyncCounter = res.body.length;
|
||||
should(res.body).have.lengthOf(json.collections.samples.filter(e => e.status ===globals.status.new).length);
|
||||
should(res.body).have.lengthOf(json.collections.samples.filter(e => e.status ==='new').length);
|
||||
should(res.body).matchEach(sample => {
|
||||
should(sample).have.only.keys('_id', 'number', 'type', 'color', 'batch', 'condition', 'material_id', 'note_id', 'user_id', 'added');
|
||||
should(sample).have.only.keys('_id', 'number', 'type', 'color', 'batch', 'condition', 'material_id', 'note_id', 'user_id', 'status', 'added');
|
||||
should(sample).have.property('_id').be.type('string');
|
||||
should(sample).have.property('number').be.type('string');
|
||||
should(sample).have.property('type').be.type('string');
|
||||
@ -565,8 +577,9 @@ describe('/sample', () => {
|
||||
should(sample).have.property('note_id');
|
||||
should(sample).have.property('user_id').be.type('string');
|
||||
should(sample).have.property('added').be.type('string');
|
||||
should(sample).have.property('status').be.type('string');
|
||||
SampleModel.findById(sample._id).lean().exec((err, data) => {
|
||||
should(data).have.property('status',globals.status.new);
|
||||
should(data).have.property('status','new');
|
||||
if (--asyncCounter === 0) {
|
||||
done();
|
||||
}
|
||||
@ -584,9 +597,9 @@ describe('/sample', () => {
|
||||
if (err) return done(err);
|
||||
const json = require('../test/db.json');
|
||||
let asyncCounter = res.body.length;
|
||||
should(res.body).have.lengthOf(json.collections.samples.filter(e => e.status === -1).length);
|
||||
should(res.body).have.lengthOf(json.collections.samples.filter(e => e.status === 'deleted').length);
|
||||
should(res.body).matchEach(sample => {
|
||||
should(sample).have.only.keys('_id', 'number', 'type', 'color', 'batch', 'condition', 'material_id', 'note_id', 'user_id', 'added');
|
||||
should(sample).have.only.keys('_id', 'number', 'type', 'color', 'batch', 'condition', 'material_id', 'note_id', 'user_id', 'status', 'added');
|
||||
should(sample).have.property('_id').be.type('string');
|
||||
should(sample).have.property('number').be.type('string');
|
||||
should(sample).have.property('type').be.type('string');
|
||||
@ -600,8 +613,9 @@ describe('/sample', () => {
|
||||
should(sample).have.property('note_id');
|
||||
should(sample).have.property('user_id').be.type('string');
|
||||
should(sample).have.property('added').be.type('string');
|
||||
should(sample).have.property('status').be.type('string');
|
||||
SampleModel.findById(sample._id).lean().exec((err, data) => {
|
||||
should(data).have.property('status',globals.status.deleted);
|
||||
should(data).have.property('status','deleted');
|
||||
if (--asyncCounter === 0) {
|
||||
done();
|
||||
}
|
||||
@ -677,7 +691,7 @@ describe('/sample', () => {
|
||||
url: '/sample/400000000000000000000003',
|
||||
auth: {basic: 'janedoe'},
|
||||
httpStatus: 200,
|
||||
res: {_id: '400000000000000000000003', number: '33', type: 'part', color: 'black', batch: '1704-005', condition: {material: 'copper', weeks: 3, condition_template: '200000000000000000000001'}, material: {_id: '100000000000000000000005', name: 'Amodel A 1133 HS', supplier: 'Solvay', group: 'PPA', properties: {material_template: '130000000000000000000003', mineral: 0, glass_fiber: 33, carbon_fiber: 0}, numbers: ['5514262406']}, notes: {comment: '', sample_references: [{sample_id: '400000000000000000000004', relation: 'granulate to sample'}], custom_fields: {'not allowed for new applications': true}}, measurements: [{_id: '800000000000000000000003', sample_id: '400000000000000000000003', values: {val1: 1}, measurement_template: '300000000000000000000003'}], user: 'admin'}
|
||||
res: {_id: '400000000000000000000003', number: '33', type: 'part', color: 'black', batch: '1704-005', condition: {material: 'copper', weeks: 3, condition_template: '200000000000000000000001'}, material: {_id: '100000000000000000000005', name: 'Amodel A 1133 HS', supplier: 'Solvay', group: 'PPA', properties: {material_template: '130000000000000000000003', mineral: 0, glass_fiber: 33, carbon_fiber: 0}, numbers: ['5514262406']}, notes: {comment: '', sample_references: [{sample_id: '400000000000000000000004', relation: 'granulate to sample'}], custom_fields: {'not allowed for new applications': true}}, measurements: [{_id: '800000000000000000000003', sample_id: '400000000000000000000003', values: {val1: 1}, measurement_template: '300000000000000000000003'}], status: 'new', user: 'admin'}
|
||||
});
|
||||
});
|
||||
it('works with an API key', done => {
|
||||
@ -686,7 +700,7 @@ describe('/sample', () => {
|
||||
url: '/sample/400000000000000000000003',
|
||||
auth: {key: 'janedoe'},
|
||||
httpStatus: 200,
|
||||
res: {_id: '400000000000000000000003', number: '33', type: 'part', color: 'black', batch: '1704-005', condition: {material: 'copper', weeks: 3, condition_template: '200000000000000000000001'}, material: {_id: '100000000000000000000005', name: 'Amodel A 1133 HS', supplier: 'Solvay', group: 'PPA', properties: {material_template: '130000000000000000000003', mineral: 0, glass_fiber: 33, carbon_fiber: 0}, numbers: ['5514262406']}, notes: {comment: '', sample_references: [{sample_id: '400000000000000000000004', relation: 'granulate to sample'}], custom_fields: {'not allowed for new applications': true}}, measurements: [{_id: '800000000000000000000003', sample_id: '400000000000000000000003', values: {val1: 1}, measurement_template: '300000000000000000000003'}], user: 'admin'}
|
||||
res: {_id: '400000000000000000000003', number: '33', type: 'part', color: 'black', batch: '1704-005', condition: {material: 'copper', weeks: 3, condition_template: '200000000000000000000001'}, material: {_id: '100000000000000000000005', name: 'Amodel A 1133 HS', supplier: 'Solvay', group: 'PPA', properties: {material_template: '130000000000000000000003', mineral: 0, glass_fiber: 33, carbon_fiber: 0}, numbers: ['5514262406']}, notes: {comment: '', sample_references: [{sample_id: '400000000000000000000004', relation: 'granulate to sample'}], custom_fields: {'not allowed for new applications': true}}, measurements: [{_id: '800000000000000000000003', sample_id: '400000000000000000000003', values: {val1: 1}, measurement_template: '300000000000000000000003'}], status: 'new', user: 'admin'}
|
||||
});
|
||||
});
|
||||
it ('filters out spectral data for a write user', done => {
|
||||
@ -695,7 +709,7 @@ describe('/sample', () => {
|
||||
url: '/sample/400000000000000000000001',
|
||||
auth: {basic: 'janedoe'},
|
||||
httpStatus: 200,
|
||||
res: {_id: '400000000000000000000001', number: '1', type: 'granulate', color: 'black', batch: '', condition: {material: 'copper', weeks: 3, condition_template: '200000000000000000000001'}, material: {numbers: ['5513933405'], _id: '100000000000000000000004', name: 'Schulamid 66 GF 25 H', properties: {material_template: '130000000000000000000003', mineral: 0, glass_fiber: 25, carbon_fiber: 0}, group: 'PA66', supplier: 'Schulmann'}, user: 'janedoe', notes: {}, measurements: [{_id: '800000000000000000000001', sample_id: '400000000000000000000001', values: {device: 'Alpha I'}, measurement_template: '300000000000000000000001'}, {_id: '800000000000000000000007', sample_id: '400000000000000000000001', values: {device: 'Alpha II'}, measurement_template: '300000000000000000000001'}]}
|
||||
res: {_id: '400000000000000000000001', number: '1', type: 'granulate', color: 'black', batch: '', condition: {material: 'copper', weeks: 3, condition_template: '200000000000000000000001'}, material: {numbers: ['5513933405'], _id: '100000000000000000000004', name: 'Schulamid 66 GF 25 H', properties: {material_template: '130000000000000000000003', mineral: 0, glass_fiber: 25, carbon_fiber: 0}, group: 'PA66', supplier: 'Schulmann'}, user: 'janedoe', notes: {}, measurements: [{_id: '800000000000000000000001', sample_id: '400000000000000000000001', values: {device: 'Alpha I'}, measurement_template: '300000000000000000000001'}, {_id: '800000000000000000000007', sample_id: '400000000000000000000001', values: {device: 'Alpha II'}, measurement_template: '300000000000000000000001'}], status: 'validated'}
|
||||
});
|
||||
});
|
||||
it ('returns spectral data for an admin user', done => {
|
||||
@ -704,7 +718,7 @@ describe('/sample', () => {
|
||||
url: '/sample/400000000000000000000001',
|
||||
auth: {basic: 'admin'},
|
||||
httpStatus: 200,
|
||||
res: {_id: '400000000000000000000001', number: '1', type: 'granulate', color: 'black', batch: '', condition: {material: 'copper', weeks: 3, condition_template: '200000000000000000000001'}, material: {numbers: ['5513933405'], _id: '100000000000000000000004', name: 'Schulamid 66 GF 25 H', properties: {material_template: '130000000000000000000003', mineral: 0, glass_fiber: 25, carbon_fiber: 0}, group: 'PA66', supplier: 'Schulmann'}, user: 'janedoe', notes: {}, measurements: [{_id: '800000000000000000000001', sample_id: '400000000000000000000001', values: {dpt: [[ 3997.12558, 98.00555 ], [ 3995.08519, 98.03253 ], [ 3993.0448, 98.02657 ]],device: 'Alpha I'}, measurement_template: '300000000000000000000001'}, {_id: '800000000000000000000007', sample_id: '400000000000000000000001', values: {dpt: [[ 3996.12558, 98.00555 ], [ 3995.08519, 98.03253 ], [ 3993.0448, 98.02657 ]], device: 'Alpha II'}, measurement_template: '300000000000000000000001'}]}
|
||||
res: {_id: '400000000000000000000001', number: '1', type: 'granulate', color: 'black', batch: '', condition: {material: 'copper', weeks: 3, condition_template: '200000000000000000000001'}, material: {numbers: ['5513933405'], _id: '100000000000000000000004', name: 'Schulamid 66 GF 25 H', properties: {material_template: '130000000000000000000003', mineral: 0, glass_fiber: 25, carbon_fiber: 0}, group: 'PA66', supplier: 'Schulmann'}, user: 'janedoe', notes: {}, measurements: [{_id: '800000000000000000000001', sample_id: '400000000000000000000001', values: {dpt: [[ 3997.12558, 98.00555 ], [ 3995.08519, 98.03253 ], [ 3993.0448, 98.02657 ]],device: 'Alpha I'}, measurement_template: '300000000000000000000001'}, {_id: '800000000000000000000007', sample_id: '400000000000000000000001', values: {dpt: [[ 3996.12558, 98.00555 ], [ 3995.08519, 98.03253 ], [ 3993.0448, 98.02657 ]], device: 'Alpha II'}, measurement_template: '300000000000000000000001'}], status: 'validated'}
|
||||
});
|
||||
});
|
||||
it('returns a deleted sample for a dev/admin user', done => {
|
||||
@ -713,7 +727,7 @@ describe('/sample', () => {
|
||||
url: '/sample/400000000000000000000005',
|
||||
auth: {basic: 'admin'},
|
||||
httpStatus: 200,
|
||||
res: {_id: '400000000000000000000005', number: 'Rng33', type: 'granulate', color: 'black', batch: '1653000308', condition: {condition_template: '200000000000000000000003'}, material: {_id: '100000000000000000000005', name: 'Amodel A 1133 HS', supplier: 'Solvay', group: 'PPA', properties: {material_template: '130000000000000000000003', mineral: 0, glass_fiber: 33, carbon_fiber: 0}, numbers: ['5514262406']}, notes: {}, measurements: [], user: 'admin'}
|
||||
res: {_id: '400000000000000000000005', number: 'Rng33', type: 'granulate', color: 'black', batch: '1653000308', condition: {condition_template: '200000000000000000000003'}, material: {_id: '100000000000000000000005', name: 'Amodel A 1133 HS', supplier: 'Solvay', group: 'PPA', properties: {material_template: '130000000000000000000003', mineral: 0, glass_fiber: 33, carbon_fiber: 0}, numbers: ['5514262406']}, notes: {}, measurements: [], status: 'deleted', user: 'admin'}
|
||||
});
|
||||
});
|
||||
it('returns 403 for a write user when requesting a deleted sample', done => {
|
||||
@ -757,7 +771,7 @@ describe('/sample', () => {
|
||||
auth: {basic: 'janedoe'},
|
||||
httpStatus: 200,
|
||||
req: {},
|
||||
res: {_id: '400000000000000000000001', number: '1', type: 'granulate', color: 'black', batch: '', condition: {material: 'copper', weeks: 3, condition_template: '200000000000000000000001'}, material_id: '100000000000000000000004', note_id: null, user_id: '000000000000000000000002', added: '2004-01-10T13:37:04.000Z'}
|
||||
res: {_id: '400000000000000000000001', number: '1', type: 'granulate', color: 'black', batch: '', condition: {material: 'copper', weeks: 3, condition_template: '200000000000000000000001'}, material_id: '100000000000000000000004', note_id: null, user_id: '000000000000000000000002', status: 'validated', added: '2004-01-10T13:37:04.000Z'}
|
||||
});
|
||||
});
|
||||
it('keeps unchanged properties', done => {
|
||||
@ -769,7 +783,7 @@ describe('/sample', () => {
|
||||
req: {type: 'granulate', color: 'black', batch: '', condition: {material: 'copper', weeks: 3, condition_template: '200000000000000000000001'}, 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: '', condition: {material: 'copper', weeks: 3, condition_template: '200000000000000000000001'}, material_id: '100000000000000000000004', note_id: null, user_id: '000000000000000000000002', added: '2004-01-10T13:37:04.000Z'});
|
||||
should(res.body).be.eql({_id: '400000000000000000000001', number: '1', type: 'granulate', color: 'black', batch: '', condition: {material: 'copper', weeks: 3, condition_template: '200000000000000000000001'}, material_id: '100000000000000000000004', note_id: null, user_id: '000000000000000000000002', status: 'validated', added: '2004-01-10T13:37:04.000Z'});
|
||||
SampleModel.findById('400000000000000000000001').lean().exec((err, data: any) => {
|
||||
if (err) return done (err);
|
||||
should(data).have.only.keys('_id', 'number', 'color', 'type', 'batch', 'condition', 'material_id', 'note_id', 'user_id', 'status', '__v');
|
||||
@ -781,7 +795,7 @@ describe('/sample', () => {
|
||||
should(data).have.property('condition', {material: 'copper', weeks: 3, condition_template: '200000000000000000000001'});
|
||||
should(data.material_id.toString()).be.eql('100000000000000000000004');
|
||||
should(data.user_id.toString()).be.eql('000000000000000000000002');
|
||||
should(data).have.property('status',globals.status.validated);
|
||||
should(data).have.property('status','validated');
|
||||
should(data).have.property('note_id', null);
|
||||
done();
|
||||
});
|
||||
@ -796,10 +810,10 @@ describe('/sample', () => {
|
||||
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: '', condition: {material: 'copper', weeks: 3, condition_template: '200000000000000000000001'}, material_id: '100000000000000000000004', note_id: null, user_id: '000000000000000000000002', added: '2004-01-10T13:37:04.000Z'});
|
||||
should(res.body).be.eql({_id: '400000000000000000000001', number: '1', type: 'granulate', color: 'black', batch: '', condition: {material: 'copper', weeks: 3, condition_template: '200000000000000000000001'}, material_id: '100000000000000000000004', note_id: null, user_id: '000000000000000000000002', status: 'validated', added: '2004-01-10T13:37:04.000Z'});
|
||||
SampleModel.findById('400000000000000000000001').lean().exec((err, data: any) => {
|
||||
if (err) return done (err);
|
||||
should(data).have.property('status',globals.status.validated);
|
||||
should(data).have.property('status','validated');
|
||||
done();
|
||||
});
|
||||
});
|
||||
@ -813,10 +827,10 @@ describe('/sample', () => {
|
||||
req: {condition: {material: 'copper', weeks: 3, condition_template: '200000000000000000000001'}}
|
||||
}).end((err, res) => {
|
||||
if (err) return done(err);
|
||||
should(res.body).be.eql({_id: '400000000000000000000001', number: '1', type: 'granulate', color: 'black', batch: '', condition: {material: 'copper', weeks: 3, condition_template: '200000000000000000000001'}, material_id: '100000000000000000000004', note_id: null, user_id: '000000000000000000000002', added: '2004-01-10T13:37:04.000Z'});
|
||||
should(res.body).be.eql({_id: '400000000000000000000001', number: '1', type: 'granulate', color: 'black', batch: '', condition: {material: 'copper', weeks: 3, condition_template: '200000000000000000000001'}, material_id: '100000000000000000000004', note_id: null, user_id: '000000000000000000000002', status: 'validated', added: '2004-01-10T13:37:04.000Z'});
|
||||
SampleModel.findById('400000000000000000000001').lean().exec((err, data: any) => {
|
||||
if (err) return done (err);
|
||||
should(data).have.property('status',globals.status.validated);
|
||||
should(data).have.property('status','validated');
|
||||
done();
|
||||
});
|
||||
});
|
||||
@ -830,7 +844,7 @@ describe('/sample', () => {
|
||||
req: {notes: {comment: 'Stoff gesperrt', sample_references: []}}
|
||||
}).end((err, res) => {
|
||||
if (err) return done(err);
|
||||
should(res.body).be.eql({_id: '400000000000000000000002', number: '21', type: 'granulate', color: 'natural', batch: '1560237365', condition: {material: 'copper', weeks: 3, condition_template: '200000000000000000000001'}, material_id: '100000000000000000000001', note_id: '500000000000000000000001', user_id: '000000000000000000000002', added: '2004-01-10T13:37:04.000Z'});
|
||||
should(res.body).be.eql({_id: '400000000000000000000002', number: '21', type: 'granulate', color: 'natural', batch: '1560237365', condition: {material: 'copper', weeks: 3, condition_template: '200000000000000000000001'}, material_id: '100000000000000000000001', note_id: '500000000000000000000001', user_id: '000000000000000000000002', status: 'validated', added: '2004-01-10T13:37:04.000Z'});
|
||||
SampleModel.findById('400000000000000000000002').lean().exec((err, data: any) => {
|
||||
if (err) return done (err);
|
||||
should(data).have.only.keys('_id', 'number', 'color', 'type', 'batch', 'condition', 'material_id', 'note_id', 'user_id', 'status', '__v');
|
||||
@ -844,7 +858,7 @@ describe('/sample', () => {
|
||||
should(data.condition.condition_template.toString()).be.eql('200000000000000000000001');
|
||||
should(data.material_id.toString()).be.eql('100000000000000000000001');
|
||||
should(data.user_id.toString()).be.eql('000000000000000000000002');
|
||||
should(data).have.property('status',globals.status.validated);
|
||||
should(data).have.property('status','validated');
|
||||
should(data.note_id.toString()).be.eql('500000000000000000000001');
|
||||
done();
|
||||
});
|
||||
@ -870,7 +884,7 @@ describe('/sample', () => {
|
||||
should(data).have.property('condition', {condition_template: '200000000000000000000003'});
|
||||
should(data.material_id.toString()).be.eql('100000000000000000000002');
|
||||
should(data.user_id.toString()).be.eql('000000000000000000000002');
|
||||
should(data).have.property('status',globals.status.new);
|
||||
should(data).have.property('status','new');
|
||||
should(data).have.property('note_id');
|
||||
NoteModel.findById(data.note_id).lean().exec((err, data: any) => {
|
||||
if (err) return done (err);
|
||||
@ -895,7 +909,7 @@ describe('/sample', () => {
|
||||
log: {
|
||||
collection: 'samples',
|
||||
dataAdd: {
|
||||
status: 0
|
||||
status: 'new'
|
||||
},
|
||||
dataIgn: ['notes', 'note_id']
|
||||
}
|
||||
@ -1097,7 +1111,7 @@ describe('/sample', () => {
|
||||
auth: {basic: 'janedoe'},
|
||||
httpStatus: 200,
|
||||
req: {condition: {}},
|
||||
res: {_id: '400000000000000000000006', number: 'Rng36', type: 'granulate', color: 'black', batch: '', condition: {}, material_id: '100000000000000000000004', note_id: null, user_id: '000000000000000000000002', added: '2004-01-10T13:37:04.000Z'}
|
||||
res: {_id: '400000000000000000000006', number: 'Rng36', type: 'granulate', color: 'black', batch: '', condition: {}, material_id: '100000000000000000000004', note_id: null, user_id: '000000000000000000000002', status: 'new', added: '2004-01-10T13:37:04.000Z'}
|
||||
});
|
||||
});
|
||||
it('rejects an old version of a condition template', done => {
|
||||
@ -1117,7 +1131,7 @@ describe('/sample', () => {
|
||||
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', added: '2004-01-10T13:37:04.000Z'}
|
||||
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', status: 'new', added: '2004-01-10T13:37:04.000Z'}
|
||||
});
|
||||
});
|
||||
it('rejects changing back to an empty condition', done => {
|
||||
@ -1164,7 +1178,7 @@ describe('/sample', () => {
|
||||
auth: {basic: 'admin'},
|
||||
httpStatus: 200,
|
||||
req: {},
|
||||
res: {_id: '400000000000000000000001', number: '1', type: 'granulate', color: 'black', batch: '', condition: {condition_template: '200000000000000000000001', material: 'copper', weeks: 3}, material_id: '100000000000000000000004', note_id: null, user_id: '000000000000000000000002', added: '2004-01-10T13:37:04.000Z'}
|
||||
res: {_id: '400000000000000000000001', number: '1', type: 'granulate', color: 'black', batch: '', condition: {condition_template: '200000000000000000000001', material: 'copper', weeks: 3}, material_id: '100000000000000000000004', note_id: null, user_id: '000000000000000000000002', status: 'validated', added: '2004-01-10T13:37:04.000Z'}
|
||||
});
|
||||
});
|
||||
it('rejects requests from a read user', done => {
|
||||
@ -1218,7 +1232,7 @@ describe('/sample', () => {
|
||||
should(data.condition.condition_template.toString()).be.eql('200000000000000000000001');
|
||||
should(data.material_id.toString()).be.eql('100000000000000000000004');
|
||||
should(data.user_id.toString()).be.eql('000000000000000000000002');
|
||||
should(data).have.property('status',globals.status.deleted);
|
||||
should(data).have.property('status','deleted');
|
||||
should(data).have.property('note_id', null);
|
||||
done();
|
||||
});
|
||||
@ -1233,7 +1247,7 @@ describe('/sample', () => {
|
||||
log: {
|
||||
collection: 'samples',
|
||||
skip: 1,
|
||||
dataAdd: {status: -1}
|
||||
dataAdd: {status: 'deleted'}
|
||||
}
|
||||
});
|
||||
});
|
||||
@ -1307,7 +1321,7 @@ describe('/sample', () => {
|
||||
should(res.body).be.eql({status: 'OK'});
|
||||
SampleModel.findById('400000000000000000000001').lean().exec((err, data) => {
|
||||
if (err) return done(err);
|
||||
should(data).have.property('status',globals.status.deleted);
|
||||
should(data).have.property('status','deleted');
|
||||
done();
|
||||
});
|
||||
});
|
||||
@ -1324,7 +1338,7 @@ describe('/sample', () => {
|
||||
MeasurementModel.find({sample_id: mongoose.Types.ObjectId('400000000000000000000001')}).lean().exec((err, data: any) => {
|
||||
if (err) return done(err);
|
||||
should(data).matchEach(sample => {
|
||||
should(sample).have.property('status', -1);
|
||||
should(sample).have.property('status', 'deleted');
|
||||
});
|
||||
done();
|
||||
});
|
||||
@ -1386,7 +1400,7 @@ describe('/sample', () => {
|
||||
url: '/sample/number/33',
|
||||
auth: {basic: 'janedoe'},
|
||||
httpStatus: 200,
|
||||
res: {_id: '400000000000000000000003', number: '33', type: 'part', color: 'black', batch: '1704-005', condition: {material: 'copper', weeks: 3, condition_template: '200000000000000000000001'}, material: {_id: '100000000000000000000005', name: 'Amodel A 1133 HS', supplier: 'Solvay', group: 'PPA', properties: {material_template: '130000000000000000000003', mineral: 0, glass_fiber: 33, carbon_fiber: 0}, numbers: ['5514262406']}, notes: {comment: '', sample_references: [{sample_id: '400000000000000000000004', relation: 'granulate to sample'}], custom_fields: {'not allowed for new applications': true}}, measurements: [{_id: '800000000000000000000003', sample_id: '400000000000000000000003', values: {val1: 1}, measurement_template: '300000000000000000000003'}], user: 'admin'}
|
||||
res: {_id: '400000000000000000000003', number: '33', type: 'part', color: 'black', batch: '1704-005', condition: {material: 'copper', weeks: 3, condition_template: '200000000000000000000001'}, material: {_id: '100000000000000000000005', name: 'Amodel A 1133 HS', supplier: 'Solvay', group: 'PPA', properties: {material_template: '130000000000000000000003', mineral: 0, glass_fiber: 33, carbon_fiber: 0}, numbers: ['5514262406']}, notes: {comment: '', sample_references: [{sample_id: '400000000000000000000004', relation: 'granulate to sample'}], custom_fields: {'not allowed for new applications': true}}, measurements: [{_id: '800000000000000000000003', sample_id: '400000000000000000000003', values: {val1: 1}, measurement_template: '300000000000000000000003'}], status: 'new', user: 'admin'}
|
||||
});
|
||||
});
|
||||
it('works with an API key', done => {
|
||||
@ -1395,7 +1409,7 @@ describe('/sample', () => {
|
||||
url: '/sample/number/33',
|
||||
auth: {key: 'janedoe'},
|
||||
httpStatus: 200,
|
||||
res: {_id: '400000000000000000000003', number: '33', type: 'part', color: 'black', batch: '1704-005', condition: {material: 'copper', weeks: 3, condition_template: '200000000000000000000001'}, material: {_id: '100000000000000000000005', name: 'Amodel A 1133 HS', supplier: 'Solvay', group: 'PPA', properties: {material_template: '130000000000000000000003', mineral: 0, glass_fiber: 33, carbon_fiber: 0}, numbers: ['5514262406']}, notes: {comment: '', sample_references: [{sample_id: '400000000000000000000004', relation: 'granulate to sample'}], custom_fields: {'not allowed for new applications': true}}, measurements: [{_id: '800000000000000000000003', sample_id: '400000000000000000000003', values: {val1: 1}, measurement_template: '300000000000000000000003'}], user: 'admin'}
|
||||
res: {_id: '400000000000000000000003', number: '33', type: 'part', color: 'black', batch: '1704-005', condition: {material: 'copper', weeks: 3, condition_template: '200000000000000000000001'}, material: {_id: '100000000000000000000005', name: 'Amodel A 1133 HS', supplier: 'Solvay', group: 'PPA', properties: {material_template: '130000000000000000000003', mineral: 0, glass_fiber: 33, carbon_fiber: 0}, numbers: ['5514262406']}, notes: {comment: '', sample_references: [{sample_id: '400000000000000000000004', relation: 'granulate to sample'}], custom_fields: {'not allowed for new applications': true}}, measurements: [{_id: '800000000000000000000003', sample_id: '400000000000000000000003', values: {val1: 1}, measurement_template: '300000000000000000000003'}], status: 'new', user: 'admin'}
|
||||
});
|
||||
});
|
||||
it('returns a deleted sample for a dev/admin user', done => {
|
||||
@ -1404,7 +1418,7 @@ describe('/sample', () => {
|
||||
url: '/sample/number/Rng33',
|
||||
auth: {basic: 'admin'},
|
||||
httpStatus: 200,
|
||||
res: {_id: '400000000000000000000005', number: 'Rng33', type: 'granulate', color: 'black', batch: '1653000308', condition: {condition_template: '200000000000000000000003'}, material: {_id: '100000000000000000000005', name: 'Amodel A 1133 HS', supplier: 'Solvay', group: 'PPA', properties: {material_template: '130000000000000000000003', mineral: 0, glass_fiber: 33, carbon_fiber: 0}, numbers: ['5514262406']}, notes: {}, measurements: [], user: 'admin'}
|
||||
res: {_id: '400000000000000000000005', number: 'Rng33', type: 'granulate', color: 'black', batch: '1653000308', condition: {condition_template: '200000000000000000000003'}, material: {_id: '100000000000000000000005', name: 'Amodel A 1133 HS', supplier: 'Solvay', group: 'PPA', properties: {material_template: '130000000000000000000003', mineral: 0, glass_fiber: 33, carbon_fiber: 0}, numbers: ['5514262406']}, notes: {}, measurements: [], status: 'deleted', user: 'admin'}
|
||||
});
|
||||
});
|
||||
it ('filters out spectral data for a write user', done => {
|
||||
@ -1413,7 +1427,7 @@ describe('/sample', () => {
|
||||
url: '/sample/number/1',
|
||||
auth: {basic: 'janedoe'},
|
||||
httpStatus: 200,
|
||||
res: {_id: '400000000000000000000001', number: '1', type: 'granulate', color: 'black', batch: '', condition: {material: 'copper', weeks: 3, condition_template: '200000000000000000000001'}, material: {numbers: ['5513933405'], _id: '100000000000000000000004', name: 'Schulamid 66 GF 25 H', properties: {material_template: '130000000000000000000003', mineral: 0, glass_fiber: 25, carbon_fiber: 0}, group: 'PA66', supplier: 'Schulmann'}, user: 'janedoe', notes: {}, measurements: [{_id: '800000000000000000000001', sample_id: '400000000000000000000001', values: {device: 'Alpha I'}, measurement_template: '300000000000000000000001'}, {_id: '800000000000000000000007', sample_id: '400000000000000000000001', values: {device: 'Alpha II'}, measurement_template: '300000000000000000000001'}]}
|
||||
res: {_id: '400000000000000000000001', number: '1', type: 'granulate', color: 'black', batch: '', condition: {material: 'copper', weeks: 3, condition_template: '200000000000000000000001'}, material: {numbers: ['5513933405'], _id: '100000000000000000000004', name: 'Schulamid 66 GF 25 H', properties: {material_template: '130000000000000000000003', mineral: 0, glass_fiber: 25, carbon_fiber: 0}, group: 'PA66', supplier: 'Schulmann'}, user: 'janedoe', notes: {}, measurements: [{_id: '800000000000000000000001', sample_id: '400000000000000000000001', values: {device: 'Alpha I'}, measurement_template: '300000000000000000000001'}, {_id: '800000000000000000000007', sample_id: '400000000000000000000001', values: {device: 'Alpha II'}, measurement_template: '300000000000000000000001'}], status: 'validated'}
|
||||
});
|
||||
});
|
||||
it ('returns spectral data for an admin user', done => {
|
||||
@ -1422,7 +1436,7 @@ describe('/sample', () => {
|
||||
url: '/sample/number/1',
|
||||
auth: {basic: 'admin'},
|
||||
httpStatus: 200,
|
||||
res: {_id: '400000000000000000000001', number: '1', type: 'granulate', color: 'black', batch: '', condition: {material: 'copper', weeks: 3, condition_template: '200000000000000000000001'}, material: {numbers: ['5513933405'], _id: '100000000000000000000004', name: 'Schulamid 66 GF 25 H', properties: {material_template: '130000000000000000000003', mineral: 0, glass_fiber: 25, carbon_fiber: 0}, group: 'PA66', supplier: 'Schulmann'}, user: 'janedoe', notes: {}, measurements: [{_id: '800000000000000000000001', sample_id: '400000000000000000000001', values: {dpt: [[ 3997.12558, 98.00555 ], [ 3995.08519, 98.03253 ], [ 3993.0448, 98.02657 ]],device: 'Alpha I'}, measurement_template: '300000000000000000000001'}, {_id: '800000000000000000000007', sample_id: '400000000000000000000001', values: {dpt: [[ 3996.12558, 98.00555 ], [ 3995.08519, 98.03253 ], [ 3993.0448, 98.02657 ]], device: 'Alpha II'}, measurement_template: '300000000000000000000001'}]}
|
||||
res: {_id: '400000000000000000000001', number: '1', type: 'granulate', color: 'black', batch: '', condition: {material: 'copper', weeks: 3, condition_template: '200000000000000000000001'}, material: {numbers: ['5513933405'], _id: '100000000000000000000004', name: 'Schulamid 66 GF 25 H', properties: {material_template: '130000000000000000000003', mineral: 0, glass_fiber: 25, carbon_fiber: 0}, group: 'PA66', supplier: 'Schulmann'}, user: 'janedoe', notes: {}, measurements: [{_id: '800000000000000000000001', sample_id: '400000000000000000000001', values: {dpt: [[ 3997.12558, 98.00555 ], [ 3995.08519, 98.03253 ], [ 3993.0448, 98.02657 ]],device: 'Alpha I'}, measurement_template: '300000000000000000000001'}, {_id: '800000000000000000000007', sample_id: '400000000000000000000001', values: {dpt: [[ 3996.12558, 98.00555 ], [ 3995.08519, 98.03253 ], [ 3993.0448, 98.02657 ]], device: 'Alpha II'}, measurement_template: '300000000000000000000001'}], status: 'validated'}
|
||||
});
|
||||
});
|
||||
it('returns 403 for a write user when requesting a deleted sample', done => {
|
||||
@ -1471,7 +1485,7 @@ describe('/sample', () => {
|
||||
should(res.body).be.eql({status: 'OK'});
|
||||
SampleModel.findById('400000000000000000000005').lean().exec((err, data: any) => {
|
||||
if (err) return done(err);
|
||||
should(data).have.property('status',globals.status.new);
|
||||
should(data).have.property('status','new');
|
||||
done();
|
||||
});
|
||||
});
|
||||
@ -1488,7 +1502,7 @@ describe('/sample', () => {
|
||||
dataAdd: {
|
||||
group_id: '900000000000000000000002',
|
||||
supplier_id: '110000000000000000000002',
|
||||
status: 0
|
||||
status: 'new'
|
||||
},
|
||||
dataIgn: ['group_id', 'supplier_id']
|
||||
}
|
||||
@ -1544,7 +1558,7 @@ describe('/sample', () => {
|
||||
should(res.body).be.eql({status: 'OK'});
|
||||
SampleModel.findById('400000000000000000000003').lean().exec((err, data: any) => {
|
||||
if (err) return done(err);
|
||||
should(data).have.property('status',globals.status.validated);
|
||||
should(data).have.property('status','validated');
|
||||
done();
|
||||
});
|
||||
});
|
||||
@ -1561,7 +1575,7 @@ describe('/sample', () => {
|
||||
dataAdd: {
|
||||
group_id: '900000000000000000000002',
|
||||
supplier_id: '110000000000000000000002',
|
||||
status: 10
|
||||
status: 'validated'
|
||||
},
|
||||
dataIgn: ['group_id', 'supplier_id']
|
||||
}
|
||||
@ -1579,7 +1593,7 @@ describe('/sample', () => {
|
||||
should(res.body).be.eql({status: 'OK'});
|
||||
SampleModel.findById('400000000000000000000006').lean().exec((err, data: any) => {
|
||||
if (err) return done(err);
|
||||
should(data).have.property('status',globals.status.validated);
|
||||
should(data).have.property('status','validated');
|
||||
done();
|
||||
});
|
||||
});
|
||||
@ -1596,7 +1610,7 @@ describe('/sample', () => {
|
||||
should(res.body).be.eql({status: 'OK'});
|
||||
SampleModel.findById('400000000000000000000004').lean().exec((err, data: any) => {
|
||||
if (err) return done(err);
|
||||
should(data).have.property('status',globals.status.validated);
|
||||
should(data).have.property('status','validated');
|
||||
done();
|
||||
});
|
||||
});
|
||||
@ -1648,7 +1662,7 @@ describe('/sample', () => {
|
||||
req: {color: 'black', type: 'granulate', batch: '1560237365', condition: {material: 'copper', weeks: 3, condition_template: '200000000000000000000001'}, 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', 'added');
|
||||
should(res.body).have.only.keys('_id', 'number', 'color', 'type', 'batch', 'condition', 'material_id', 'note_id', 'user_id', 'status', 'added');
|
||||
should(res.body).have.property('_id').be.type('string');
|
||||
should(res.body).have.property('number', 'Rng37');
|
||||
should(res.body).have.property('color', 'black');
|
||||
@ -1658,6 +1672,7 @@ describe('/sample', () => {
|
||||
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', '000000000000000000000002');
|
||||
should(res.body).have.property('status', 'new');
|
||||
should(res.body).have.property('added').be.type('string');
|
||||
should(new Date().getTime() - new Date(res.body.added).getTime()).be.below(1000);
|
||||
done();
|
||||
@ -1684,7 +1699,7 @@ describe('/sample', () => {
|
||||
should(data[0]).have.property('condition', {material: 'copper', weeks: 3, condition_template: '200000000000000000000001'});
|
||||
should(data[0].material_id.toString()).be.eql('100000000000000000000001');
|
||||
should(data[0].user_id.toString()).be.eql('000000000000000000000002');
|
||||
should(data[0]).have.property('status',globals.status.new);
|
||||
should(data[0]).have.property('status','new');
|
||||
should(data[0]).have.property('note_id');
|
||||
NoteModel.findById(data[0].note_id).lean().exec((err, data: any) => {
|
||||
if (err) return done (err);
|
||||
@ -1711,7 +1726,7 @@ describe('/sample', () => {
|
||||
dataAdd: {
|
||||
number: 'Rng37',
|
||||
user_id: '000000000000000000000002',
|
||||
status: 0
|
||||
status: 'new'
|
||||
},
|
||||
dataIgn: ['notes', 'note_id']
|
||||
}
|
||||
@ -1763,7 +1778,7 @@ describe('/sample', () => {
|
||||
req: {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', 'added');
|
||||
should(res.body).have.only.keys('_id', 'number', 'color', 'type', 'batch', 'condition', 'material_id', 'note_id', 'user_id', 'status', 'added');
|
||||
should(res.body).have.property('_id').be.type('string');
|
||||
should(res.body).have.property('number', 'Fe1');
|
||||
should(res.body).have.property('color', 'black');
|
||||
@ -1772,6 +1787,7 @@ describe('/sample', () => {
|
||||
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', '000000000000000000000004');
|
||||
should(res.body).have.property('status', 'new');
|
||||
should(res.body).have.property('added').be.type('string');
|
||||
should(new Date().getTime() - new Date(res.body.added).getTime()).be.below(1500);
|
||||
done();
|
||||
@ -1786,7 +1802,7 @@ describe('/sample', () => {
|
||||
req: {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', 'added');
|
||||
should(res.body).have.only.keys('_id', 'number', 'color', 'type', 'batch', 'condition', 'material_id', 'note_id', 'user_id', 'status', 'added');
|
||||
should(res.body).have.property('_id').be.type('string');
|
||||
should(res.body).have.property('number', 'Rng37');
|
||||
should(res.body).have.property('color', 'black');
|
||||
@ -1796,6 +1812,7 @@ describe('/sample', () => {
|
||||
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', '000000000000000000000002');
|
||||
should(res.body).have.property('status', 'new');
|
||||
should(res.body).have.property('added').be.type('string');
|
||||
should(new Date().getTime() - new Date(res.body.added).getTime()).be.below(1000);
|
||||
done();
|
||||
@ -1830,7 +1847,7 @@ describe('/sample', () => {
|
||||
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', 'added');
|
||||
should(res.body).have.only.keys('_id', 'number', 'color', 'type', 'batch', 'condition', 'material_id', 'note_id', 'user_id', 'status', 'added');
|
||||
should(res.body).have.property('_id').be.type('string');
|
||||
should(res.body).have.property('number', 'Rng34');
|
||||
should(res.body).have.property('color', 'black');
|
||||
@ -1840,6 +1857,7 @@ describe('/sample', () => {
|
||||
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');
|
||||
should(res.body).have.property('status', 'new');
|
||||
should(res.body).have.property('added').be.type('string');
|
||||
should(new Date().getTime() - new Date(res.body.added).getTime()).be.below(1000);
|
||||
done();
|
||||
|
Reference in New Issue
Block a user