我正在使用mocha为Javascript编写测试用例。我的代码完全像这样 apigee
这个JavaScript部署在apigee云中。它有权访问平台变量的地方。这是我的脚本代码.js
var responseCode = parseInt(context.getVariable(properties.source));
var log = {
org: context.getVariable(organization.name),
env: context.getVariable(environment.name),
responseCode: responseCode,
isError: (responseCode >= 400)
};
if (log.isError) {
log.errorMessage = context.getVariable(flow.error.message);
}
var logglyRequest = new Request(
'https://loggly.com/aaa',
'POST',
{'Content-Type': 'application/json'},
JSON.stringify(log)
);
httpClient.send(logglyRequest);
JavaScript代码在运行时可以访问properties.source。Apigee平台有自己的内部方式来解释jc如何访问这些参数。我的问题是,如果我正在为这个jc编写测试用例,我将如何模拟properties.source的值。我能够模拟函数调用context.getVariable((。我收到引用错误:未定义属性。在给定的 apigee 链接中使用相同的测试脚本。
尝试将以下内容添加到测试中:
global.properties = {
source: 'jwt.Decode-IAM-JWT.decoded.header.kid'
};
这就是我所做的,它工作得很好。