replace with custom superagent based on fetch API
This commit is contained in:
@@ -8,7 +8,7 @@
|
||||
const constants = require('../../constants.js'),
|
||||
common = require('./common.js'),
|
||||
expect = require('expect.js'),
|
||||
superagent = require('superagent');
|
||||
superagent = require('../../superagent.js');
|
||||
|
||||
describe('Cloudron', function () {
|
||||
const { setup, cleanup, serverUrl, owner, user, dashboardFqdn } = common;
|
||||
@@ -21,14 +21,14 @@ describe('Cloudron', function () {
|
||||
const response = await superagent.get(`${serverUrl}/api/v1/dashboard/config`)
|
||||
.ok(() => true);
|
||||
|
||||
expect(response.statusCode).to.equal(401);
|
||||
expect(response.status).to.equal(401);
|
||||
});
|
||||
|
||||
it('can get config (admin)', async function () {
|
||||
const response = await superagent.get(`${serverUrl}/api/v1/dashboard/config`)
|
||||
.query({ access_token: owner.token });
|
||||
|
||||
expect(response.statusCode).to.equal(200);
|
||||
expect(response.status).to.equal(200);
|
||||
expect(response.body.apiServerOrigin).to.eql('http://localhost:6060');
|
||||
expect(response.body.webServerOrigin).to.eql('https://cloudron.io');
|
||||
expect(response.body.adminFqdn).to.eql(dashboardFqdn);
|
||||
@@ -40,7 +40,7 @@ describe('Cloudron', function () {
|
||||
const response = await superagent.get(`${serverUrl}/api/v1/dashboard/config`)
|
||||
.query({ access_token: user.token });
|
||||
|
||||
expect(response.statusCode).to.equal(200);
|
||||
expect(response.status).to.equal(200);
|
||||
expect(response.body.apiServerOrigin).to.eql('http://localhost:6060');
|
||||
expect(response.body.webServerOrigin).to.eql('https://cloudron.io');
|
||||
expect(response.body.adminFqdn).to.eql(dashboardFqdn);
|
||||
@@ -61,13 +61,13 @@ describe('Cloudron', function () {
|
||||
const response = await superagent.post(`${serverUrl}/api/v1/users`)
|
||||
.query({ access_token: owner.token })
|
||||
.send({ email: USER.email });
|
||||
expect(response.statusCode).to.equal(201);
|
||||
expect(response.status).to.equal(201);
|
||||
USER.id = response.body.id;
|
||||
|
||||
const response2 = await superagent.get(`${serverUrl}/api/v1/users/${USER.id}/invite_link`)
|
||||
.query({ access_token: owner.token })
|
||||
.ok(() => true);
|
||||
expect(response2.statusCode).to.equal(200);
|
||||
expect(response2.status).to.equal(200);
|
||||
|
||||
const response3 = await superagent.post(`${serverUrl}/api/v1/auth/setup_account`)
|
||||
.send({
|
||||
@@ -77,20 +77,20 @@ describe('Cloudron', function () {
|
||||
displayName: USER.displayName
|
||||
})
|
||||
.ok(() => true);
|
||||
expect(response3.statusCode).to.equal(201);
|
||||
expect(response3.status).to.equal(201);
|
||||
expect(response3.body.accessToken).to.be.a('string');
|
||||
|
||||
const response4 = await superagent.get(`${serverUrl}/api/v1/users/${USER.id}`)
|
||||
.query({ access_token: owner.token })
|
||||
.ok(() => true);
|
||||
|
||||
expect(response4.statusCode).to.equal(200);
|
||||
expect(response4.status).to.equal(200);
|
||||
expect(response4.body.username).to.equal(USER.username);
|
||||
expect(response4.body.displayName).to.equal(USER.displayName);
|
||||
|
||||
const response5 = await superagent.post(`${serverUrl}/api/v1/auth/login`)
|
||||
.send({ username: USER.username, password: USER.password });
|
||||
expect(response5.statusCode).to.equal(200);
|
||||
expect(response5.status).to.equal(200);
|
||||
});
|
||||
|
||||
it('succeeds and overwrites with pre-set username and display name', async function () {
|
||||
@@ -104,13 +104,13 @@ describe('Cloudron', function () {
|
||||
const response = await superagent.post(`${serverUrl}/api/v1/users`)
|
||||
.query({ access_token: owner.token })
|
||||
.send({ email: USER.email, username: 'presetup2', displayName: 'pre setup' });
|
||||
expect(response.statusCode).to.equal(201);
|
||||
expect(response.status).to.equal(201);
|
||||
USER.id = response.body.id;
|
||||
|
||||
const response2 = await superagent.get(`${serverUrl}/api/v1/users/${USER.id}/invite_link`)
|
||||
.query({ access_token: owner.token })
|
||||
.ok(() => true);
|
||||
expect(response2.statusCode).to.equal(200);
|
||||
expect(response2.status).to.equal(200);
|
||||
|
||||
const response3 = await superagent.post(`${serverUrl}/api/v1/auth/setup_account`)
|
||||
.send({
|
||||
@@ -120,7 +120,7 @@ describe('Cloudron', function () {
|
||||
displayName: USER.displayName
|
||||
})
|
||||
.ok(() => true);
|
||||
expect(response3.statusCode).to.equal(409);
|
||||
expect(response3.status).to.equal(409);
|
||||
|
||||
const response4 = await superagent.post(`${serverUrl}/api/v1/auth/setup_account`)
|
||||
.send({
|
||||
@@ -129,20 +129,20 @@ describe('Cloudron', function () {
|
||||
displayName: USER.displayName
|
||||
})
|
||||
.ok(() => true);
|
||||
expect(response4.statusCode).to.equal(201);
|
||||
expect(response4.status).to.equal(201);
|
||||
expect(response4.body.accessToken).to.be.a('string');
|
||||
|
||||
const response5 = await superagent.get(`${serverUrl}/api/v1/users/${USER.id}`)
|
||||
.query({ access_token: owner.token })
|
||||
.ok(() => true);
|
||||
|
||||
expect(response5.statusCode).to.equal(200);
|
||||
expect(response5.status).to.equal(200);
|
||||
expect(response5.body.username).to.equal(USER.username);
|
||||
expect(response5.body.displayName).to.equal(USER.displayName);
|
||||
|
||||
const response6 = await superagent.post(`${serverUrl}/api/v1/auth/login`)
|
||||
.send({ username: USER.username, password: USER.password });
|
||||
expect(response6.statusCode).to.equal(200);
|
||||
expect(response6.status).to.equal(200);
|
||||
});
|
||||
|
||||
it('succeeds and does not overwrite pre-set username and display name if profiles are locked', async function () {
|
||||
@@ -156,18 +156,18 @@ describe('Cloudron', function () {
|
||||
const response0 = await superagent.post(`${serverUrl}/api/v1/user_directory/profile_config`)
|
||||
.query({ access_token: owner.token })
|
||||
.send({ lockUserProfiles: true, mandatory2FA: false });
|
||||
expect(response0.statusCode).to.equal(200);
|
||||
expect(response0.status).to.equal(200);
|
||||
|
||||
const response = await superagent.post(`${serverUrl}/api/v1/users`)
|
||||
.query({ access_token: owner.token })
|
||||
.send({ email: USER.email, username: 'presetup3', displayName: 'pre setup3' });
|
||||
expect(response.statusCode).to.equal(201);
|
||||
expect(response.status).to.equal(201);
|
||||
USER.id = response.body.id;
|
||||
|
||||
const response2 = await superagent.get(`${serverUrl}/api/v1/users/${USER.id}/invite_link`)
|
||||
.query({ access_token: owner.token })
|
||||
.ok(() => true);
|
||||
expect(response2.statusCode).to.equal(200);
|
||||
expect(response2.status).to.equal(200);
|
||||
|
||||
const response3 = await superagent.post(`${serverUrl}/api/v1/auth/setup_account`)
|
||||
.send({
|
||||
@@ -177,20 +177,20 @@ describe('Cloudron', function () {
|
||||
displayName: USER.displayName // ignored
|
||||
})
|
||||
.ok(() => true);
|
||||
expect(response3.statusCode).to.equal(201);
|
||||
expect(response3.status).to.equal(201);
|
||||
expect(response3.body.accessToken).to.be.a('string');
|
||||
|
||||
const response4 = await superagent.get(`${serverUrl}/api/v1/users/${USER.id}`)
|
||||
.query({ access_token: owner.token })
|
||||
.ok(() => true);
|
||||
|
||||
expect(response4.statusCode).to.equal(200);
|
||||
expect(response4.status).to.equal(200);
|
||||
expect(response4.body.username).to.equal('presetup3'); // what the admin provided
|
||||
expect(response4.body.displayName).to.equal('pre setup3'); // what the admin provided
|
||||
|
||||
const response5 = await superagent.post(`${serverUrl}/api/v1/auth/login`)
|
||||
.send({ username: 'presetup3', password: USER.password });
|
||||
expect(response5.statusCode).to.equal(200);
|
||||
expect(response5.status).to.equal(200);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -198,7 +198,7 @@ describe('Cloudron', function () {
|
||||
it('cannot login without body', async function () {
|
||||
const response = await superagent.post(`${serverUrl}/api/v1/auth/login`)
|
||||
.ok(() => true);
|
||||
expect(response.statusCode).to.equal(400);
|
||||
expect(response.status).to.equal(400);
|
||||
});
|
||||
|
||||
it('cannot login without username', async function () {
|
||||
@@ -206,7 +206,7 @@ describe('Cloudron', function () {
|
||||
.send({ password: owner.password })
|
||||
.ok(() => true);
|
||||
|
||||
expect(response.statusCode).to.equal(400);
|
||||
expect(response.status).to.equal(400);
|
||||
});
|
||||
|
||||
it('cannot login without password', async function () {
|
||||
@@ -214,7 +214,7 @@ describe('Cloudron', function () {
|
||||
.send({ username: owner.username })
|
||||
.ok(() => true);
|
||||
|
||||
expect(response.statusCode).to.equal(400);
|
||||
expect(response.status).to.equal(400);
|
||||
});
|
||||
|
||||
it('cannot login with empty username', async function () {
|
||||
@@ -222,7 +222,7 @@ describe('Cloudron', function () {
|
||||
.send({ username: '', password: owner.password })
|
||||
.ok(() => true);
|
||||
|
||||
expect(response.statusCode).to.equal(400);
|
||||
expect(response.status).to.equal(400);
|
||||
});
|
||||
|
||||
it('cannot login with empty password', async function () {
|
||||
@@ -230,7 +230,7 @@ describe('Cloudron', function () {
|
||||
.send({ username: owner.username, password: '' })
|
||||
.ok(() => true);
|
||||
|
||||
expect(response.statusCode).to.equal(400);
|
||||
expect(response.status).to.equal(400);
|
||||
});
|
||||
|
||||
it('cannot login with unknown username', async function () {
|
||||
@@ -238,7 +238,7 @@ describe('Cloudron', function () {
|
||||
.send({ username: 'somethingrandom', password: owner.password })
|
||||
.ok(() => true);
|
||||
|
||||
expect(response.statusCode).to.equal(401);
|
||||
expect(response.status).to.equal(401);
|
||||
});
|
||||
|
||||
it('cannot login with unknown email', async function () {
|
||||
@@ -246,7 +246,7 @@ describe('Cloudron', function () {
|
||||
.send({ username: 'randomgemail', password: owner.password })
|
||||
.ok(() => true);
|
||||
|
||||
expect(response.statusCode).to.equal(401);
|
||||
expect(response.status).to.equal(401);
|
||||
});
|
||||
|
||||
it('cannot login with wrong password', async function () {
|
||||
@@ -254,14 +254,14 @@ describe('Cloudron', function () {
|
||||
.send({ username: owner.username, password: owner.password.toUpperCase() })
|
||||
.ok(() => true);
|
||||
|
||||
expect(response.statusCode).to.equal(401);
|
||||
expect(response.status).to.equal(401);
|
||||
});
|
||||
|
||||
it('can login with username', async function () {
|
||||
const response = await superagent.post(`${serverUrl}/api/v1/auth/login`)
|
||||
.send({ username: owner.username, password: owner.password });
|
||||
|
||||
expect(response.statusCode).to.equal(200);
|
||||
expect(response.status).to.equal(200);
|
||||
expect(new Date(response.body.expires).toString()).to.not.be('Invalid Date');
|
||||
expect(response.body.accessToken).to.be.a('string');
|
||||
});
|
||||
@@ -270,7 +270,7 @@ describe('Cloudron', function () {
|
||||
const response = await superagent.post(`${serverUrl}/api/v1/auth/login`)
|
||||
.send({ username: owner.username.toUpperCase(), password: owner.password });
|
||||
|
||||
expect(response.statusCode).to.equal(200);
|
||||
expect(response.status).to.equal(200);
|
||||
expect(new Date(response.body.expires).toString()).to.not.be('Invalid Date');
|
||||
expect(response.body.accessToken).to.be.a('string');
|
||||
});
|
||||
@@ -279,7 +279,7 @@ describe('Cloudron', function () {
|
||||
const response = await superagent.post(`${serverUrl}/api/v1/auth/login`)
|
||||
.send({ username: owner.email, password: owner.password });
|
||||
|
||||
expect(response.statusCode).to.equal(200);
|
||||
expect(response.status).to.equal(200);
|
||||
expect(new Date(response.body.expires).toString()).to.not.be('Invalid Date');
|
||||
expect(response.body.accessToken).to.be.a('string');
|
||||
});
|
||||
@@ -288,7 +288,7 @@ describe('Cloudron', function () {
|
||||
const response = await superagent.post(`${serverUrl}/api/v1/auth/login`)
|
||||
.send({ username: owner.email.toUpperCase(), password: owner.password });
|
||||
|
||||
expect(response.statusCode).to.equal(200);
|
||||
expect(response.status).to.equal(200);
|
||||
expect(new Date(response.body.expires).toString()).to.not.be('Invalid Date');
|
||||
expect(response.body.accessToken).to.be.a('string');
|
||||
});
|
||||
@@ -298,7 +298,7 @@ describe('Cloudron', function () {
|
||||
it('succeeds', async function () {
|
||||
const response = await superagent.get(`${serverUrl}/api/v1/cloudron/languages`);
|
||||
|
||||
expect(response.statusCode).to.equal(200);
|
||||
expect(response.status).to.equal(200);
|
||||
expect(response.body.languages).to.be.an('array');
|
||||
expect(response.body.languages.indexOf('en')).to.not.equal(-1);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user