There are a few different things here, so I divided my answer into two parts.
1) First you need to create test users via Facebook. You can do this in one of two ways: 1) Facebook Graph API or 2) through the Roles page of your application.
2) The recommended method for persistent sessions with SuperTest uses the SuperAgent method .agent () to continue the sessions. Everything you can do with SuperAgent you can do with SuperTest. See Github for more details.
var supertest = require('supertest'); var app = require('../lib/your_app_location'); describe('when user not logged in', function() { describe('POST /api/posts', function() { var agent1 = supertest.agent(app); agent1 .post(API.url('posts')) .set('Accept', 'application/json') .send(post: data) .(end(function(err, res) { should.not.exist(err); res.should.have.status(401); should.exist(res.headers['set-cookie']); done(); })); }); });
VisionMedia Github has some more good code snippets. Find them here .
source share