我正在尝试为使用流星编写的API端点创建一个测试。我用的是茉莉花和速度。它打算在同一个项目中运行,这就是我使用它们的原因。
当我试图运行测试并检查端点中的数据时,问题就出现了。我在mongodb副本中有一个引导数据集,当我POST它时,它与本地应用程序中引导的数据集不匹配。
下面是示例代码:
Jasmine.onTest(function () {
describe('RestApi.MyMethod', function () {
it('Expects to fail because it lacks of valid parameters', function () { /*but it fails because of the user can't be found in the real app*/
var response = "";
var userId = Meteor.users.findOne({"username": "MyUser"})._id;
try {
response = Meteor.http.call(
"POST",
"http://localhost:3000/api/myMethod",
{
data: {
"userId":
},
timeout: 1000
}
);
} catch(error){
expect(error.message.indexOf("failed [400]")).toBeGreaterThan(-1);
expect(error.message.indexOf("Invalid parameters provided")).toBeGreaterThan(-1);
}
expect(response).toBe('');
});
});
});
我认为它应该指向镜像的rest api。有办法做到这一点吗?我将localhost:3000更改为localhost:5000,但没有起作用。如何检查镜像的端口?
提前感谢!