Skip to content

Commit ed5d4b7

Browse files
author
Emmanouil Konstantinidis
committed
More tests for NotificationsStore
1 parent d1fa069 commit ed5d4b7

File tree

2 files changed

+40
-4
lines changed

2 files changed

+40
-4
lines changed

src/js/__tests__/stores/notifications.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,43 @@ describe('Tests for NotificationsStore', function () {
9191
jest.runAllTimers();
9292

9393
var repository = NotificationsStore._notifications[0][0].repository;
94+
var subject = NotificationsStore._notifications[0][0].subject;
9495
expect(repository.full_name).toBe('octocat/Hello-World');
96+
expect(subject.title).toBe('Greetings');
97+
expect(NotificationsStore.trigger).toHaveBeenCalled();
98+
99+
});
100+
101+
it('should get 0(zero) notifications from the GitHub API', function () {
102+
103+
spyOn(NotificationsStore, 'trigger');
104+
105+
var response = [];
106+
107+
var superagent = require('superagent');
108+
superagent.__setResponse(200, 'ok', response, false);
109+
110+
Actions.getNotifications();
111+
112+
jest.runAllTimers();
113+
114+
expect(NotificationsStore._notifications.length).toBe(0);
115+
expect(NotificationsStore.trigger).toHaveBeenCalled();
116+
117+
});
118+
119+
it('should FAIL to create a booking via the API', function () {
120+
121+
spyOn(NotificationsStore, 'trigger');
122+
spyOn(NotificationsStore, 'onGetNotificationsFailed');
123+
124+
var superagent = require('superagent');
125+
superagent.__setResponse(400, false);
126+
127+
Actions.getNotifications();
128+
129+
jest.runAllTimers();
130+
95131
expect(NotificationsStore.trigger).toHaveBeenCalled();
96132

97133
});

src/js/stores/notifications.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ var NotificationsStore = Reflux.createStore({
2323

2424
onGetNotifications: function () {
2525
var self = this;
26-
var tokens = AuthStore.authStatus();
2726

2827
apiRequests
2928
.getAuth('https://api.github.com/notifications')
@@ -45,16 +44,17 @@ var NotificationsStore = Reflux.createStore({
4544
});
4645

4746
var array = [];
48-
_.map(groupedNotifications, function (obj, i) {
47+
_.map(groupedNotifications, function (obj) {
4948
array.push(obj);
5049
});
5150

5251
this._notifications = array;
5352
this.trigger(this._notifications);
5453
},
5554

56-
onGetNotificationsFailed: function (error) {
57-
console.log('Errored.' + error);
55+
onGetNotificationsFailed: function () {
56+
this._notifications = [];
57+
this.trigger(this._notifications);
5858
}
5959

6060
});

0 commit comments

Comments
 (0)