Skip to content

Commit

Permalink
fix the unit test and change message to a more human friendly descrip…
Browse files Browse the repository at this point in the history
…tion of the error cdimascio#601
  • Loading branch information
pilerou authored and cdimascio committed Dec 24, 2021
1 parent 56f778b commit 2069cf9
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
18 changes: 18 additions & 0 deletions src/framework/ajv/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,15 @@ function createAjv(
obj[propName] = sch.deserialize(data);
}
catch(e) {
(<ajv.ValidateFunction>validate).errors = [
{
keyword: 'serdes',
schemaPath: data,
dataPath: path,
message: `format is invalid`,
params: { 'x-eov-serdes': propName },
},
];
return false;
}
}
Expand Down Expand Up @@ -108,6 +117,15 @@ function createAjv(
obj[propName] = sch.serialize(data);
}
catch(e) {
(<ajv.ValidateFunction>validate).errors = [
{
keyword: 'serdes',
schemaPath: data,
dataPath: path,
message: `format is invalid`,
params: { 'x-eov-serdes': propName },
},
];
return false;
}
}
Expand Down
6 changes: 3 additions & 3 deletions test/serdes.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -307,13 +307,13 @@ describe('serdes serialize response components only', () => {
.expect(500)
.then((r) => {
console.log(r);
expect(r.body.message).to.equal('d.toISOString is not a function');
expect(r.body.message).to.equal('.response.creationDate format is invalid');
}));

/*
FIXME Manage format validation after serialize ? I can serialize using a working serialize method but that respond a bad format
it('should throw error 500 on an object that serialize to a bad string format', async () =>
request(app)
.get(`${app.basePath}/users/5fdefd13a6640bb5fb5fa925`)
.query({baddateresponse : 'functionBadFormat'})
Expand All @@ -322,7 +322,7 @@ describe('serdes serialize response components only', () => {
console.log(r.body);
expect(r.body.message).to.equal('Something saying that date is not date-time format');
}));
*/

});
Expand Down

0 comments on commit 2069cf9

Please sign in to comment.