@bonniernews/b0rker
Advanced tools
Comparing version 4.4.3 to 4.5.0
@@ -39,2 +39,6 @@ import GoogleAuth from "google-auth-library"; | ||
} | ||
if (params.responseType) { | ||
opts.responseType = params.responseType; | ||
} | ||
let response; | ||
@@ -147,2 +151,3 @@ try { | ||
if (!body) return; | ||
if (body.readable) return "streamed"; | ||
const s = JSON.stringify(body); | ||
@@ -149,0 +154,0 @@ return s.substring(0, 4000); |
{ | ||
"name": "@bonniernews/b0rker", | ||
"version": "4.4.3", | ||
"version": "4.5.0", | ||
"engines": { | ||
@@ -5,0 +5,0 @@ "node": ">=16 <=18" |
import nock from "nock"; | ||
import { fakeGcpAuth } from "@bonniernews/lu-test"; | ||
import config from "exp-config"; | ||
import { Readable } from "stream"; | ||
@@ -56,2 +57,14 @@ import http from "../../lib/http.js"; | ||
it("should do stream get-requests", async () => { | ||
const content = "some content\nsome other content\n"; | ||
fakeApi.get("/some/path").reply(200, Readable.from([ content ])); | ||
const result = await http.asserted.get({ path: "/some/path", responseType: "stream", correlationId }); | ||
result.should.be.instanceOf(Readable); | ||
const chunks = []; | ||
for await (const chunk of result) { | ||
chunks.push(Buffer.from(chunk)); | ||
} | ||
Buffer.concat(chunks).toString("utf-8").should.eql(content); | ||
}); | ||
it("should fail on 500", (done) => { | ||
@@ -140,2 +153,27 @@ fakeApi.get("/some/path").reply(500, { ok: false }); | ||
it("should do stream get-requests", async () => { | ||
const content = "some content\nsome other content\n"; | ||
fakeApi.get("/some/path").reply(200, Readable.from([ content ])); | ||
const result = await http.get({ path: "/some/path", responseType: "stream", correlationId }); | ||
result.statusCode.should.eql(200); | ||
result.body.should.be.instanceOf(Readable); | ||
const chunks = []; | ||
for await (const chunk of result.body) { | ||
chunks.push(Buffer.from(chunk)); | ||
} | ||
Buffer.concat(chunks).toString("utf-8").should.eql(content); | ||
}); | ||
it("should do stream post-requests", async () => { | ||
const content = "some content\nsome other content\n"; | ||
fakeApi.post("/some/path").reply(200, { ok: true }); | ||
const result = await http.post({ | ||
path: "/some/path", | ||
body: Readable.from([ content ]), | ||
correlationId, | ||
}); | ||
result.statusCode.should.eql(200); | ||
result.body.should.eql({ ok: true }); | ||
}); | ||
it("should not fail on 500", async () => { | ||
@@ -142,0 +180,0 @@ fakeApi.get("/some/path").reply(500, { ok: false }); |
119804
3202