Files
cloudron-box/src/test/applinks-test.js

94 lines
3.2 KiB
JavaScript
Raw Normal View History

2022-07-06 19:15:59 +02:00
/* global it:false */
/* global describe:false */
/* global before:false */
/* global after:false */
'use strict';
const applinks = require('../applinks.js'),
BoxError = require('../boxerror.js'),
common = require('./common.js'),
expect = require('expect.js'),
safe = require('safetydance');
describe('Applinks', function () {
const { setup, cleanup } = common;
before(setup);
after(cleanup);
const APPLINK_0 = {
upstreamUri: 'https://cloudron.io'
};
const APPLINK_1 = {
upstreamUri: 'https://digitalocean.com',
label: 'Digitalocean YaY',
accessRestriction: { users: [], groups: [] },
tags: [ 'vps', 'vservers' ],
icon: 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABAQMAAAAl21bKAAAAA1BMVEX/TQBcNTh/AAAAAXRSTlPM0jRW/QAAAApJREFUeJxjYgAAAAYAAzY3fKgAAAAASUVORK5CYII='
};
it('can add applink', async function () {
APPLINK_0.id = await applinks.add(APPLINK_0);
});
it('can add second applink with attributes', async function () {
APPLINK_1.id = await applinks.add(APPLINK_1);
});
it('can list all without accessRestriction', async function () {
const result = await applinks.list();
expect(result.length).to.equal(2);
expect(result[0].id).to.eql(APPLINK_0.id);
expect(result[0].upstreamUri).to.eql(APPLINK_0.upstreamUri);
expect(result[1].id).to.eql(APPLINK_1.id);
expect(result[1].upstreamUri).to.eql(APPLINK_1.upstreamUri);
expect(result[1].label).to.eql(APPLINK_1.label);
expect(result[1].accessRestriction).to.eql(APPLINK_1.accessRestriction);
expect(result[1].tags).to.eql(APPLINK_1.tags);
2022-08-03 14:57:58 +02:00
expect(result[1].icon.toString()).to.eql(APPLINK_1.icon);
2022-07-06 19:15:59 +02:00
});
it('cannot get applink with wrong id', async function () {
const [error] = await safe(applinks.get('doesnotexist'));
expect(error).to.be.a(BoxError);
expect(error.reason).to.eql(BoxError.NOT_FOUND);
});
it('can get applink', async function () {
const result = await applinks.get(APPLINK_0.id);
expect(result.upstreamUri).to.eql(APPLINK_0.upstreamUri);
});
it('can get second applink', async function () {
const result = await applinks.get(APPLINK_1.id);
expect(result.id).to.eql(APPLINK_1.id);
expect(result.upstreamUri).to.eql(APPLINK_1.upstreamUri);
expect(result.label).to.eql(APPLINK_1.label);
expect(result.accessRestriction).to.eql(APPLINK_1.accessRestriction);
expect(result.tags).to.eql(APPLINK_1.tags);
2022-08-03 14:57:58 +02:00
expect(result.icon.toString()).to.eql(APPLINK_1.icon);
2022-07-06 19:15:59 +02:00
});
it('can update applink', async function () {
// TODO
});
it('cannot remove applink with wrong id', async function () {
const [error] = await safe(applinks.remove('doesnotexist'));
expect(error).to.be.a(BoxError);
expect(error.reason).to.eql(BoxError.NOT_FOUND);
});
it('can remove applink', async function () {
await applinks.remove(APPLINK_0.id);
const [error] = await safe(applinks.get(APPLINK_0.id));
expect(error).to.be.a(BoxError);
expect(error.reason).to.eql(BoxError.NOT_FOUND);
});
});