Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
niomwungeri-fabrice committed May 10, 2019
1 parent 6a8242c commit 9bc7c09
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 215 deletions.
70 changes: 40 additions & 30 deletions src/__tests__/__actions__/commentsActions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import {
} from "../../redux/actions/commentActions";
import {
FETCHING_COMMENTS,
CREATE_NEW_COMMENT,
SET_LOADING_COMMENTS,
SET_SUCCESS_MESSAGE,
SET_ERROR_MESSAGE,
COMMENTS_INPUT
Expand All @@ -22,17 +24,19 @@ import {
const { API_URL } = process.env;
const mockStore = configureStore([thunk]);
let store;
const comments = [{ id: "123", body: "comment body" }];
const comments = { id: "123", body: "comment body" };
const slug = "how-to-train-your-drago-lkdw66uc4h";
const commentId = "3885730kjdjfkskd";

describe("comments actions", () => {
describe("actions creates", () => {
test("should dispatch setComments actions", () => {
const comment = [{ id: "123", body: "comment body" }];
const expectedAction = {
type: FETCHING_COMMENTS,
comments
type: "FETCHING_COMMENTS",
comments: { "123": { id: "123", body: "comment body" } }
};
expect(setComments(comments)).toEqual(expectedAction);
expect(setComments(comment)).toEqual(expectedAction);
});

test("should dispatch setSuccessMessage actions", () => {
Expand Down Expand Up @@ -65,31 +69,42 @@ describe("comments actions", () => {

describe("fetchComments()", () => {
test("should fetch all comments", () => {
moxios.stubRequest(`${API_URL}/articles/${slug}/comments?page=1`, {
status: 200,
response: {
article: comments
const expectedAction = [
{ type: SET_LOADING_COMMENTS },
{ type: FETCHING_COMMENTS, comments: {} }
];
moxios.stubRequest(
`${API_URL}/articles/${slug}/comments?pageNumber=1`,
{
status: 200,
response: {
article: comments
}
}
});
);
return store.dispatch(fetchComments(slug, 1)).then(() => {
const actions = store.getActions();
expect(actions[0].type).toEqual("FETCHING_COMMENTS");
expect(actions).toEqual(expectedAction);
});
});

test("should throw error on fetching", () => {
const expectedActions = [
{ type: SET_LOADING_COMMENTS },
{
type: SET_ERROR_MESSAGE,
payload: "There is no article with that slug"
}
];
moxios.stubRequest(`${API_URL}/articles/${slug}/comments?page=1`, {
status: 404,
response: {
message: "There is no article with that slug"
moxios.stubRequest(
`${API_URL}/articles/${slug}/comments?pageNumber=1`,
{
status: 404,
response: {
message: "There is no article with that slug"
}
}
});
);
return store.dispatch(fetchComments(slug, 1)).then(() => {
const actions = store.getActions();
expect(actions).toEqual(expectedActions);
Expand All @@ -100,19 +115,15 @@ describe("comments actions", () => {
describe("createComment()", () => {
test("should create a new comment", () => {
const expectedActions = [
{
type: SET_SUCCESS_MESSAGE,
payload: "Comments created"
},
{
type: COMMENTS_INPUT,
payload: { field: "body", value: "" }
}
{ type: SET_SUCCESS_MESSAGE, payload: "Comments created" },
{ type: COMMENTS_INPUT, payload: { field: "body", value: "" } },
{ type: CREATE_NEW_COMMENT, payload: "article" }
];
moxios.stubRequest(`${API_URL}/articles/${slug}/comments`, {
status: 201,
response: {
message: "Comments created"
message: "Comments created",
comment: "article"
}
});
return store.dispatch(createComment("New article", slug)).then(() => {
Expand Down Expand Up @@ -140,10 +151,8 @@ describe("comments actions", () => {
describe("deleteComment()", () => {
test("should delete comment successfully", () => {
const expectedActions = [
{
type: SET_SUCCESS_MESSAGE,
payload: "Comment deleted"
}
{ payload: "Comment deleted", type: "SET_SUCCESS_MESSAGE" },
{ payload: "3885730kjdjfkskd", type: " DELETE_COMMENT" }
];
moxios.stubRequest(
`${API_URL}/articles/${slug}/comments/${commentId}`,
Expand Down Expand Up @@ -183,9 +192,10 @@ describe("comments actions", () => {
describe("updateComment()", () => {
test("should update comment successfully", () => {
const expectedActions = [
{ payload: "Comment updated", type: "SET_SUCCESS_MESSAGE" },
{
type: SET_SUCCESS_MESSAGE,
payload: "Comment updated"
payload: { body: "new comment", commentId: "3885730kjdjfkskd" },
type: "UPDATE_COMMENT"
}
];
moxios.stubRequest(
Expand Down
184 changes: 0 additions & 184 deletions src/__tests__/__components__/Dialogues/DeleteDialogue.test.js

This file was deleted.

3 changes: 2 additions & 1 deletion src/__tests__/__reducers__/commentsReducer.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ const initialState = {
bodyEdit: "",
success: "",
error: "",
comments: {}
comments: {},
isLoading: false
};

describe("team reducer", () => {
Expand Down

0 comments on commit 9bc7c09

Please sign in to comment.