return test.then(res => res.text)
}
+function unwrapBodyOrDecodeToJSON <T> (test: request.Test): Promise<T> {
+ return test.then(res => {
+ if (res.body instanceof Buffer) {
+ return JSON.parse(new TextDecoder().decode(res.body))
+ }
+
+ return res.body
+ })
+}
+
+function unwrapTextOrDecode (test: request.Test): Promise<string> {
+ return test.then(res => res.text || new TextDecoder().decode(res.body))
+}
+
// ---------------------------------------------------------------------------
export {
makeRawRequest,
makeActivityPubGetRequest,
unwrapBody,
+ unwrapTextOrDecode,
+ unwrapBodyOrDecodeToJSON,
unwrapText
}
if (fields[key] === undefined) continue
if (Array.isArray(fields[key]) && fields[key].length === 0) {
- req.field(key, null)
+ req.field(key, [])
continue
}