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

127 lines
4.1 KiB
JavaScript
Raw Normal View History

2017-04-24 12:34:57 +02:00
/* jslint node:true */
/* global it:false */
/* global describe:false */
/* global before:false */
/* global after:false */
'use strict';
2025-07-24 18:09:33 +02:00
const backupListing = require('../backuplisting.js'),
2025-07-24 18:46:21 +02:00
backupTargets = require('../backuptargets.js'),
2019-10-22 11:03:56 -07:00
BoxError = require('../boxerror.js'),
2021-06-03 12:20:44 -07:00
common = require('./common.js'),
2017-04-24 12:34:57 +02:00
expect = require('expect.js'),
2021-07-14 19:03:12 -07:00
safe = require('safetydance');
2019-01-10 16:00:49 -08:00
describe('backups', function () {
2025-07-24 19:02:02 +02:00
const { setup, cleanup } = common;
2021-07-14 19:03:12 -07:00
const boxBackup = {
2022-04-04 14:13:27 -07:00
id: null,
remotePath: 'backup-box',
2021-07-14 19:03:12 -07:00
encryptionVersion: 2,
packageVersion: '1.0.0',
2025-07-24 18:09:33 +02:00
type: backupListing.BACKUP_TYPE_BOX,
state: backupListing.BACKUP_STATE_NORMAL,
2021-07-14 19:03:12 -07:00
identifier: 'box',
dependsOn: [ 'dep1' ],
manifest: null,
preserveSecs: 0,
2024-12-09 16:20:24 +01:00
label: '',
appConfig: null,
targetId: null
2021-07-14 19:03:12 -07:00
};
const appBackup = {
2022-04-04 14:13:27 -07:00
id: null,
remotePath: 'app_appid_123',
2021-07-14 19:03:12 -07:00
encryptionVersion: null,
packageVersion: '1.0.0',
2025-07-24 18:09:33 +02:00
type: backupListing.BACKUP_TYPE_APP,
state: backupListing.BACKUP_STATE_CREATING,
2021-07-14 19:03:12 -07:00
identifier: 'appid',
dependsOn: [ ],
manifest: { foo: 'bar' },
preserveSecs: 0,
2024-12-09 16:20:24 +01:00
label: '',
appConfig: null,
targetId: null
2021-07-14 19:03:12 -07:00
};
2025-07-24 19:02:02 +02:00
let defaultBackupTarget;
before(async function () {
await setup();
2025-07-24 19:02:02 +02:00
defaultBackupTarget = await backupTargets._getDefault();
boxBackup.targetId = defaultBackupTarget.id;
appBackup.targetId = defaultBackupTarget.id;
});
after(cleanup);
2023-08-04 11:24:28 +05:30
describe('crud', function () {
it('add succeeds', async function () {
2025-07-24 18:09:33 +02:00
boxBackup.id = await backupListing.add(boxBackup);
2023-08-04 11:24:28 +05:30
});
it('fails with duplicate path', async function () {
2025-07-24 18:09:33 +02:00
const [error] = await safe(backupListing.add(boxBackup));
2023-08-04 11:24:28 +05:30
expect(error.reason).to.be(BoxError.ALREADY_EXISTS);
});
it('get succeeds', async function () {
2025-07-24 18:09:33 +02:00
const result = await backupListing.get(boxBackup.id);
2023-08-04 11:24:28 +05:30
delete result.creationTime;
expect(result).to.eql(boxBackup);
});
it('get of unknown id fails', async function () {
2025-07-24 18:09:33 +02:00
const result = await backupListing.get('somerandom');
2023-08-04 11:24:28 +05:30
expect(result).to.be(null);
});
it('getByTypePaged succeeds', async function () {
2025-07-24 18:09:33 +02:00
const results = await backupListing.getByTypePaged(backupListing.BACKUP_TYPE_BOX, 1, 5);
2023-08-04 11:24:28 +05:30
expect(results.length).to.be(1);
delete results[0].creationTime;
expect(results[0]).to.eql(boxBackup);
});
it('update succeeds', async function () {
2025-07-24 18:09:33 +02:00
await backupListing.update(boxBackup.id, { label: 'DuMonde', preserveSecs: 30 });
const result = await backupListing.get(boxBackup.id);
2023-08-04 11:24:28 +05:30
expect(result.label).to.eql('DuMonde');
expect(result.preserveSecs).to.eql(30);
});
it('delete succeeds', async function () {
2025-07-24 18:09:33 +02:00
await backupListing.del(boxBackup.id);
const result = await backupListing.get(boxBackup.id);
2023-08-04 11:24:28 +05:30
expect(result).to.be(null);
});
it('add app backup succeeds', async function () {
2025-07-24 18:09:33 +02:00
appBackup.id = await backupListing.add(appBackup);
2023-08-04 11:24:28 +05:30
});
it('get app backup succeeds', async function () {
2025-07-24 18:09:33 +02:00
const result = await backupListing.get(appBackup.id);
2023-08-04 11:24:28 +05:30
delete result.creationTime;
expect(result).to.eql(appBackup);
});
it('getByIdentifierAndStatePaged succeeds', async function () {
2025-07-24 18:09:33 +02:00
const results = await backupListing.getByIdentifierAndStatePaged(appBackup.identifier, backupListing.BACKUP_STATE_CREATING, 1, 5);
2023-08-04 11:24:28 +05:30
expect(results.length).to.be(1);
delete results[0].creationTime;
expect(results[0]).to.eql(appBackup);
});
it('delete app backup succeeds', async function () {
2025-07-24 18:09:33 +02:00
await backupListing.del(appBackup.id);
const result = await backupListing.get(appBackup.id);
2023-08-04 11:24:28 +05:30
expect(result).to.be(null);
});
2017-04-24 12:34:57 +02:00
});
});