Skip to content

Commit c0983c6

Browse files
committed
fix the unit test and change message to a more human friendly description of the error cdimascio#601
1 parent ce5194b commit c0983c6

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

src/framework/ajv/index.ts

+18
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,15 @@ function createAjv(
5959
obj[propName] = sch.deserialize(data);
6060
}
6161
catch(e) {
62+
(<ajv.ValidateFunction>validate).errors = [
63+
{
64+
keyword: 'serdes',
65+
schemaPath: data,
66+
dataPath: path,
67+
message: `format is invalid`,
68+
params: { 'x-eov-serdes': propName },
69+
},
70+
];
6271
return false;
6372
}
6473
}
@@ -108,6 +117,15 @@ function createAjv(
108117
obj[propName] = sch.serialize(data);
109118
}
110119
catch(e) {
120+
(<ajv.ValidateFunction>validate).errors = [
121+
{
122+
keyword: 'serdes',
123+
schemaPath: data,
124+
dataPath: path,
125+
message: `format is invalid`,
126+
params: { 'x-eov-serdes': propName },
127+
},
128+
];
111129
return false;
112130
}
113131
}

test/serdes.spec.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -307,13 +307,13 @@ describe('serdes serialize response components only', () => {
307307
.expect(500)
308308
.then((r) => {
309309
console.log(r);
310-
expect(r.body.message).to.equal('d.toISOString is not a function');
310+
expect(r.body.message).to.equal('.response.creationDate format is invalid');
311311
}));
312312

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

328328
});

0 commit comments

Comments
 (0)