test: add provision test
This commit is contained in:
60
src/test/provision-test.js
Normal file
60
src/test/provision-test.js
Normal file
@@ -0,0 +1,60 @@
|
||||
/* global it:false */
|
||||
/* global describe:false */
|
||||
/* global before:false */
|
||||
/* global after:false */
|
||||
|
||||
'use strict';
|
||||
|
||||
const appstore = require('../appstore.js'),
|
||||
BoxError = require('../boxerror.js'),
|
||||
common = require('./common.js'),
|
||||
expect = require('expect.js'),
|
||||
nock = require('nock'),
|
||||
provision = require('../provision.js'),
|
||||
safe = require('safetydance');
|
||||
|
||||
describe('Provision', function () {
|
||||
const { domainSetup, auditSource, cleanup } = common;
|
||||
|
||||
describe('Activate', function () {
|
||||
before(domainSetup);
|
||||
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' });
|
||||
|
||||
await provision.activate('username', 'password', 'test@cloudron.io', 'Some Name', '1.2.3.4', auditSource);
|
||||
expect(scope1.isDone()).to.be.ok();
|
||||
scope1.persist(false);
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user