add some superagent tests
This commit is contained in:
+1
-2
@@ -31,7 +31,6 @@ class Request {
|
|||||||
this.okFunc = (response) => response.ok;
|
this.okFunc = (response) => response.ok;
|
||||||
this.timer = { timeout: 0, id: null, controller: null };
|
this.timer = { timeout: 0, id: null, controller: null };
|
||||||
this.retryCount = 0;
|
this.retryCount = 0;
|
||||||
this.fetchOptions.headers.set('Content-Type', 'application/json');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async _makeRequest() {
|
async _makeRequest() {
|
||||||
@@ -101,7 +100,7 @@ class Request {
|
|||||||
|
|
||||||
send(data) {
|
send(data) {
|
||||||
const contentType = this.fetchOptions.headers.get('Content-Type');
|
const contentType = this.fetchOptions.headers.get('Content-Type');
|
||||||
if (contentType === 'application/json') {
|
if (!contentType || contentType === 'application/json') {
|
||||||
this.fetchOptions.headers.set('Content-Type', 'application/json');
|
this.fetchOptions.headers.set('Content-Type', 'application/json');
|
||||||
this.fetchOptions.body = JSON.stringify(data);
|
this.fetchOptions.body = JSON.stringify(data);
|
||||||
} else if (contentType === 'application/x-www-form-urlencoded') {
|
} else if (contentType === 'application/x-www-form-urlencoded') {
|
||||||
|
|||||||
@@ -0,0 +1,25 @@
|
|||||||
|
/* global it:false */
|
||||||
|
/* global describe:false */
|
||||||
|
/* global before:false */
|
||||||
|
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
const expect = require('expect.js'),
|
||||||
|
safe = require('safetydance'),
|
||||||
|
superagent = require('../superagent.js');
|
||||||
|
|
||||||
|
describe('Superagent', function () {
|
||||||
|
it('can get URL', async function () {
|
||||||
|
await superagent.get('https://www.cloudron.io').set('User-Agent', 'Mozilla').timeout(10*1000);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('follows redirect', async function () {
|
||||||
|
const response = await superagent.get('https://cloudron.io').set('User-Agent', 'Mozilla').timeout(10*1000);
|
||||||
|
expect(response.url).to.be('https://www.cloudron.io/');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('can disable redirects', async function () {
|
||||||
|
const [error] = await safe(superagent.get('https://cloudron.io').set('User-Agent', 'Mozilla').timeout(10*1000).redirects(0));
|
||||||
|
expect(error).to.be.ok();
|
||||||
|
});
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user