|
| 1 | +/*global jest, describe, it, expect, spyOn, beforeEach */ |
| 2 | + |
| 3 | +'use strict'; |
| 4 | + |
| 5 | +jest.dontMock('reflux'); |
| 6 | +jest.dontMock('../../stores/auth'); |
| 7 | +jest.dontMock('../../utils/api-requests'); |
| 8 | +jest.dontMock('../../actions/actions'); |
| 9 | + |
| 10 | +describe('Tests for AuthStore', function () { |
| 11 | + |
| 12 | + var AuthStore, Actions, apiRequests; |
| 13 | + |
| 14 | + beforeEach(function () { |
| 15 | + |
| 16 | + window.localStorage = { |
| 17 | + item: false, |
| 18 | + setItem: function (item) { |
| 19 | + this.item = item; |
| 20 | + }, |
| 21 | + getItem: function () { |
| 22 | + return this.item; |
| 23 | + }, |
| 24 | + clear: function () { |
| 25 | + this.item = false; |
| 26 | + } |
| 27 | + }; |
| 28 | + |
| 29 | + Actions = require('../../actions/actions'); |
| 30 | + apiRequests = require('../../utils/api-requests'); |
| 31 | + AuthStore = require('../../stores/auth'); |
| 32 | + }); |
| 33 | + |
| 34 | + it('should login - store the token', function () { |
| 35 | + spyOn(localStorage, 'setItem').andCallThrough(); |
| 36 | + var githubToken = '123456'; |
| 37 | + AuthStore.onLogin(githubToken); |
| 38 | + expect(AuthStore._githubtoken).toEqual(githubToken); |
| 39 | + expect(AuthStore.authStatus()).toEqual(githubToken); |
| 40 | + expect(localStorage.setItem).toHaveBeenCalledWith('githubtoken', githubToken); |
| 41 | + }); |
| 42 | + |
| 43 | + it('should logout - remove the token', function () { |
| 44 | + spyOn(localStorage, 'clear').andCallThrough(); |
| 45 | + var githubToken = false; |
| 46 | + AuthStore.onLogout(githubToken); |
| 47 | + expect(AuthStore._githubtoken).toEqual(false); |
| 48 | + expect(AuthStore.authStatus()).toEqual(false); |
| 49 | + expect(localStorage.clear).toHaveBeenCalled(); |
| 50 | + }); |
| 51 | + |
| 52 | +}); |
0 commit comments