Files
cloudron-box/src/test/provision-test.js
T

70 lines
3.0 KiB
JavaScript
Raw Normal View History

2025-06-06 11:25:57 +02:00
/* global it:false */
import * as appstore from '../appstore.js';
import BoxError from '../boxerror.js';
import * as common from './common.js';
import expect from 'expect.js';
import nock from 'nock';
import * as provision from '../provision.js';
import safe from 'safetydance';
2025-06-06 11:25:57 +02:00
/* global describe:false */
/* global before:false */
/* global after:false */
describe('Provision', function () {
const { domainSetup, auditSource, cleanup } = common;
describe('Activate', function () {
2025-06-06 15:48:21 +02:00
before(async function () {
await domainSetup();
if (!nock.isActive()) nock.activate();
});
2025-06-06 11:25:57 +02:00
after(cleanup);
it('cannot activate when appstore unreachable', async function () {
const [error] = await safe(provision.activate('username', 'password', 'test@cloudron.io', 'Some Name', '1.2.3.4', auditSource));
expect(error.reason).to.be(BoxError.NETWORK_ERROR);
});
it('cannot activate with non-201', async function () {
const scope1 = nock(await appstore.getApiServerOrigin())
.post('/api/v1/register_cloudron3', (body) => typeof body.domain === 'string' && typeof body.version === 'string')
.reply(401, {});
const [error] = await safe(provision.activate('username', 'password', 'test@cloudron.io', 'Some Name', '1.2.3.4', auditSource));
expect(error.reason).to.be(BoxError.EXTERNAL_ERROR);
expect(scope1.isDone()).to.be.ok();
scope1.persist(false);
});
it('cannot activate with incorrect fields', async function () {
const scope1 = nock(await appstore.getApiServerOrigin())
.post('/api/v1/register_cloudron3', (body) => typeof body.domain === 'string' && typeof body.version === 'string')
.reply(201, { id: '32' });
const [error] = await safe(provision.activate('username', 'password', 'test@cloudron.io', 'Some Name', '1.2.3.4', auditSource));
expect(error.reason).to.be(BoxError.EXTERNAL_ERROR);
expect(scope1.isDone()).to.be.ok();
scope1.persist(false);
});
it('can activate with correct fields', async function () {
const scope1 = nock(await appstore.getApiServerOrigin())
.post('/api/v1/register_cloudron3', (body) => typeof body.domain === 'string' && typeof body.version === 'string')
.reply(201, { cloudronId: '32', cloudronToken: 'xx' });
2025-10-07 09:34:35 +02:00
const scope2 = nock(await appstore.getApiServerOrigin())
.post('/api/v1/subscription3?accessToken=xx', (body) => typeof body.state === 'object' && typeof body.state.userCount === 'number')
.reply(200, { features: {} });
2025-06-06 11:25:57 +02:00
await provision.activate('username', 'password', 'test@cloudron.io', 'Some Name', '1.2.3.4', auditSource);
expect(scope1.isDone()).to.be.ok();
scope1.persist(false);
2025-10-07 09:34:35 +02:00
expect(scope2.isDone()).to.be.ok();
scope2.persist(false);
2025-06-06 11:25:57 +02:00
});
});
});