add some superagent tests

This commit is contained in:
Girish Ramakrishnan
2025-02-15 15:54:39 +01:00
parent 8e58349bfa
commit 4cfa658fde
2 changed files with 26 additions and 2 deletions

View File

@@ -31,7 +31,6 @@ class Request {
this.okFunc = (response) => response.ok;
this.timer = { timeout: 0, id: null, controller: null };
this.retryCount = 0;
this.fetchOptions.headers.set('Content-Type', 'application/json');
}
async _makeRequest() {
@@ -101,7 +100,7 @@ class Request {
send(data) {
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.body = JSON.stringify(data);
} else if (contentType === 'application/x-www-form-urlencoded') {

View File

@@ -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();
});
});