@@ -3,7 +3,7 @@ import { HTTPError, JSONParseError, RequestError } from "../lib/exceptions";
3
3
import { get , post , stream , del , postBinary } from "../lib/http" ;
4
4
import { getStreamData } from "./helpers/stream" ;
5
5
import { close , listen } from "./helpers/test-server" ;
6
- import { readFileSync } from "fs" ;
6
+ import { readFileSync , createReadStream } from "fs" ;
7
7
import { join } from "path" ;
8
8
9
9
const pkg = require ( "../package.json" ) ;
@@ -110,6 +110,27 @@ describe("http", () => {
110
110
} ) ;
111
111
} ) ;
112
112
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
+
113
134
it ( "fail with 404" , ( ) => {
114
135
return get ( `${ TEST_URL } /404` , { } )
115
136
. then ( ( ) => ok ( false ) )
0 commit comments