Skip to content

Commit 460955f

Browse files
author
Emmanouil Konstantinidis
committed
Test AuthStore
1 parent fc982d5 commit 460955f

File tree

2 files changed

+55
-1
lines changed

2 files changed

+55
-1
lines changed

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,9 @@
6363
"collectCoverage": true,
6464
"collectCoverageOnlyFrom": {
6565
"src/js/actions/actions.js": true,
66-
"src/js/components/footer.js": true
66+
"src/js/components/navigation.js": true,
67+
"src/js/components/footer.js": true,
68+
"src/js/stores/auth.js": true
6769
},
6870
"unmockedModulePathPatterns": [
6971
"node_modules/react",

src/js/__tests__/stores/auth.js

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
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

Comments
 (0)