Skip to content

Commit

Permalink
fix(http): fix tests to reflect new error reporting
Browse files Browse the repository at this point in the history
  • Loading branch information
marcj committed Oct 24, 2023
1 parent efb1668 commit 1eb83ff
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 10 deletions.
2 changes: 1 addition & 1 deletion packages/http/src/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ export class BodyValidationError {
}

getErrorMessageForPath(path: string): string {
return this.getErrorsForPath(path).map(v => v.message).join(', ');
return this.getErrorsForPath(path).map(v => v.toString()).join(', ');
}
}

Expand Down
14 changes: 5 additions & 9 deletions packages/http/tests/router.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -949,14 +949,14 @@ test('BodyValidation', async () => {
const httpKernel = createHttpKernel([Controller]);
expect((await httpKernel.request(HttpRequest.POST('/action1').json({ username: 'Peter' }))).json).toEqual({ username: 'Peter' });
expect((await httpKernel.request(HttpRequest.POST('/action1').json({ username: 'Pe' }))).json).toEqual({
errors: [{ code: 'minLength', message: 'Min length is 3', path: 'username', value: 'Pe' }], message: 'Validation error:\nusername(minLength): Min length is 3'
errors: [{ code: 'minLength', message: 'Min length is 3', path: 'username', value: 'Pe' }], message: 'Validation error:\nusername(minLength): Min length is 3 caused by value \"Pe\"'
});

expect((await httpKernel.request(HttpRequest.POST('/action2').json({ username: 'Peter' }))).json).toEqual({ username: 'Peter' });
expect((await httpKernel.request(HttpRequest.POST('/action2').json({ username: 'Pe' }))).bodyString).toEqual(`{"message":"Invalid: Min length is 3"}`);
expect((await httpKernel.request(HttpRequest.POST('/action2').json({ username: 'Pe' }))).json.message).toEqual('Invalid: username(minLength): Min length is 3 caused by value "Pe"');

expect((await httpKernel.request(HttpRequest.POST('/action3').json({ username: 'Peter' }))).json).toEqual({ username: 'Peter' });
expect((await httpKernel.request(HttpRequest.POST('/action3').json({ username: 'Pe' }))).bodyString).toEqual(`{"message":"Invalid: Min length is 3"}`);
expect((await httpKernel.request(HttpRequest.POST('/action3').json({ username: 'Pe' }))).json.message).toEqual('Invalid: username(minLength): Min length is 3 caused by value "Pe"');
});

test('unpopulated entity without type information', async () => {
Expand Down Expand Up @@ -1373,9 +1373,7 @@ test('upload security', async () => {
type: 'image/jpeg',
lastModifiedDate: null
}
}))).json).toMatchObject({
message: 'Validation error:\nsomeFile(uploadSecurity): Not an uploaded file'
});
}))).json.message).toContain('Not an uploaded file caused by value');

// ensure type deserialization doesn't set the invalid 'fake value' value to UploadedFileSymbol
expect((await httpKernel.request(HttpRequest.POST('/upload').json({
Expand All @@ -1387,9 +1385,7 @@ test('upload security', async () => {
type: 'image/jpeg',
lastModifiedDate: null
}
}))).json).toMatchObject({
message: 'Validation error:\nsomeFile(uploadSecurity): Not an uploaded file'
});
}))).json.message).toContain('Not an uploaded file caused by value');

expect((await httpKernel.request(HttpRequest.POST('/upload').multiPart([
{
Expand Down

0 comments on commit 1eb83ff

Please sign in to comment.