2020-04-29 18:44:27 +03:00
|
|
|
const should = require('should');
|
|
|
|
const sinon = require('sinon');
|
|
|
|
const _ = require('lodash');
|
|
|
|
const fs = require('fs-extra');
|
|
|
|
const models = require('../../../../core/server/models');
|
|
|
|
const exporter = require('../../../../core/server/data/exporter');
|
|
|
|
const dbBackup = require('../../../../core/server/data/db/backup');
|
2017-12-14 05:36:50 +03:00
|
|
|
|
|
|
|
describe('Backup', function () {
|
2020-04-29 18:44:27 +03:00
|
|
|
let exportStub;
|
|
|
|
let filenameStub;
|
|
|
|
let fsStub;
|
2017-12-14 05:36:50 +03:00
|
|
|
|
|
|
|
before(function () {
|
|
|
|
models.init();
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(function () {
|
2019-01-21 19:53:44 +03:00
|
|
|
sinon.restore();
|
2017-12-14 05:36:50 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
beforeEach(function () {
|
2019-01-21 19:53:44 +03:00
|
|
|
exportStub = sinon.stub(exporter, 'doExport').resolves();
|
|
|
|
filenameStub = sinon.stub(exporter, 'fileName').resolves('test');
|
|
|
|
fsStub = sinon.stub(fs, 'writeFile').resolves();
|
2017-12-14 05:36:50 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should create a backup JSON file', function (done) {
|
2020-02-13 07:53:44 +03:00
|
|
|
dbBackup.backup().then(function () {
|
2017-12-14 05:36:50 +03:00
|
|
|
exportStub.calledOnce.should.be.true();
|
|
|
|
filenameStub.calledOnce.should.be.true();
|
|
|
|
fsStub.calledOnce.should.be.true();
|
|
|
|
|
|
|
|
done();
|
|
|
|
}).catch(done);
|
|
|
|
});
|
|
|
|
});
|