Extracted commonly used URL in groups.test.js to constant

This commit is contained in:
Philipp Czora
2018-11-06 13:19:56 +01:00
parent d00c487f36
commit 3d604fc833

View File

@@ -47,6 +47,7 @@ import reducer, {
getCreateGroupLink getCreateGroupLink
} from "./groups"; } from "./groups";
const GROUPS_URL = "/api/v2/groups"; const GROUPS_URL = "/api/v2/groups";
const URL_HUMAN_GROUP = "http://localhost:8081/api/v2/groups/humanGroup";
const URL = "/groups"; const URL = "/groups";
const error = new Error("You have an error!"); const error = new Error("You have an error!");
@@ -60,13 +61,13 @@ const humanGroup = {
members: ["userZaphod"], members: ["userZaphod"],
_links: { _links: {
self: { self: {
href: "http://localhost:8081/api/v2/groups/humanGroup" href: URL_HUMAN_GROUP
}, },
delete: { delete: {
href: "http://localhost:8081/api/v2/groups/humanGroup" href: URL_HUMAN_GROUP
}, },
update: { update: {
href: "http://localhost:8081/api/v2/groups/humanGroup" href: URL_HUMAN_GROUP
} }
}, },
_embedded: { _embedded: {
@@ -199,10 +200,7 @@ describe("groups fetch()", () => {
}); });
it("should sucessfully fetch single group", () => { it("should sucessfully fetch single group", () => {
fetchMock.getOnce( fetchMock.getOnce(URL_HUMAN_GROUP, humanGroup);
"http://localhost:8081/api/v2/groups/humanGroup",
humanGroup
);
const store = mockStore({}); const store = mockStore({});
return store.dispatch(fetchGroupByLink(humanGroup)).then(() => { return store.dispatch(fetchGroupByLink(humanGroup)).then(() => {
@@ -214,7 +212,7 @@ describe("groups fetch()", () => {
}); });
it("should fail fetching single group on HTTP 500", () => { it("should fail fetching single group on HTTP 500", () => {
fetchMock.getOnce("http://localhost:8081/api/v2/groups/humanGroup", { fetchMock.getOnce(URL_HUMAN_GROUP, {
status: 500 status: 500
}); });
@@ -274,13 +272,10 @@ describe("groups fetch()", () => {
}); });
it("should successfully modify group", () => { it("should successfully modify group", () => {
fetchMock.putOnce("http://localhost:8081/api/v2/groups/humanGroup", { fetchMock.putOnce(URL_HUMAN_GROUP, {
status: 204 status: 204
}); });
fetchMock.getOnce( fetchMock.getOnce(URL_HUMAN_GROUP, humanGroup);
"http://localhost:8081/api/v2/groups/humanGroup",
humanGroup
);
const store = mockStore({}); const store = mockStore({});
@@ -294,13 +289,10 @@ describe("groups fetch()", () => {
}); });
it("should call the callback after modifying group", () => { it("should call the callback after modifying group", () => {
fetchMock.putOnce("http://localhost:8081/api/v2/groups/humanGroup", { fetchMock.putOnce(URL_HUMAN_GROUP, {
status: 204 status: 204
}); });
fetchMock.getOnce( fetchMock.getOnce(URL_HUMAN_GROUP, humanGroup);
"http://localhost:8081/api/v2/groups/humanGroup",
humanGroup
);
let called = false; let called = false;
const callback = () => { const callback = () => {
@@ -318,7 +310,7 @@ describe("groups fetch()", () => {
}); });
it("should fail modifying group on HTTP 500", () => { it("should fail modifying group on HTTP 500", () => {
fetchMock.putOnce("http://localhost:8081/api/v2/groups/humanGroup", { fetchMock.putOnce(URL_HUMAN_GROUP, {
status: 500 status: 500
}); });
@@ -333,7 +325,7 @@ describe("groups fetch()", () => {
}); });
it("should delete successfully group humanGroup", () => { it("should delete successfully group humanGroup", () => {
fetchMock.deleteOnce("http://localhost:8081/api/v2/groups/humanGroup", { fetchMock.deleteOnce(URL_HUMAN_GROUP, {
status: 204 status: 204
}); });
@@ -348,7 +340,7 @@ describe("groups fetch()", () => {
}); });
it("should call the callback, after successful delete", () => { it("should call the callback, after successful delete", () => {
fetchMock.deleteOnce("http://localhost:8081/api/v2/groups/humanGroup", { fetchMock.deleteOnce(URL_HUMAN_GROUP, {
status: 204 status: 204
}); });
@@ -364,7 +356,7 @@ describe("groups fetch()", () => {
}); });
it("should fail to delete group humanGroup", () => { it("should fail to delete group humanGroup", () => {
fetchMock.deleteOnce("http://localhost:8081/api/v2/groups/humanGroup", { fetchMock.deleteOnce(URL_HUMAN_GROUP, {
status: 500 status: 500
}); });