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 = {
|
2022-09-28 14:23:45 +02:00
|
|
|
upstreamUri: 'https://www.digitalocean.com/',
|
2022-07-06 19:15:59 +02:00
|
|
|
label: 'Digitalocean YaY',
|
|
|
|
|
accessRestriction: { users: [], groups: [] },
|
|
|
|
|
tags: [ 'vps', 'vservers' ],
|
|
|
|
|
icon: 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABAQMAAAAl21bKAAAAA1BMVEX/TQBcNTh/AAAAAXRSTlPM0jRW/QAAAApJREFUeJxjYgAAAAYAAzY3fKgAAAAASUVORK5CYII='
|
|
|
|
|
};
|
|
|
|
|
|
2022-09-28 14:23:45 +02:00
|
|
|
const APPLINK_2 = {
|
|
|
|
|
upstreamUri: 'https://google.com'
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const APPLINK_3 = {
|
|
|
|
|
upstreamUri: 'http://example.com'
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
it('can add applink with redirect', async function () {
|
2022-09-19 20:59:48 +02:00
|
|
|
APPLINK_0.id = await applinks.add(JSON.parse(JSON.stringify(APPLINK_0)));
|
2022-09-28 14:23:45 +02:00
|
|
|
|
|
|
|
|
// redirect should have put www in
|
|
|
|
|
APPLINK_0.upstreamUri = 'https://www.cloudron.io/';
|
2022-07-06 19:15:59 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('can add second applink with attributes', async function () {
|
2022-09-19 20:59:48 +02:00
|
|
|
APPLINK_1.id = await applinks.add(JSON.parse(JSON.stringify(APPLINK_1)));
|
2022-07-06 19:15:59 +02:00
|
|
|
});
|
|
|
|
|
|
2022-09-28 14:23:45 +02:00
|
|
|
it('can add third applink to test google.com favicon', async function () {
|
|
|
|
|
APPLINK_2.id = await applinks.add(JSON.parse(JSON.stringify(APPLINK_2)));
|
|
|
|
|
|
|
|
|
|
const result = await applinks.get(APPLINK_2.id);
|
|
|
|
|
expect(result.upstreamUri).to.eql('https://www.google.com/');
|
|
|
|
|
expect(result.icon.length).to.not.eql(0);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('can add fourth applink to test no favicon', async function () {
|
|
|
|
|
APPLINK_3.id = await applinks.add(JSON.parse(JSON.stringify(APPLINK_3)));
|
|
|
|
|
|
|
|
|
|
const result = await applinks.get(APPLINK_3.id);
|
|
|
|
|
expect(result.upstreamUri).to.eql('http://example.com');
|
|
|
|
|
expect(result.icon).to.eql(null);
|
|
|
|
|
});
|
|
|
|
|
|
2022-07-06 19:15:59 +02:00
|
|
|
it('can list all without accessRestriction', async function () {
|
|
|
|
|
const result = await applinks.list();
|
|
|
|
|
|
2022-09-28 14:23:45 +02:00
|
|
|
expect(result.length).to.equal(4);
|
|
|
|
|
expect(result[1].id).to.eql(APPLINK_0.id);
|
|
|
|
|
expect(result[1].upstreamUri).to.eql(APPLINK_0.upstreamUri);
|
|
|
|
|
expect(result[2].id).to.eql(APPLINK_1.id);
|
|
|
|
|
expect(result[2].upstreamUri).to.eql(APPLINK_1.upstreamUri);
|
|
|
|
|
expect(result[2].label).to.eql(APPLINK_1.label);
|
|
|
|
|
expect(result[2].accessRestriction).to.eql(APPLINK_1.accessRestriction);
|
|
|
|
|
expect(result[2].tags).to.eql(APPLINK_1.tags);
|
|
|
|
|
expect(result[2].icon.toString('base64')).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-09-19 20:59:48 +02:00
|
|
|
expect(result.icon.toString('base64')).to.eql(APPLINK_1.icon);
|
2022-07-06 19:15:59 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('can update applink', async function () {
|
2022-09-19 20:59:48 +02:00
|
|
|
APPLINK_0.upstreamUri = 'https://duckduckgo.com';
|
|
|
|
|
APPLINK_0.icon = APPLINK_1.icon;
|
|
|
|
|
|
|
|
|
|
await applinks.update(APPLINK_0.id, JSON.parse(JSON.stringify(APPLINK_0)));
|
|
|
|
|
|
|
|
|
|
const result = await applinks.get(APPLINK_0.id);
|
|
|
|
|
expect(result.upstreamUri).to.equal('https://duckduckgo.com');
|
|
|
|
|
expect(result.icon.toString('base64')).to.eql(APPLINK_1.icon);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('can get applink icon', async function () {
|
|
|
|
|
const result = await applinks.getIcon(APPLINK_0.id);
|
|
|
|
|
expect(result.toString('base64')).to.eql(APPLINK_1.icon);
|
2022-07-06 19:15:59 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
});
|
|
|
|
|
});
|