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

84 lines
2.5 KiB
JavaScript
Raw Normal View History

2024-12-10 10:06:52 +01:00
/* global it:false */
/* global describe:false */
/* global before:false */
/* global after:false */
'use strict';
const archives = require('../archives.js'),
2025-07-24 18:09:33 +02:00
backupListing = require('../backuplisting.js'),
2024-12-10 10:06:52 +01:00
BoxError = require('../boxerror.js'),
common = require('./common.js'),
expect = require('expect.js'),
safe = require('safetydance');
describe('Archives', function () {
const { setup, cleanup, auditSource } = common;
const appBackup = {
id: null,
remotePath: 'backup-box',
encryptionVersion: 2,
packageVersion: '1.0.0',
2025-07-24 18:09:33 +02:00
type: backupListing.BACKUP_TYPE_APP,
state: backupListing.BACKUP_STATE_NORMAL,
2024-12-10 10:06:52 +01:00
identifier: 'box',
dependsOn: [ 'dep1' ],
manifest: null,
preserveSecs: 0,
label: '',
2024-12-10 20:52:29 +01:00
appConfig: { loc: 'loc1' }
2024-12-10 10:06:52 +01:00
};
before(async function () {
await setup();
2025-07-24 18:09:33 +02:00
appBackup.id = await backupListing.add(appBackup);
2024-12-10 10:06:52 +01:00
});
after(cleanup);
let archiveId;
it('cannot add bad backup to archives', async function () {
2024-12-10 20:52:29 +01:00
const [error] = await safe(archives.add('badId', {}, auditSource));
2024-12-10 10:06:52 +01:00
expect(error.reason).to.be(BoxError.NOT_FOUND);
});
it('can add good backup to archives', async function () {
2024-12-10 20:52:29 +01:00
archiveId = await archives.add(appBackup.id, {}, auditSource);
2024-12-10 10:06:52 +01:00
});
it('cannot get invalid archive', async function () {
const result = await archives.get('bad');
expect(result).to.be(null);
});
it('can get archive', async function () {
const result = await archives.get(archiveId);
2024-12-10 20:52:29 +01:00
expect(result.appConfig).to.eql(appBackup.appConfig);
2024-12-10 10:06:52 +01:00
});
it('can list archives', async function () {
const result = await archives.list(1, 100);
expect(result.length).to.be(1);
expect(result[0].id).to.be(archiveId);
2024-12-10 20:52:29 +01:00
expect(result[0].appConfig).to.eql(appBackup.appConfig);
2024-12-10 10:06:52 +01:00
});
it('can list backupIds', async function () {
const result = await archives.listBackupIds();
expect(result.length).to.be(1);
expect(result[0]).to.be(appBackup.id);
});
it('cannot delete bad archive', async function () {
2024-12-10 11:01:10 +01:00
const [error] = await safe(archives.del({ id: 'badId' }, auditSource));
2024-12-10 10:06:52 +01:00
expect(error.reason).to.be(BoxError.NOT_FOUND);
});
it('can del valid archive', async function () {
2024-12-10 11:01:10 +01:00
await archives.del({ id: archiveId }, auditSource);
2024-12-10 10:06:52 +01:00
const result = await archives.list(1, 10);
expect(result.length).to.be(0);
});
});