41 lines
1.7 KiB
JavaScript
41 lines
1.7 KiB
JavaScript
|
"use strict";
|
||
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||
|
};
|
||
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||
|
exports.validateSettings = exports.TC_OLDEST_COMPATIBLE_VERSION = void 0;
|
||
|
const consts_1 = require("./consts");
|
||
|
const texts_1 = require("./texts");
|
||
|
const semver_1 = __importDefault(require("semver"));
|
||
|
const jsonwebtoken_1 = require("jsonwebtoken");
|
||
|
// TODO: we should ask TC Dashboard
|
||
|
exports.TC_OLDEST_COMPATIBLE_VERSION = '1.14.2';
|
||
|
function validateSettings(settings, tcVersion, logger) {
|
||
|
const { authenticationToken, buildId, dashboardUrl } = settings;
|
||
|
let areSettingsValid = true;
|
||
|
if (!authenticationToken) {
|
||
|
logger.error(texts_1.AUTHENTICATION_TOKEN_NOT_DEFINED);
|
||
|
areSettingsValid = false;
|
||
|
}
|
||
|
else {
|
||
|
const token = jsonwebtoken_1.decode(authenticationToken);
|
||
|
if (!token || !token.projectId)
|
||
|
throw new Error(texts_1.AUTHENTICATION_TOKEN_INVALID);
|
||
|
}
|
||
|
if (!dashboardUrl) {
|
||
|
logger.error(texts_1.DASHBOARD_LOCATION_NOT_DEFINED);
|
||
|
areSettingsValid = false;
|
||
|
}
|
||
|
if (buildId && buildId.length > consts_1.MAX_BUILD_ID_LENGTH) {
|
||
|
logger.error(texts_1.createLongBuildIdError(buildId));
|
||
|
areSettingsValid = false;
|
||
|
}
|
||
|
if (!semver_1.default.valid(tcVersion))
|
||
|
throw new Error(texts_1.createTestCafeVersionInvalidError(tcVersion));
|
||
|
else if (semver_1.default.lt(tcVersion, exports.TC_OLDEST_COMPATIBLE_VERSION))
|
||
|
throw new Error(texts_1.createTestCafeVersionIncompatibledError(tcVersion));
|
||
|
return areSettingsValid;
|
||
|
}
|
||
|
exports.validateSettings = validateSettings;
|
||
|
;
|