Skip to content
This repository has been archived by the owner on Nov 11, 2023. It is now read-only.

Commit

Permalink
Fix Delete composition
Browse files Browse the repository at this point in the history
  • Loading branch information
fabien0102 committed Nov 7, 2018
1 parent ef00272 commit 81644b1
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 25 deletions.
6 changes: 3 additions & 3 deletions src/Mutate.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ describe("Mutate", () => {
expect(children.mock.calls[2][1].loading).toEqual(false);
});

it("should call the correct url with a specific id (with base in Mutate)", async () => {
nock("https://my-awesome-api.fake")
it("should call the correct url with a specific id (with base and path in Mutate)", async () => {
nock("https://my-awesome-api.fake/user")
.delete("/plop")
.reply(200, { id: 1 });

Expand All @@ -89,7 +89,7 @@ describe("Mutate", () => {
// setup - first render
render(
<RestfulProvider base="https://my-awesome-api.fake">
<Mutate verb="DELETE" path="user">
<Mutate verb="DELETE" base="https://my-awesome-api.fake" path="user">
{children}
</Mutate>
</RestfulProvider>,
Expand Down
6 changes: 3 additions & 3 deletions src/Mutate.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as React from "react";
import RestfulReactProvider, { InjectedProps, RestfulReactConsumer, RestfulReactProviderProps } from "./Context";
import { GetState } from "./Get";
import { composePath, composePathWithBody, composeUrl } from "./util/composeUrl";
import { composePath, composeUrl } from "./util/composeUrl";
import { processResponse } from "./util/processResponse";

/**
Expand Down Expand Up @@ -145,11 +145,11 @@ class ContextlessMutate<TData, TError> extends React.Component<
const makeRequestPath = () => {
if (__internal_hasExplicitBase) {
return verb === "DELETE" && typeof body === "string"
? composeUrl(base!, "", composePathWithBody(path!, body))
? composeUrl(base!, "", composePath(path!, body))
: composeUrl(base!, "", path || "");
} else {
return verb === "DELETE" && typeof body === "string"
? composeUrl(base!, parentPath!, composePathWithBody(path!, body))
? composeUrl(base!, parentPath!, composePath(path!, body))
: composeUrl(base!, parentPath!, path!);
}
};
Expand Down
18 changes: 1 addition & 17 deletions src/util/composeUrl.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { composePath, composePathWithBody, composeUrl } from "./composeUrl";
import { composePath, composeUrl } from "./composeUrl";

describe("compose paths and urls", () => {
it("should handle empty parentPath with absolute path", () => {
Expand Down Expand Up @@ -75,19 +75,3 @@ describe("compose paths and urls", () => {
);
});
});

describe("compose path with body", () => {
it("should compose body with absolute path", () => {
const path = "/absolute";
const body = "?somebody";

expect(composePathWithBody(path, body)).toBe("/absolute?somebody");
});

it("should compose body with relative path", () => {
const path = "relative";
const body = "?somebody";

expect(composePathWithBody(path, body)).toBe("relative?somebody");
});
});
2 changes: 0 additions & 2 deletions src/util/composeUrl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,3 @@ export const composePath = (parentPath: string = "", path: string = ""): string
return parentPath;
}
};

export const composePathWithBody = (path: string, body: string): string => url.resolve(path, body);

0 comments on commit 81644b1

Please sign in to comment.