You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by gl...@apache.org on 2020/02/27 16:10:04 UTC
[couchdb-nano] 10/12: added tests for gzip/user-agent headers +
TypeScript defs
This is an automated email from the ASF dual-hosted git repository.
glynnbird pushed a commit to branch axios
in repository https://gitbox.apache.org/repos/asf/couchdb-nano.git
commit 8344ea642088f0fb1166a9aa1260efc453581d86
Author: Glynn Bird <gl...@gmail.com>
AuthorDate: Fri Feb 14 08:15:26 2020 +0000
added tests for gzip/user-agent headers + TypeScript defs
---
lib/nano.d.ts | 2 ++
test/nano.request.test.js | 36 ++++++++++++++++++++++++++++++++++++
2 files changed, 38 insertions(+)
diff --git a/lib/nano.d.ts b/lib/nano.d.ts
index 2e56b59..3ecac47 100644
--- a/lib/nano.d.ts
+++ b/lib/nano.d.ts
@@ -18,6 +18,8 @@ declare function nano(
declare namespace nano {
interface requestDefaultsOptions {
timeout: number;
+ agent: any;
+ headers: object;
};
interface Configuration {
diff --git a/test/nano.request.test.js b/test/nano.request.test.js
index 3b16df0..8b04158 100644
--- a/test/nano.request.test.js
+++ b/test/nano.request.test.js
@@ -474,3 +474,39 @@ test('check request doesn\'t mangle bodies containing functions - nano.request',
expect(p).toStrictEqual(response)
expect(scope.isDone()).toBe(true)
})
+
+test('check request sends user-agent header - nano.request', async () => {
+ // mocks
+ const response = { ok: true }
+ const scope = nock(COUCH_URL, { reqheaders: { 'user-agent': /^nano/ } })
+ .get('/db?a=1&b=2')
+ .reply(200, response)
+
+ // test GET /db?a=1&b=2
+ const req = {
+ method: 'get',
+ db: 'db',
+ qs: { a: 1, b: 2 }
+ }
+ const p = await nano.request(req)
+ expect(p).toStrictEqual(response)
+ expect(scope.isDone()).toBe(true)
+})
+
+test('check request sends headers for gzipped responses - nano.request', async () => {
+ // mocks
+ const response = { ok: true }
+ const scope = nock(COUCH_URL, { reqheaders: { 'accept-encoding': /gzip/ } })
+ .get('/db?a=1&b=2')
+ .reply(200, response)
+
+ // test GET /db?a=1&b=2
+ const req = {
+ method: 'get',
+ db: 'db',
+ qs: { a: 1, b: 2 }
+ }
+ const p = await nano.request(req)
+ expect(p).toStrictEqual(response)
+ expect(scope.isDone()).toBe(true)
+})