Files
cloudron-box/src/routes/test/common.js

253 lines
7.8 KiB
JavaScript
Raw Normal View History

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 09:53:14 +01:00
import apps from '../../apps.js';
import appstore from '../../appstore.js';
import backupSites from '../../backupsites.js';
import logger from '../../logger.js';
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 09:53:14 +01:00
import constants from '../../constants.js';
import database from '../../database.js';
2026-02-18 22:21:54 +01:00
import assert from 'node:assert/strict';
import mailer from '../../mailer.js';
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 09:53:14 +01:00
import nock from 'nock';
import oidcClients from '../../oidcclients.js';
import oidcServer from '../../oidcserver.js';
import server from '../../server.js';
import settings from '../../settings.js';
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 09:53:14 +01:00
import superagent from '@cloudron/superagent';
import tasks from '../../tasks.js';
import timers from 'timers/promises';
import tokens from '../../tokens.js';
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 09:53:14 +01:00
const { log, trace } = logger('test/common');
2021-05-17 22:23:18 -07:00
2025-02-12 14:09:09 +01:00
const manifest = {
'id': 'io.cloudron.test',
'author': 'The Presidents Of the United States Of America',
'title': 'test title',
'description': 'test description',
'tagline': 'test rocks',
'website': 'http://test.cloudron.io',
'contactEmail': 'test@cloudron.io',
'version': '0.1.0',
'manifestVersion': 2,
'dockerImage': 'cloudron/test:25.2.0',
'healthCheckPath': '/',
'httpPort': 7777,
'tcpPorts': {
'ECHO_SERVER_PORT': {
'title': 'Echo Server Port',
'description': 'Echo server',
'containerPort': 7778
}
},
'addons': {
'oauth': { },
'redis': { },
'mysql': { },
'postgresql': { }
}
};
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 09:53:14 +01:00
const mockApiServerOrigin = 'http://localhost:6060';
const dashboardDomain = 'test.example.com';
const appstoreToken = 'toktok';
const owner = {
id: null,
username: 'superadmin',
password: 'Foobar?1337',
email: 'superadmin@cloudron.local',
displayName: 'Super Admin',
token: null
};
const admin = {
id: null,
username: 'administrator',
password: 'Foobar?1339',
email: 'admin@cloudron.local',
token: null
};
const user = {
id: null,
username: 'user',
password: 'Foobar?1338',
email: 'user@cloudron.local',
token: null
};
const app = {
id: 'appid',
appStoreId: 'appStoreId',
installationState: apps.ISTATE_PENDING_INSTALL,
runState: 'running',
subdomain: 'app',
domain: 'test.example.com',
fqdn: 'app.test.example.com',
manifest,
containerId: 'someid',
portBindings: {},
accessRestriction: null,
memoryLimit: 0,
mailboxDomain: 'test.example.com',
secondaryDomains: [],
redirectDomains: [],
aliasDomains: []
};
const serverUrl = `http://localhost:${constants.PORT}`;
2021-05-17 22:23:18 -07:00
2021-09-07 09:57:49 -07:00
async function setupServer() {
log('Setting up server');
2023-03-21 13:54:40 +01:00
await database.initialize();
2023-08-14 11:08:38 +05:30
await database._clear();
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 09:53:14 +01:00
await appstore._setApiServerOrigin(mockApiServerOrigin);
2025-06-11 22:00:09 +02:00
await oidcServer.stop();
2023-03-21 13:54:40 +01:00
await server.start();
log('Set up server complete');
}
2021-08-12 16:27:31 -07:00
2021-09-07 09:57:49 -07:00
async function setup() {
log('Setting up');
2025-02-06 15:01:59 +01:00
2021-09-07 09:57:49 -07:00
await setupServer();
// setup
let response = await superagent.post(`${serverUrl}/api/v1/provision/setup`)
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 09:53:14 +01:00
.send({ domainConfig: { provider: 'noop', domain: dashboardDomain, config: {}, tlsConfig: { provider: 'fallback' } } });
2026-02-18 22:21:54 +01:00
assert.deepEqual(response.status, 200);
2021-09-07 09:57:49 -07:00
2023-05-14 10:53:50 +02:00
await timers.setTimeout(2000);
2021-09-07 09:57:49 -07:00
// create owner
const scope1 = nock(await appstore.getApiServerOrigin())
.post('/api/v1/register_cloudron3', (body) => typeof body.domain === 'string' && typeof body.version === 'string')
2025-06-06 11:09:48 +02:00
.reply(201, { cloudronId: 'cid', cloudronToken: 'CLOUDRON_TOKEN' });
2025-10-07 09:34:35 +02:00
const scope2 = nock(await appstore.getApiServerOrigin())
2026-02-21 20:03:26 +01:00
.post('/api/v1/subscription3?accessToken=CLOUDRON_TOKEN', (body) => typeof body.state === 'object' && typeof body.state.users.count === 'number')
2025-10-07 09:34:35 +02:00
.reply(200, { features: {} });
response = await superagent.post(`${serverUrl}/api/v1/provision/activate`)
2021-09-07 09:57:49 -07:00
.query({ setupToken: 'somesetuptoken' })
2025-10-07 09:34:35 +02:00
.send({ username: owner.username, password: owner.password, email: owner.email })
.ok(() => true);
2026-02-18 22:21:54 +01:00
assert.deepEqual(response.status, 201);
2021-09-07 09:57:49 -07:00
owner.token = response.body.token;
owner.id = response.body.userId;
2026-02-18 22:21:54 +01:00
assert.ok(scope1.isDone());
2025-06-06 11:25:57 +02:00
scope1.persist(false);
2026-02-18 22:21:54 +01:00
assert.ok(scope2.isDone());
2025-10-07 09:34:35 +02:00
scope2.persist(false);
2021-09-07 09:57:49 -07:00
// create an admin
response = await superagent.post(`${serverUrl}/api/v1/users`)
.query({ access_token: owner.token })
.send({ username: admin.username, email: admin.email, password: admin.password, role: 'admin' });
2026-02-18 22:21:54 +01:00
assert.equal(response.status, 201);
admin.id = response.body.id;
// HACK to get a token for second user (passwords are generated and the user should have gotten a password setup link...)
2025-06-11 22:53:29 +02:00
const token1 = await tokens.add({ identifier: admin.id, clientId: oidcClients.ID_WEBADMIN, expires: Date.now() + (60 * 60 * 1000), name: 'fromtest', allowedIpRanges: '' });
admin.token = token1.accessToken;
2021-09-07 09:57:49 -07:00
// create user
response = await superagent.post(`${serverUrl}/api/v1/users`)
.query({ access_token: owner.token })
.send({ username: user.username, email: user.email, password: user.password });
2026-02-18 22:21:54 +01:00
assert.equal(response.status, 201);
2021-09-07 09:57:49 -07:00
user.id = response.body.id;
// HACK to get a token for second user (passwords are generated and the user should have gotten a password setup link...)
2025-06-11 22:53:29 +02:00
const token2 = await tokens.add({ identifier: user.id, clientId: oidcClients.ID_WEBADMIN, expires: Date.now() + (60 * 60 * 1000), name: 'fromtest', allowedIpRanges: '' });
user.token = token2.accessToken;
2021-11-17 11:14:33 -08:00
2025-02-12 14:09:09 +01:00
// create app object
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 09:53:14 +01:00
await apps.add(app.id, app.appStoreId, '', app.manifest, app.subdomain, app.domain, app.portBindings, app);
2025-02-12 14:09:09 +01:00
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 09:53:14 +01:00
await settings._set(settings.APPSTORE_API_TOKEN_KEY, appstoreToken); // appstore token
2025-02-06 15:01:59 +01:00
log('Setup complete');
2021-05-17 22:23:18 -07:00
}
2021-08-20 09:19:44 -07:00
async function cleanup() {
log('Cleaning up');
2021-09-07 09:57:49 -07:00
await server.stop();
2025-06-11 22:00:09 +02:00
await oidcServer.stop();
2025-07-17 01:16:24 +02:00
if (!nock.isActive()) nock.activate();
log('Cleaned up');
2021-05-17 22:23:18 -07:00
}
2021-06-05 11:46:34 -07:00
function clearMailQueue() {
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 09:53:14 +01:00
mailer.clearMailQueue();
2021-06-05 11:46:34 -07:00
}
async function checkMails(number) {
2023-05-14 10:53:50 +02:00
await timers.setTimeout(1000);
2026-02-18 22:21:54 +01:00
assert.equal(mailer._mailQueue.length, number);
2021-06-05 11:46:34 -07:00
clearMailQueue();
}
async function waitForTask(taskId) {
log(`Waiting for task: ${taskId}`);
2025-02-06 15:01:59 +01:00
2024-01-11 16:31:12 +01:00
for (let i = 0; i < 30; i++) {
const result = await tasks.get(taskId);
2026-02-18 22:21:54 +01:00
assert.notEqual(result, null);
if (!result.active) {
if (result.success) return result;
throw new Error(`Task ${taskId} failed: ${result.error.message} - ${result.error.stack}`);
}
2023-05-14 10:53:50 +02:00
await timers.setTimeout(2000);
log(`Waiting for task to ${taskId} finish`);
}
throw new Error(`Task ${taskId} never finished`);
}
2025-07-17 01:16:24 +02:00
async function waitForAsyncTask(es) {
return new Promise((resolve, reject) => {
const messages = [];
es.addEventListener('message', function (message) {
log(`waitForAsyncTask: ${message.data}`);
2025-07-17 01:16:24 +02:00
messages.push(JSON.parse(message.data));
if (messages[messages.length-1].type === 'done') {
log('waitForAsyncTask: finished');
2025-07-17 01:16:24 +02:00
es.close();
resolve(messages);
}
});
es.addEventListener('error', function (error) {
log('waitForAsyncTask: errored', error);
2025-07-17 01:16:24 +02:00
es.close();
const e = new Error(error.message);
e.code = error.code;
reject(e);
});
});
}
2025-07-25 07:44:25 +02:00
2025-09-12 09:48:37 +02:00
async function getDefaultBackupSite() {
2025-09-29 14:44:42 +02:00
const result = await backupSites.list();
2025-08-04 15:00:21 +02:00
return result.find(r => r.name === 'Default');
2025-07-25 07:44:25 +02:00
}
export default {
setup,
setupServer,
cleanup,
clearMailQueue,
checkMails,
waitForTask,
waitForAsyncTask,
owner,
admin,
user,
app,
getDefaultBackupSite,
mockApiServerOrigin,
dashboardDomain,
dashboardFqdn: 'my.test.example.com',
appstoreToken,
mailFqdn: 'my.test.example.com',
serverUrl,
auditSource: { ip: '5.6.7.8' }
};