Archived
2

added required parameter range

This commit is contained in:
VLE2FE
2020-08-24 15:24:31 +02:00
parent 2c250e0111
commit 6702fb78c4
8 changed files with 122 additions and 447 deletions

View File

@ -1148,6 +1148,28 @@ describe('/sample', () => {
res: {status: 'Invalid body format', details: '"weeks" must be less than or equal to 10'}
});
});
it('rejects a missing condition parameter marked as required', done => {
TestHelper.request(server, done, {
method: 'put',
url: '/sample/400000000000000000000001',
auth: {basic: 'janedoe'},
httpStatus: 400,
req: {condition: {material: 'copper', condition_template: '200000000000000000000001'}},
res: {status: 'Invalid body format', details: '"weeks" is required'}
});
});
it('accepts a missing condition parameter not marked as required', done => {
TestHelper.request(server, done, {
method: 'put',
url: '/sample/400000000000000000000001',
auth: {basic: 'janedoe'},
httpStatus: 200,
req: {condition: {weeks: 10, condition_template: '200000000000000000000001'}}
}).end(err => {
if (err) return done(err);
done();
});
});
it('rejects an invalid condition template', done => {
TestHelper.request(server, done, {
method: 'put',
@ -1985,8 +2007,8 @@ describe('/sample', () => {
url: '/sample/new',
auth: {basic: 'janedoe'},
httpStatus: 400,
req: {color: 'black', type: 'as-delivered/raw', batch: '1560237365', condition: {material: 'copper', weeks: 3, xxx: 23, condition_template: '20000000000000000000001'}, material_id: '100000000000000000000001', notes: {comment: 'Testcomment', sample_references: [{sample_id: '400000000000000000000003', relation: 'part to this sample'}]}},
res: {status: 'Condition template not available'}
req: {color: 'black', type: 'as-delivered/raw', batch: '1560237365', condition: {material: 'copper', weeks: 3, xxx: 23, condition_template: '200000000000000000000001'}, material_id: '100000000000000000000001', notes: {comment: 'Testcomment', sample_references: [{sample_id: '400000000000000000000003', relation: 'part to this sample'}]}},
res: {status: 'Invalid body format', details: '"xxx" is not allowed'}
});
});
it('rejects missing condition parameters', done => {
@ -1995,8 +2017,8 @@ describe('/sample', () => {
url: '/sample/new',
auth: {basic: 'janedoe'},
httpStatus: 400,
req: {color: 'black', type: 'as-delivered/raw', batch: '1560237365', condition: {material: 'copper', condition_template: '20000000000000000000001'}, material_id: '100000000000000000000001', notes: {comment: 'Testcomment', sample_references: [{sample_id: '400000000000000000000003', relation: 'part to this sample'}]}},
res: {status: 'Condition template not available'}
req: {color: 'black', type: 'as-delivered/raw', batch: '1560237365', condition: {material: 'copper', condition_template: '200000000000000000000001'}, material_id: '100000000000000000000001', notes: {comment: 'Testcomment', sample_references: [{sample_id: '400000000000000000000003', relation: 'part to this sample'}]}},
res: { status: 'Invalid body format', details: '"weeks" is required'}
});
});
it('rejects condition parameters not in the value range', done => {
@ -2005,8 +2027,8 @@ describe('/sample', () => {
url: '/sample/new',
auth: {basic: 'janedoe'},
httpStatus: 400,
req: {color: 'black', type: 'as-delivered/raw', batch: '1560237365', condition: {material: 'xxx', weeks: 3, condition_template: '20000000000000000000001'}, material_id: '100000000000000000000001', notes: {comment: 'Testcomment', sample_references: [{sample_id: '400000000000000000000003', relation: 'part to this sample'}]}},
res: {status: 'Condition template not available'}
req: {color: 'black', type: 'as-delivered/raw', batch: '1560237365', condition: {material: 'xxx', weeks: 3, condition_template: '200000000000000000000001'}, material_id: '100000000000000000000001', notes: {comment: 'Testcomment', sample_references: [{sample_id: '400000000000000000000003', relation: 'part to this sample'}]}},
res: {status: 'Invalid body format', details: '"material" must be one of [copper, hot air]'}
});
});
it('rejects a condition parameter below minimum range', done => {
@ -2015,8 +2037,8 @@ describe('/sample', () => {
url: '/sample/new',
auth: {basic: 'janedoe'},
httpStatus: 400,
req: {color: 'black', type: 'as-delivered/raw', batch: '1560237365', condition: {material: 'copper', weeks: 0, condition_template: '20000000000000000000001'}, material_id: '100000000000000000000001', notes: {comment: 'Testcomment', sample_references: [{sample_id: '400000000000000000000003', relation: 'part to this sample'}]}},
res: {status: 'Condition template not available'}
req: {color: 'black', type: 'as-delivered/raw', batch: '1560237365', condition: {material: 'copper', weeks: 0, condition_template: '200000000000000000000001'}, material_id: '100000000000000000000001', notes: {comment: 'Testcomment', sample_references: [{sample_id: '400000000000000000000003', relation: 'part to this sample'}]}},
res: {status: 'Invalid body format', details: '"weeks" must be greater than or equal to 1'}
});
});
it('rejects a condition parameter above maximum range', done => {
@ -2025,8 +2047,30 @@ describe('/sample', () => {
url: '/sample/new',
auth: {basic: 'janedoe'},
httpStatus: 400,
req: {color: 'black', type: 'as-delivered/raw', batch: '1560237365', condition: {material: 'copper', weeks: 11, condition_template: '20000000000000000000001'}, material_id: '100000000000000000000001', notes: {comment: 'Testcomment', sample_references: [{sample_id: '400000000000000000000003', relation: 'part to this sample'}]}},
res: {status: 'Condition template not available'}
req: {color: 'black', type: 'as-delivered/raw', batch: '1560237365', condition: {material: 'copper', weeks: 11, condition_template: '200000000000000000000001'}, material_id: '100000000000000000000001', notes: {comment: 'Testcomment', sample_references: [{sample_id: '400000000000000000000003', relation: 'part to this sample'}]}},
res: {status: 'Invalid body format', details: '"weeks" must be less than or equal to 10'}
});
});
it('rejects a missing condition parameter marked as required', done => {
TestHelper.request(server, done, {
method: 'post',
url: '/sample/new',
auth: {basic: 'janedoe'},
httpStatus: 400,
req: {color: 'black', type: 'as-delivered/raw', batch: '1560237365', condition: {material: 'copper', condition_template: '200000000000000000000001'}, material_id: '100000000000000000000001', notes: {comment: 'Testcomment', sample_references: [{sample_id: '400000000000000000000003', relation: 'part to this sample'}]}},
res: {status: 'Invalid body format', details: '"weeks" is required'}
});
});
it('accepts a missing condition parameter not marked as required', done => {
TestHelper.request(server, done, {
method: 'post',
url: '/sample/new',
auth: {basic: 'janedoe'},
httpStatus: 200,
req: {color: 'black', type: 'as-delivered/raw', batch: '1560237365', condition: { weeks: 10, condition_template: '200000000000000000000001'}, material_id: '100000000000000000000001', notes: {comment: 'Testcomment', sample_references: [{sample_id: '400000000000000000000003', relation: 'part to this sample'}]}},
}).end(err => {
if (err) return done(err);
done();
});
});
it('rejects a condition without condition template', done => {