javascript - Mocha and supertest, testing authentificate GET -


i'm using nodejs , sails framework create api.

i'm trying create test testing petition show list of array in db. can make login users.

i make test see user login with:

it('should return ok loged in',function(done){   agentuser = require('supertest').agent(sails.hooks.http.app);   var user = {user_id: user.id, password:'demo'};   agentuser.post('/user-login')     .send(user)     .expect(200, done); }); 

this test ok, can make test verify list can get petition. make this:

it('should return ok level list', function(done){   agent     .get('/books')     .set('accept', 'application/json')     .expect('content-type', /json/)     .expect(200)     .end(function(err, res){       if(err) return done(err);       res.body.should.be.instanceof(array);       res.body.length.should.be.equal(4);       res.body[0].should.have.property('id');       res.body[0].should.have.property('books');       res.body[0].should.have.property('description');       done();     }); }); 

the test not passed because expect 200 , 403 not logged in. how can make test passed petition in test make login first?

thanks


Comments

Popular posts from this blog

Formatting string according to pattern without regex in php -

c - zlib and gdi32 with OpenSSL? -

java - inputmismatch exception -