1

I am writing a test driven development for my strongloop API code with the help of loopback-testing .

Here they do not have any detailed document on this, so i am stuck with case of argument passing with the API call

Example i have a below case,

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

i need to pass the below arguments with this 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}'

How can i pass these three arguments with this API ?

I can easily handle ,if there is only two types of arguments

Example :

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

 arguments : test_username  and  password

I can handle this like this ,

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

But how can i handle the above case , Many thanks for your answers for this example.

Jordan Kasper
  • 13,153
  • 3
  • 36
  • 55
Sakeer
  • 1,885
  • 3
  • 24
  • 43
  • see https://github.com/strongloop/loopback-testing/blob/afff664efab913f26974fb71cfc83dd77ec5efee/lib/helpers.js#L261 https://github.com/strongloop/loopback-testing/blob/afff664efab913f26974fb71cfc83dd77ec5efee/test/test.js#L49 – Midhun KM Apr 09 '15 at 06:11
  • Sorry fox i can't understand the doc , can you please explain this with an answer? – Sakeer Apr 09 '15 at 06:28

1 Answers1

3

I'm not entirely sure what your specific problem is, but I will attempt to walk through everything you should need.

I am assuming you are using the predefined prototype.updateAttributes() method for your model as described here.

Next assumption is that you want to use the built-in authentication and authorization to allow the user to call this method. Given that assumption, you need something like this in your test code:

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);
      });
  }
);

If you are using the out-of-the-box user model, you should be fine, but if you extended the model as is commonly done, you may need something like this early on in your test file:

lt.beforeEach.withUserModel('user');

Also, be aware of a few (currently incomplete) updates to will allow for better handling of built-in model extensions: Suggestions #56, Add support for non-default models #57, and givenLoggedInUser() function throws error #59.

philarmour
  • 394
  • 5
  • 10
  • Be warned: loopback-testing has been [deprecated](https://groups.google.com/forum/#!topic/loopbackjs/w038RvqHeYI) – philarmour Jan 04 '16 at 19:42