|
1 | 1 | import { expect } from 'chai'; |
2 | 2 | import nock from 'nock'; |
3 | | -import { apiMiddleware } from 'redux-api-middleware'; |
| 3 | +import { apiMiddleware, ApiError } from 'redux-api-middleware'; |
4 | 4 | import configureMockStore from 'redux-mock-store'; |
| 5 | + |
| 6 | +import Constants from '../../utils/constants'; |
5 | 7 | import * as actions from '../../actions'; |
6 | 8 |
|
7 | 9 | const middlewares = [ apiMiddleware ]; |
@@ -186,7 +188,6 @@ describe('actions/index.js', () => { |
186 | 188 |
|
187 | 189 | }); |
188 | 190 |
|
189 | | - |
190 | 191 | it('should mark a repository\'s notifications as read with success', () => { |
191 | 192 | const loginId = 'ekonstantinidis'; |
192 | 193 | const repoId = 'gitify'; |
@@ -249,6 +250,44 @@ describe('actions/index.js', () => { |
249 | 250 |
|
250 | 251 | }); |
251 | 252 |
|
| 253 | + it('should check if the user has starred the repository', () => { |
| 254 | + nock('https://api.github.com/') |
| 255 | + .get(`/user/starred/${Constants.REPO_SLUG}`) |
| 256 | + .reply(200); |
| 257 | + |
| 258 | + const expectedActions = [ |
| 259 | + { type: actions.HAS_STARRED_REQUEST, payload: undefined, meta: undefined }, |
| 260 | + { type: actions.HAS_STARRED_SUCCESS, payload: undefined, meta: undefined } |
| 261 | + ]; |
| 262 | + |
| 263 | + const store = createMockStore({ response: [] }, expectedActions); |
| 264 | + |
| 265 | + return store.dispatch(actions.checkHasStarred()) |
| 266 | + .then(() => { // return of async actions |
| 267 | + expect(store.getActions()).to.eql(expectedActions); |
| 268 | + }); |
| 269 | + |
| 270 | + }); |
| 271 | + |
| 272 | + it('should check if the user has starred the repository', () => { |
| 273 | + nock('https://api.github.com/') |
| 274 | + .get(`/user/starred/${Constants.REPO_SLUG}`) |
| 275 | + .reply(404); |
| 276 | + |
| 277 | + const apiError = new ApiError(404, 'Not Found', undefined); |
| 278 | + const expectedActions = [ |
| 279 | + { type: actions.HAS_STARRED_REQUEST, payload: undefined, meta: undefined }, |
| 280 | + { type: actions.HAS_STARRED_FAILURE, payload: apiError, error: true, meta: undefined } |
| 281 | + ]; |
| 282 | + |
| 283 | + const store = createMockStore({ response: [] }, expectedActions); |
| 284 | + |
| 285 | + return store.dispatch(actions.checkHasStarred()) |
| 286 | + .then(() => { // return of async actions |
| 287 | + expect(store.getActions()).to.eql(expectedActions); |
| 288 | + }); |
| 289 | + |
| 290 | + }); |
252 | 291 |
|
253 | 292 | it('should search the notifications with a query', () => { |
254 | 293 |
|
|
0 commit comments