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
+27 -27
View File
@@ -8,7 +8,7 @@
const backups = require('../../backups.js'),
common = require('./common.js'),
expect = require('expect.js'),
superagent = require('superagent');
superagent = require('../../superagent.js');
const BACKUP_FOLDER = '/tmp/backup_test';
@@ -33,7 +33,7 @@ describe('Backups API', function () {
.send(tmp)
.ok(() => true);
expect(response.statusCode).to.equal(400);
expect(response.status).to.equal(400);
});
it('cannot set backup_policy with invalid schedule', async function () {
@@ -45,7 +45,7 @@ describe('Backups API', function () {
.send(tmp)
.ok(() => true);
expect(response.statusCode).to.equal(400);
expect(response.status).to.equal(400);
});
it('cannot set backup_policy without retention', async function () {
@@ -57,7 +57,7 @@ describe('Backups API', function () {
.send(tmp)
.ok(() => true);
expect(response.statusCode).to.equal(400);
expect(response.status).to.equal(400);
});
it('cannot set backup_policy with invalid retention', async function () {
@@ -69,7 +69,7 @@ describe('Backups API', function () {
.send(tmp)
.ok(() => true);
expect(response.statusCode).to.equal(400);
expect(response.status).to.equal(400);
});
it('cannot set backup_policy with empty retention', async function () {
@@ -81,7 +81,7 @@ describe('Backups API', function () {
.send(tmp)
.ok(() => true);
expect(response.statusCode).to.equal(400);
expect(response.status).to.equal(400);
});
it('cannot set backup_policy with retention missing properties', async function () {
@@ -93,7 +93,7 @@ describe('Backups API', function () {
.send(tmp)
.ok(() => true);
expect(response.statusCode).to.equal(400);
expect(response.status).to.equal(400);
});
it('cannot set backup_policy with retention with invalid keepWithinSecs', async function () {
@@ -105,7 +105,7 @@ describe('Backups API', function () {
.send(tmp)
.ok(() => true);
expect(response.statusCode).to.equal(400);
expect(response.status).to.equal(400);
});
});
@@ -122,7 +122,7 @@ describe('Backups API', function () {
const response = await superagent.get(`${serverUrl}/api/v1/backups/config`)
.query({ access_token: owner.token });
expect(response.statusCode).to.equal(200);
expect(response.status).to.equal(200);
expect(response.body).to.eql(defaultConfig);
});
@@ -135,7 +135,7 @@ describe('Backups API', function () {
.send(tmp)
.ok(() => true);
expect(response.statusCode).to.equal(400);
expect(response.status).to.equal(400);
});
it('cannot set backup_config with invalid provider', async function () {
@@ -147,7 +147,7 @@ describe('Backups API', function () {
.send(tmp)
.ok(() => true);
expect(response.statusCode).to.equal(400);
expect(response.status).to.equal(400);
});
it('cannot set backup_config without format', async function () {
@@ -159,7 +159,7 @@ describe('Backups API', function () {
.send(tmp)
.ok(() => true);
expect(response.statusCode).to.equal(400);
expect(response.status).to.equal(400);
});
it('cannot set backup_config with invalid format', async function () {
@@ -171,7 +171,7 @@ describe('Backups API', function () {
.send(tmp)
.ok(() => true);
expect(response.statusCode).to.equal(400);
expect(response.status).to.equal(400);
});
it('cannot set backup_config with invalid password', async function () {
@@ -183,7 +183,7 @@ describe('Backups API', function () {
.send(tmp)
.ok(() => true);
expect(response.statusCode).to.equal(400);
expect(response.status).to.equal(400);
});
it('cannot set backup_config with invalid syncConcurrency', async function () {
@@ -195,7 +195,7 @@ describe('Backups API', function () {
.send(tmp)
.ok(() => true);
expect(response.statusCode).to.equal(400);
expect(response.status).to.equal(400);
});
it('cannot set backup_config with invalid syncConcurrency', async function () {
@@ -207,7 +207,7 @@ describe('Backups API', function () {
.send(tmp)
.ok(() => true);
expect(response.statusCode).to.equal(400);
expect(response.status).to.equal(400);
});
it('cannot set backup_config with invalid acceptSelfSignedCerts', async function () {
@@ -219,7 +219,7 @@ describe('Backups API', function () {
.send(tmp)
.ok(() => true);
expect(response.statusCode).to.equal(400);
expect(response.status).to.equal(400);
});
it('can set backup_config', async function () {
@@ -232,14 +232,14 @@ describe('Backups API', function () {
.query({ access_token: owner.token })
.send(tmp);
expect(response.statusCode).to.equal(200);
expect(response.status).to.equal(200);
});
it('can get backup_config', async function () {
const response = await superagent.get(`${serverUrl}/api/v1/backups/config`)
.query({ access_token: owner.token });
expect(response.statusCode).to.equal(200);
expect(response.status).to.equal(200);
expect(response.body.format).to.equal('rsync');
expect(response.body.backupFolder).to.equal(BACKUP_FOLDER);
});
@@ -258,20 +258,20 @@ describe('Backups API', function () {
it('fails due to mising token', async function () {
const response = await superagent.post(`${serverUrl}/api/v1/backups/create`)
.ok(() => true);
expect(response.statusCode).to.equal(401);
expect(response.status).to.equal(401);
});
it('fails due to wrong token', async function () {
const response = await superagent.post(`${serverUrl}/api/v1/backups/create`)
.query({ access_token: 'randomtoken' })
.ok(() => true);
expect(response.statusCode).to.equal(401);
expect(response.status).to.equal(401);
});
it('succeeds', async function () {
const response = await superagent.post(`${serverUrl}/api/v1/backups/create`)
.query({ access_token: owner.token });
expect(response.statusCode).to.equal(202);
expect(response.status).to.equal(202);
expect(response.body.taskId).to.be.a('string');
await waitForTask(response.body.taskId);
});
@@ -281,7 +281,7 @@ describe('Backups API', function () {
it('succeeds', async function () {
const response = await superagent.get(`${serverUrl}/api/v1/backups`)
.query({ access_token: owner.token });
expect(response.statusCode).to.equal(200);
expect(response.status).to.equal(200);
expect(response.body.backups.length).to.be(1);
});
});
@@ -292,7 +292,7 @@ describe('Backups API', function () {
before(async function () {
const response = await superagent.get(`${serverUrl}/api/v1/backups`)
.query({ access_token: owner.token });
expect(response.statusCode).to.equal(200);
expect(response.status).to.equal(200);
expect(response.body.backups.length).to.be(1);
someBackup = response.body.backups[0];
});
@@ -302,7 +302,7 @@ describe('Backups API', function () {
.query({ access_token: owner.token })
.send({ preserveSecs: 'not-a-number', label: 'some string' })
.ok(() => true);
expect(response.statusCode).to.equal(400);
expect(response.status).to.equal(400);
});
it('fails for unknown backup', async function () {
@@ -311,14 +311,14 @@ describe('Backups API', function () {
.send({ preserveSecs: 30, label: 'NewOrleans' })
.ok(() => true);
expect(response.statusCode).to.equal(404);
expect(response.status).to.equal(404);
});
it('succeeds', async function () {
const response = await superagent.post(`${serverUrl}/api/v1/backups/${someBackup.id}`)
.query({ access_token: owner.token })
.send({ preserveSecs: 30, label: 'NewOrleans' });
expect(response.statusCode).to.equal(200);
expect(response.status).to.equal(200);
});
});
});