loopback/test/access-token.test.js

41 lines
1009 B
JavaScript
Raw Normal View History

2013-11-13 19:49:08 +00:00
var loopback = require('../');
var Token = loopback.AccessToken.extend('MyToken');
// attach Token to testing memory ds
Token.attachTo(loopback.memory());
describe('loopback.token(app, options)', function() {
beforeEach(createTestingToken);
it('should populate req.token from the query string', function (done) {
var app = loopback();
var options = {};
2013-11-14 21:01:47 +00:00
options.model = Token;
2013-11-13 19:49:08 +00:00
var testToken = this.token;
app.use(loopback.token(app, options));
app.get('/', function (req, res) {
2013-11-14 21:01:47 +00:00
try {
assert(req.accessToken, 'req should have accessToken');
assert(req.accessToken.id === testToken.id);
} catch(e) {
return done(e);
}
2013-11-13 19:49:08 +00:00
res.send('ok');
});
request(app)
.get('/?access_token=' + this.token.id)
.expect(200)
.end(done);
});
});
function createTestingToken(done) {
var test = this;
Token.create({}, function (err, token) {
if(err) return done(err);
test.token = token;
done();
});
2013-11-14 21:01:47 +00:00
}