Files
cloudron-box/src/test/archives-test.js
T
Girish Ramakrishnan 96dc79cfe6 Migrate codebase from CommonJS to ES Modules
- Convert all require()/module.exports to import/export across 260+ files
- Add "type": "module" to package.json to enable ESM by default
- Add migrations/package.json with "type": "commonjs" to keep db-migrate compatible
- Convert eslint.config.js to ESM with sourceType: "module"
- Replace __dirname/__filename with import.meta.dirname/import.meta.filename
- Replace require.main === module with process.argv[1] === import.meta.filename
- Remove 'use strict' directives (implicit in ESM)
- Convert dynamic require() in switch statements to static import lookup maps
  (dns.js, domains.js, backupformats.js, backupsites.js, network.js)
- Extract self-referencing exports.CONSTANT patterns into standalone const
  declarations (apps.js, services.js, locks.js, users.js, mail.js, etc.)
- Lazify SERVICES object in services.js to avoid circular dependency TDZ issues
- Add clearMailQueue() to mailer.js for ESM-safe queue clearing in tests
- Add _setMockApp() to ldapserver.js for ESM-safe test mocking
- Add _setMockResolve() wrapper to dig.js for ESM-safe DNS mocking in tests
- Convert backupupload.js to use dynamic imports so --check exits before
  loading the module graph (which requires BOX_ENV)
- Update check-install to use ESM import for infra_version.js
- Convert scripts/ (hotfix, release, remote_hotfix.js, find-unused-translations)
- All 1315 tests passing

Migration stats (AI-assisted using Cursor with Claude):
- Wall clock time: ~3-4 hours
- Assistant completions: ~80-100
- Estimated token usage: ~1-2M tokens

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-14 15:11:45 +01:00

85 lines
2.6 KiB
JavaScript

/* global it:false */
import * as archives from '../archives.js';
import backups from '../backups.js';
import BoxError from '../boxerror.js';
import * as common from './common.js';
import expect from 'expect.js';
import safe from 'safetydance';
/* global describe:false */
/* global before:false */
/* global after:false */
describe('Archives', function () {
const { setup, cleanup, auditSource, getDefaultBackupSite } = common;
const appBackup = {
id: null,
remotePath: 'backup-box',
encryptionVersion: 2,
packageVersion: '1.0.0',
type: backups.BACKUP_TYPE_APP,
state: backups.BACKUP_STATE_NORMAL,
identifier: 'box',
dependsOn: [ 'dep1' ],
manifest: null,
preserveSecs: 0,
label: '',
appConfig: { loc: 'loc1' },
siteId: null
};
before(async function () {
await setup();
appBackup.siteId = (await getDefaultBackupSite()).id;
appBackup.id = await backups.add(appBackup);
});
after(cleanup);
let archiveId;
it('cannot add bad backup to archives', async function () {
const [error] = await safe(archives.add('badId', {}, auditSource));
expect(error.reason).to.be(BoxError.NOT_FOUND);
});
it('can add good backup to archives', async function () {
archiveId = await archives.add(appBackup.id, {}, auditSource);
});
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);
expect(result.appConfig).to.eql(appBackup.appConfig);
});
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);
expect(result[0].appConfig).to.eql(appBackup.appConfig);
});
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 () {
const [error] = await safe(archives.del({ id: 'badId' }, auditSource));
expect(error.reason).to.be(BoxError.NOT_FOUND);
});
it('can del valid archive', async function () {
await archives.del({ id: archiveId }, auditSource);
const result = await archives.list(1, 10);
expect(result.length).to.be(0);
});
});