replace with custom superagent based on fetch API

This commit is contained in:
Girish Ramakrishnan
2025-02-14 17:26:54 +01:00
parent 68a08b1f62
commit 8e58349bfa
66 changed files with 1086 additions and 1031 deletions
+26 -26
View File
@@ -8,7 +8,7 @@
const common = require('./common.js');
const expect = require('expect.js'),
superagent = require('superagent'),
superagent = require('../../superagent.js'),
timers = require('timers/promises');
const DOMAIN = 'example-server-test.com';
@@ -39,7 +39,7 @@ describe('Provision', function () {
.send({ domainConfig: { domain: DOMAIN, config: {} } })
.ok(() => true);
expect(response.statusCode).to.eql(400);
expect(response.status).to.eql(400);
});
it('fails with invalid provider', async function () {
@@ -47,7 +47,7 @@ describe('Provision', function () {
.send({ domainConfig: { provider: 'foobar', domain: DOMAIN, config: {} } })
.ok(() => true);
expect(response.statusCode).to.eql(400);
expect(response.status).to.eql(400);
});
it('fails with missing domain', async function () {
@@ -55,7 +55,7 @@ describe('Provision', function () {
.send({ domainConfig: { provider: 'noop', config: {} } })
.ok(() => true);
expect(response.statusCode).to.eql(400);
expect(response.status).to.eql(400);
});
it('fails with invalid domain', async function () {
@@ -63,7 +63,7 @@ describe('Provision', function () {
.send({ domainConfig: { provider: 'noop', domain: '.foo', config: {} } })
.ok(() => true);
expect(response.statusCode).to.eql(400);
expect(response.status).to.eql(400);
});
it('fails with invalid config', async function () {
@@ -71,7 +71,7 @@ describe('Provision', function () {
.send({ domainConfig: { provider: 'noop', domain: DOMAIN, config: 'not an object' } })
.ok(() => true);
expect(response.statusCode).to.eql(400);
expect(response.status).to.eql(400);
});
it('fails with invalid zoneName', async function () {
@@ -79,7 +79,7 @@ describe('Provision', function () {
.send({ domainConfig: { provider: 'noop', domain: DOMAIN, config: {}, zoneName: 1337 } })
.ok(() => true);
expect(response.statusCode).to.eql(400);
expect(response.status).to.eql(400);
});
it('fails with invalid tlsConfig', async function () {
@@ -87,7 +87,7 @@ describe('Provision', function () {
.send({ domainConfig: { provider: 'noop', domain: DOMAIN, config: {}, tlsConfig: 'foobar' } })
.ok(() => true);
expect(response.statusCode).to.eql(400);
expect(response.status).to.eql(400);
});
it('fails with invalid tlsConfig provider', async function () {
@@ -95,7 +95,7 @@ describe('Provision', function () {
.send({ domainConfig: { provider: 'noop', domain: DOMAIN, config: {}, tlsConfig: { provider: 1337 } } })
.ok(() => true);
expect(response.statusCode).to.eql(400);
expect(response.status).to.eql(400);
});
it('succeeds', async function () {
@@ -103,7 +103,7 @@ describe('Provision', function () {
.send({ domainConfig: { provider: 'noop', domain: DOMAIN, adminFqdn: 'my.' + DOMAIN, config: {}, tlsConfig: { provider: 'fallback' } } })
.ok(() => true);
expect(response.statusCode).to.eql(200);
expect(response.status).to.eql(200);
await waitForSetup();
});
@@ -113,7 +113,7 @@ describe('Provision', function () {
.send({ domainConfig: { provider: 'noop', domain: DOMAIN, adminFqdn: 'my.' + DOMAIN, config: {}, tlsConfig: { provider: 'fallback' } } })
.ok(() => true);
expect(response.statusCode).to.eql(200);
expect(response.status).to.eql(200);
await waitForSetup();
});
@@ -122,7 +122,7 @@ describe('Provision', function () {
describe('Activation', function () {
it('device is in first time mode', async function () {
const response = await superagent.get(`${serverUrl}/api/v1/provision/status`);
expect(response.statusCode).to.equal(200);
expect(response.status).to.equal(200);
expect(response.body.activated).to.not.be.ok();
expect(response.body.version).to.be.ok();
expect(response.body.adminFqdn).to.be.ok(); // dashboard is setup at this point
@@ -133,7 +133,7 @@ describe('Provision', function () {
.send({ password: owner.password, email: owner.email })
.ok(() => true);
expect(response.statusCode).to.eql(400);
expect(response.status).to.eql(400);
});
it('fails with invalid username', async function () {
@@ -141,7 +141,7 @@ describe('Provision', function () {
.send({ username: '?this.is-not!valid', password: owner.password, email: owner.email })
.ok(() => true);
expect(response.statusCode).to.eql(400);
expect(response.status).to.eql(400);
});
it('fails due to empty username', async function () {
@@ -149,7 +149,7 @@ describe('Provision', function () {
.send({ username: '', password: owner.password, email: owner.email })
.ok(() => true);
expect(response.statusCode).to.eql(400);
expect(response.status).to.eql(400);
});
it('fails without email', async function () {
@@ -157,7 +157,7 @@ describe('Provision', function () {
.send({ username: owner.username, password: owner.password })
.ok(() => true);
expect(response.statusCode).to.eql(400);
expect(response.status).to.eql(400);
});
it('fails due to empty email', async function () {
@@ -165,7 +165,7 @@ describe('Provision', function () {
.send({ username: owner.username, password: owner.password, email: '' })
.ok(() => true);
expect(response.statusCode).to.eql(400);
expect(response.status).to.eql(400);
});
it('fails due to invalid email', async function () {
@@ -173,7 +173,7 @@ describe('Provision', function () {
.send({ username: owner.username, password: owner.password, email: 'invalidemail' })
.ok(() => true);
expect(response.statusCode).to.eql(400);
expect(response.status).to.eql(400);
});
it('fails without password', async function () {
@@ -181,7 +181,7 @@ describe('Provision', function () {
.send({ username: owner.password.username, email: owner.email })
.ok(() => true);
expect(response.statusCode).to.eql(400);
expect(response.status).to.eql(400);
});
it('fails due to empty password', async function () {
@@ -189,7 +189,7 @@ describe('Provision', function () {
.send({ username: owner.username, password: '', email: owner.email })
.ok(() => true);
expect(response.statusCode).to.eql(400);
expect(response.status).to.eql(400);
});
it('fails with invalid password', async function () {
@@ -197,7 +197,7 @@ describe('Provision', function () {
.send({ username: owner.username, password: 'short', email: owner.email })
.ok(() => true);
expect(response.statusCode).to.eql(400);
expect(response.status).to.eql(400);
});
it('fails due to wrong displayName type', async function () {
@@ -205,14 +205,14 @@ describe('Provision', function () {
.send({ username: owner.username, password: owner.password, email: owner.email, displayName: 1234 })
.ok(() => true);
expect(response.statusCode).to.eql(400);
expect(response.status).to.eql(400);
});
it('succeeds', async function () {
const response = await superagent.post(`${serverUrl}/api/v1/provision/activate`)
.send({ username: owner.username, password: owner.password, email: owner.email, displayName: owner.displayName });
expect(response.statusCode).to.equal(201);
expect(response.status).to.equal(201);
expect(response.body.token).to.be.a('string');
});
@@ -221,7 +221,7 @@ describe('Provision', function () {
.send({ username: owner.username, password: owner.password, email: owner.email, displayName: owner.displayName })
.ok(() => true);
expect(response.statusCode).to.eql(405); // route unavailable post activation
expect(response.status).to.eql(405); // route unavailable post activation
});
it('seutp fails after activation', async function () {
@@ -229,12 +229,12 @@ describe('Provision', function () {
.send({ domainConfig: { provider: 'noop', domain: DOMAIN, adminFqdn: 'my.' + DOMAIN, config: {}, tlsConfig: { provider: 'fallback' } } })
.ok(() => true);
expect(response.statusCode).to.eql(405);
expect(response.status).to.eql(405);
});
it('device left first time mode', async function () {
const response = await superagent.get(`${serverUrl}/api/v1/provision/status`);
expect(response.statusCode).to.equal(200);
expect(response.status).to.equal(200);
expect(response.body.activated).to.be.ok();
});
});