Fix support tests

This commit is contained in:
Girish Ramakrishnan
2023-12-03 20:00:57 +01:00
parent 344578006c
commit 8e28d2a5aa
3 changed files with 2 additions and 55 deletions
-25
View File
@@ -5,9 +5,6 @@ exports = module.exports = {
getRemoteSupport,
enableRemoteSupport,
canCreateTicket,
canEnableRemoteSupport
};
const appstore = require('../appstore.js'),
@@ -19,15 +16,6 @@ const appstore = require('../appstore.js'),
safe = require('safetydance'),
support = require('../support.js');
async function canCreateTicket(req, res, next) {
const [error, supportConfig] = await safe(support.getConfig());
if (error) return next(new HttpError(503, error.message));
if (!supportConfig.submitTickets) return next(new HttpError(405, 'feature disabled by admin'));
next();
}
async function createTicket(req, res, next) {
assert.strictEqual(typeof req.user, 'object');
@@ -41,25 +29,12 @@ async function createTicket(req, res, next) {
if (req.body.altEmail && typeof req.body.altEmail !== 'string') return next(new HttpError(400, 'altEmail must be string'));
if (req.body.enableSshSupport && typeof req.body.enableSshSupport !== 'boolean') return next(new HttpError(400, 'enableSshSupport must be a boolean'));
const [error, supportConfig] = await safe(support.getConfig());
if (error) return next(new HttpError(503, `Error getting support config: ${error.message}`));
if (supportConfig.email !== constants.SUPPORT_EMAIL) return next(new HttpError(503, 'Sending to non-cloudron email not implemented yet'));
const [ticketError, result] = await safe(appstore.createTicket(Object.assign({ }, req.body, { email: req.user.email, displayName: req.user.displayName }), AuditSource.fromRequest(req)));
if (ticketError) return next(new HttpError(503, `Error contacting cloudron.io: ${ticketError.message}. Please email ${constants.SUPPORT_EMAIL}`));
next(new HttpSuccess(201, result));
}
async function canEnableRemoteSupport(req, res, next) {
const [error, supportConfig] = await safe(support.getConfig());
if (error) return next(new HttpError(503, error.message));
if (!supportConfig.remoteSupport) return next(new HttpError(405, 'feature disabled by admin'));
next();
}
async function enableRemoteSupport(req, res, next) {
assert.strictEqual(typeof req.body, 'object');