Skip to content

Commit

Permalink
Add http error message test for HTTP source.
Browse files Browse the repository at this point in the history
  • Loading branch information
jansivans committed Oct 23, 2024
1 parent c2c2dad commit 94e8496
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions tests/http-source.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ app.get('/json', function (req: any, res: any) {
app.get('/delimited', function (req: any, res: any) {
res.send('{"text": "hello"};{"text": "world"}');
});
app.get('/error', function (req: any, res: any) {
res.status(500).send({ success: false });
});
app.get('/delimited-qualifier', function (req: any, res: any) {
res.send('"Bob, the ""HaCk3r""",Riga\nAlice,"""Wonderland"", Apt. 22"\n');
});
Expand Down Expand Up @@ -479,3 +482,26 @@ it('handles windows-1257 encoded data from HTTP', async () => {
{ header: [], arr: ['ĀāČč'], obj: undefined, row: 'ĀāČč' },
]);
});

it.only('HTTP error response should be present in error message', async () => {
const destination = new CustomDestination({
batchSize: 1,
});
const processor = new HttpProcessor({
dataFormat: 'json',
connection: {
method: `GET`,
url: `${url}/error`,
},
jsonPath: /(\d+)/,
});
const job = new Job(processor, [destination]);
let error;
job.onAny(async (x, a) => {
if (x === 'processingError') {
error = a.message;
}
});
await job.run();
expect(error).toEqual('Request failed with status code 500. Response: {"success":false}');
});

0 comments on commit 94e8496

Please sign in to comment.