applinks: add tests

This commit is contained in:
Girish Ramakrishnan
2024-12-04 15:28:21 +01:00
parent 3b9d617e37
commit 2bfa49cc2e
7 changed files with 268 additions and 135 deletions

View File

@@ -17,8 +17,13 @@ describe('Applinks', function () {
before(setup);
after(cleanup);
function deepCopy(x) {
return JSON.parse(JSON.stringify(x));
}
const APPLINK_0 = {
upstreamUri: 'https://cloudron.io'
upstreamUri: 'https://cloudron.io',
accessRestriction: null
};
const APPLINK_1 = {
@@ -30,23 +35,25 @@ describe('Applinks', function () {
};
const APPLINK_2 = {
upstreamUri: 'https://google.com'
upstreamUri: 'https://google.com',
accessRestriction: null
};
const APPLINK_3 = {
upstreamUri: 'http://example.com'
upstreamUri: 'http://example.com',
accessRestriction: null
};
it('can add applink with redirect', async function () {
APPLINK_0.id = await applinks.add(JSON.parse(JSON.stringify(APPLINK_0)));
APPLINK_0.id = await applinks.add(deepCopy(APPLINK_0));
});
it('can add second applink with attributes', async function () {
APPLINK_1.id = await applinks.add(JSON.parse(JSON.stringify(APPLINK_1)));
APPLINK_1.id = await applinks.add(deepCopy(APPLINK_1));
});
it('can add third applink to test google.com favicon', async function () {
APPLINK_2.id = await applinks.add(JSON.parse(JSON.stringify(APPLINK_2)));
APPLINK_2.id = await applinks.add(deepCopy(APPLINK_2));
const result = await applinks.get(APPLINK_2.id);
expect(result.upstreamUri).to.eql(APPLINK_2.upstreamUri); // should not have changed
@@ -54,7 +61,7 @@ describe('Applinks', function () {
});
it('can add fourth applink to test no favicon', async function () {
APPLINK_3.id = await applinks.add(JSON.parse(JSON.stringify(APPLINK_3)));
APPLINK_3.id = await applinks.add(deepCopy(APPLINK_3));
const result = await applinks.get(APPLINK_3.id);
expect(result.upstreamUri).to.eql('http://example.com');
@@ -97,10 +104,7 @@ describe('Applinks', function () {
});
it('can update applink', async function () {
APPLINK_0.upstreamUri = 'https://duckduckgo.com';
APPLINK_0.icon = APPLINK_1.icon;
await applinks.update(APPLINK_0.id, JSON.parse(JSON.stringify(APPLINK_0)));
await applinks.update(APPLINK_0, { upstreamUri: 'https://duckduckgo.com', icon: APPLINK_1.icon });
const result = await applinks.get(APPLINK_0.id);
expect(result.upstreamUri).to.equal('https://duckduckgo.com');
@@ -108,18 +112,18 @@ describe('Applinks', function () {
});
it('can get applink icon', async function () {
const result = await applinks.getIcon(APPLINK_0.id);
expect(result.toString('base64')).to.eql(APPLINK_1.icon);
const result = await applinks.get(APPLINK_0.id);
expect(result.icon.toString('base64')).to.eql(APPLINK_1.icon);
});
it('cannot del applink with wrong id', async function () {
const [error] = await safe(applinks.del('doesnotexist'));
const [error] = await safe(applinks.del({ id: 'doesnotexist' }));
expect(error).to.be.a(BoxError);
expect(error.reason).to.eql(BoxError.NOT_FOUND);
});
it('can del applink', async function () {
await applinks.del(APPLINK_0.id);
await applinks.del(APPLINK_0);
const result = await applinks.get(APPLINK_0.id);
expect(result).to.be(null);