在编写回送testing时如何传递input参数

我正在使用回送testing来为我的strongloop API代码编写一个testing驱动的开发。

在这里他们没有任何关于这个的详细文档,所以我坚持使用API​​调用传递参数的情况

例如我有一个下面的例子,

Method : PUT URL : /api/admin/vineyard/<vineyard_id> 

我需要通过这个URL下面的参数

 1. 'vineyard_id' is a id of vine, it should be an integer . 2. in header = 'token' 3. in body = '{'name':'tastyWine','price':200}' 

我怎样才能传递这三个参数与这个API?

如果只有两种参数,我可以轻易处理

例如:

  Method : POST `/api/user/members/<test_username>/auth'` arguments : test_username and password 

我可以这样处理,

 lt.describe.whenCalledRemotely('POST', '/api/user/members/'+test_username+'/auth', { 'password': test_passwords }, 

但是,我怎样才能处理上述情况,非常感谢您为这个例子的答案。

我不完全确定你的具体问题是什么,但是我会尝试去解决你所需要的一切。

我假设您正在为您的模型使用预定义的prototype.updateAttributes()方法,如此处所述。

接下来的假设是你想要使用内置的authentication和授权来允许用户调用这个方法。 考虑到这个假设,在你的testing代码中你需要这样的东西:

 var vineyard_id = 123; //the id of the test item you want to change var testUser = {email: 'test@test.com',password: 'test'}; lt.describe.whenCalledByUser(testUser, 'PUT', '/api/admin/vineyard/'+vineyard_id, { 'name':'tastyWine', 'price':200 }, function () { it('should update the record and return ok', function() { assert.equal(this.res.statusCode, 200); }); } ); 

如果您使用的是开箱即​​用的用户模型,那么您应该没问题,但是如果按照常规方式扩展模型,则可能在testing文件的早期阶段需要这样的内容:

 lt.beforeEach.withUserModel('user'); 

此外,请注意几个(当前不完整)的更新将允许更好地处理内置的模型扩展: build议#56 , 添加对非默认模型#57的支持 ,并且givenLoggedInUser()函数抛出错误#59 。