@apistudio/apim-cli
Version:
CLI for API Management Products
43 lines (42 loc) • 1.48 kB
JavaScript
import { checkForNullOrUndefined, isNullOrUndefined, } from "../../common/data-helper.js";
import { showError } from "./../../common/message-helper.js";
import { KindEnums } from "@apic/api-model/common/StudioEnums.js";
const addAssetRefValuesForTestKind = (refObjects, result, kind) => {
if (!isNullOrUndefined(refObjects)) {
refObjects.forEach((refObj) => {
if (!isNullOrUndefined(refObj.$ref)) {
result.push({
kind,
ref: refObj.$ref,
isNewlyAdded: true
});
}
});
}
};
const getRefsFromTestAsset = (asset) => {
const testAsset = asset;
const spec = testAsset.spec;
const result = [];
try {
checkForNullOrUndefined(testAsset, "Asset is null or undefined");
if (spec.environment?.$ref) {
addAssetRefValuesForTestKind([{ $ref: spec.environment.$ref }], result, KindEnums.Environment);
}
if (spec.request) {
spec.request.forEach((request) => {
if (request.assertions) {
if (request.assertions.$ref) {
addAssetRefValuesForTestKind([{ $ref: request.assertions.$ref }], result, KindEnums.Assertion);
}
}
});
}
return result;
}
catch (error) {
showError(error.message);
return [];
}
};
export { getRefsFromTestAsset };