Advertisement
Guest User

Untitled

a guest
Feb 11th, 2016
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1. function isMember(req, res, next) {
  2. MyService.GetUserAsync(authCookie)
  3. .then(function (user) {
  4. next();
  5. })
  6. .catch(function (err) {
  7. if (err.status === 400) {
  8. return res.redirect("/notAllowed");
  9. }
  10. else {
  11. return next(err);
  12. }
  13. });
  14. }
  15.  
  16. beforeEach(function () {
  17. // Overwrite the global timer functions (setTimeout, setInterval) with Sinon fakes
  18. this.clock = sinon.useFakeTimers();
  19. });
  20. afterEach(function () {
  21. // Restore the global timer functions to their native implementations
  22. this.clock.restore();
  23. });
  24.  
  25. it.only("pass authentication and set authCookie", function (done) {
  26. var user = {
  27. userNameField: "fakeUserName"
  28. };
  29. sinon.stub(MyService, "GetUserAsync").returns(Promise.resolve(user));
  30. var spyCallback = sinon.spy();
  31. var req {};
  32. var res = {};
  33. isMember(req, res, spyCallback);
  34. // Not waiting here!
  35. this.clock.tick(1510);
  36. // spyCallback.called is always false
  37. expect(spyCallback.called).to.equal(true);
  38. done();
  39. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement