用摩卡柴和Stormpath

我的谷歌福可能失败了我,但我正在考虑为使用Stormpath进行身份validation的快速应用程序构buildunit testing。 所以典型的路线看起来像这样;

app.get('/api/user', stormpath.loginRequired, userApi.get);

在这种情况下,我将如何使用像Mocha + Chai这样的testing框架?

感谢@ rdegges,这导致我find一个很好的解决scheme。 我可以看到如何在stormpath中创build一个testing用户帐户,但在我的情况下,我很高兴有一个testing用户已经在Stormpath中设置。 所以我只需要创build会话,然后运行实际的testing(所以我只需要柴保持会话)。 所以这是我最终的解决scheme。

  var agent = chai.request.agent(server); agent .post('/login') .set('Accept', 'application/json') .set('Content-Type', 'application/x-www-form-urlencoded') .send({ login: '<username>', password: '<password>' }) .then(function (res) { // The `agent` now has the session cookie saved, and will send it // back to the server in the next request: agent .put('/user') .send({user:data}) .end((err, res) => { if (err){ Logger.error(res.text); } res.should.have.status(200); // Do testing here done(); }); }); 

看看我写在express-stormpath库里面的集成testing,例如: https : //github.com/stormpath/express-stormpath/blob/master/test/middlewares/test-groups-required。 JS#L208