Skip to content

Commit 3e02442

Browse files
author
Hyunje Jun
committed
Add 'specific content type' and 'stream' test cases for postBinary
1 parent da3a622 commit 3e02442

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

test/http.spec.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { HTTPError, JSONParseError, RequestError } from "../lib/exceptions";
33
import { get, post, stream, del, postBinary } from "../lib/http";
44
import { getStreamData } from "./helpers/stream";
55
import { close, listen } from "./helpers/test-server";
6-
import { readFileSync } from "fs";
6+
import { readFileSync, createReadStream } from "fs";
77
import { join } from "path";
88

99
const pkg = require("../package.json");
@@ -110,6 +110,27 @@ describe("http", () => {
110110
});
111111
});
112112

113+
it("postBinary with specific content type", () => {
114+
const filepath = join(__dirname, "/helpers/line-icon.png");
115+
const buffer = readFileSync(filepath);
116+
return postBinary(
117+
`${TEST_URL}/post`,
118+
{},
119+
buffer,
120+
"image/jpeg",
121+
).then((res: any) => {
122+
equal(res.headers["content-type"], "image/jpeg");
123+
});
124+
});
125+
126+
it("postBinary with stream", () => {
127+
const filepath = join(__dirname, "/helpers/line-icon.png");
128+
const stream = createReadStream(filepath);
129+
return postBinary(`${TEST_URL}/post`, {}, stream).then((res: any) => {
130+
equal(res.headers["content-type"], "image/png");
131+
});
132+
});
133+
113134
it("fail with 404", () => {
114135
return get(`${TEST_URL}/404`, {})
115136
.then(() => ok(false))

0 commit comments

Comments
 (0)