UNPKG

@contract-case/case-core

Version:

Core functionality for the ContractCase contract testing suite

77 lines 4.71 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.BrokerService = void 0; const case_plugin_base_1 = require("@contract-case/case-plugin-base"); const downloadCaseContracts_1 = require("./downloadCaseContracts"); class BrokerService { broker; environment; constructor(broker, environment) { this.broker = broker; this.environment = environment; } publishVerificationResults(contract, success, context) { if (context['_case:currentRun:context:publish'] === false || context['_case:currentRun:context:publish'] === 'NEVER') { context.logger.debug(`Not publishing verification results for ${contract.description.consumerName} -> ${contract.description.providerName} as publish: 'NEVER' is set (or false)`); return Promise.resolve(); } if (context['_case:currentRun:context:publish'] === 'ONLY_IN_CI' && !this.environment.isCi()) { context.logger.debug(`Not publishing verification results for ${contract.description.consumerName} -> ${contract.description.providerName} as publish: 'ONLY_IN_CI' is set, and this is not a detected CI environment`); return Promise.resolve(); } if (context['_case:currentRun:context:publish'] === true || context['_case:currentRun:context:publish'] === 'ALWAYS' || (context['_case:currentRun:context:publish'] === 'ONLY_IN_CI' && this.environment.isCi())) { return this.broker .publishVerificationResults(contract, success, this.environment.version(context), this.environment.branch(), (0, case_plugin_base_1.addLocation)(':PublishingContractAdvanced', context)) .then(() => { }); } const message = `Configuration property 'publish' was set to the unexpected value '${context['_case:currentRun:context:publish']}'`; context.logger.error(message); return Promise.reject(new case_plugin_base_1.CaseConfigurationError(message, 'DONT_ADD_LOCATION')); } publishContract(contract, context) { if (context['_case:currentRun:context:publish'] === false || context['_case:currentRun:context:publish'] === 'NEVER') { context.logger.debug(`Not publishing contract for ${contract.description.consumerName} -> ${contract.description.providerName} as publish: 'NEVER' is set (or false)`); return Promise.resolve(); } if (context['_case:currentRun:context:publish'] === 'ONLY_IN_CI' && !this.environment.isCi()) { context.logger.debug(`Not publishing contract for ${contract.description.consumerName} -> ${contract.description.providerName} as publish: 'ONLY_IN_CI' is set, and this is not a detected CI environment`); return Promise.resolve(); } if (context['_case:currentRun:context:publish'] === true || context['_case:currentRun:context:publish'] === 'ALWAYS' || (context['_case:currentRun:context:publish'] === 'ONLY_IN_CI' && this.environment.isCi())) { return this.broker .publishContract(contract, this.environment.version(context), this.environment.branch(), (0, case_plugin_base_1.addLocation)(':PublishingContractAdvanced', context)) .then(() => { }); } const message = `Configuration property 'publish' was set to the unexpected value '${context['_case:currentRun:context:publish']}'`; context.logger.error(message); return Promise.reject(new case_plugin_base_1.CaseConfigurationError(message, 'DONT_ADD_LOCATION')); } async downloadContracts(serviceName, context) { const contractUrls = await this.broker.urlsForVerification(serviceName, context); context.logger.maintainerDebug('URLs are:', contractUrls); if (contractUrls.length === 0) { context.logger.warn('No contracts to verify. This may be normal if there is nothing to verify for this service'); return []; } return (0, downloadCaseContracts_1.downloadCaseContracts)(contractUrls, this.broker, context); } canDeploy(serviceName, environment, context, versionOverride) { const versionToCheck = versionOverride != null ? versionOverride : this.environment.version(context); context.logger.debug(`Checking whether '${serviceName}' at version '${versionToCheck}' can be deployed to '${environment}'`); return this.broker.canDeploy(serviceName, versionToCheck, environment, context); } } exports.BrokerService = BrokerService; //# sourceMappingURL=BrokerService.js.map