-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
410 additions
and
112 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import moxios from "moxios"; | ||
import thunk from "redux-thunk"; | ||
import configureMockStore from "redux-mock-store"; | ||
import axios from "../../utils/axios"; | ||
|
||
import { followUser } from "../../redux/actions/followingActions"; | ||
import { | ||
FOLLOWING_FAILED, | ||
FOLLOWING_SUCCESS, | ||
WAITING_RESPONSE | ||
} from "../../redux/actionTypes"; | ||
|
||
const mockStore = configureMockStore([thunk]); | ||
let store; | ||
|
||
describe("test the following actions", () => { | ||
beforeEach(() => { | ||
moxios.install(axios); | ||
store = mockStore({}); | ||
}); | ||
|
||
afterEach(() => { | ||
moxios.uninstall(axios); | ||
}); | ||
|
||
describe("test fetch following", () => { | ||
test("should dispatch the success action after successfully following the user", () => { | ||
store = mockStore({}); | ||
const expectedActions = [ | ||
{ type: WAITING_RESPONSE }, | ||
{ type: FOLLOWING_SUCCESS, payload: true } | ||
]; | ||
moxios.stubRequest(`${process.env.API_URL}/profiles/claude/follow`, { | ||
status: 201, | ||
response: { message: "Follow successful" } | ||
}); | ||
return store.dispatch(followUser("claude")).then(() => { | ||
expect(store.getActions()).toEqual(expectedActions); | ||
}); | ||
}); | ||
|
||
test("should dispatch the success action after successfully unfollowing the user", () => { | ||
store = mockStore({}); | ||
const expectedActions = [ | ||
{ type: WAITING_RESPONSE }, | ||
{ type: FOLLOWING_SUCCESS, payload: false } | ||
]; | ||
moxios.stubRequest(`${process.env.API_URL}/profiles/claude/follow`, { | ||
status: 202, | ||
response: { message: "You have unfollowed this author" } | ||
}); | ||
return store.dispatch(followUser("claude")).then(() => { | ||
expect(store.getActions()).toEqual(expectedActions); | ||
}); | ||
}); | ||
|
||
test("should dispatch the failed action if there was a problem while following the user", () => { | ||
store = mockStore({}); | ||
const expectedActions = [ | ||
{ type: WAITING_RESPONSE }, | ||
{ type: FOLLOWING_FAILED, payload: false } | ||
]; | ||
moxios.stubRequest(`${process.env.API_URL}/profiles/claude/follow`, { | ||
status: 500, | ||
response: { message: "Error while following the user" } | ||
}); | ||
return store.dispatch(followUser("claude")).then(() => { | ||
expect(store.getActions()).toEqual(expectedActions); | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import followingReducer, { | ||
initialState | ||
} from "../../redux/reducers/followingReducer"; | ||
import { | ||
FOLLOWING_FAILED, | ||
FOLLOWING_SUCCESS, | ||
WAITING_RESPONSE | ||
} from "../../redux/actionTypes"; | ||
|
||
describe("Following reducers", () => { | ||
it("should return initial state", () => { | ||
expect(followingReducer(undefined, {})).toEqual(initialState); | ||
}); | ||
|
||
it("should handle FOLLOWING", () => { | ||
expect(followingReducer(initialState, { type: WAITING_RESPONSE })).toEqual({ | ||
...initialState, | ||
isFetching: true | ||
}); | ||
}); | ||
|
||
it("should handle FOLLOWING SUCCESS, if followed, the status must be true", () => { | ||
expect( | ||
followingReducer(initialState, { | ||
type: FOLLOWING_SUCCESS, | ||
payload: true | ||
}) | ||
).toEqual({ ...initialState, status: true }); | ||
}); | ||
|
||
it("should handle FOLLOWING SUCCESS, if unfollowed, the status must be false", () => { | ||
expect( | ||
followingReducer(initialState, { | ||
type: FOLLOWING_SUCCESS, | ||
payload: false | ||
}) | ||
).toEqual({ ...initialState, status: false }); | ||
}); | ||
|
||
it("should handle WAITING_RESPONSE FAILED", () => { | ||
expect( | ||
followingReducer(initialState, { | ||
type: FOLLOWING_FAILED, | ||
payload: false | ||
}) | ||
).toEqual({ ...initialState, status: false }); | ||
}); | ||
}); |
Oops, something went wrong.