Skip to content

Commit

Permalink
Revert "Ajax: Send method override"
Browse files Browse the repository at this point in the history
This reverts commit f183a5e.
  • Loading branch information
tvdeyen committed Mar 24, 2022
1 parent 47736ed commit 0a832c4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 17 deletions.
20 changes: 5 additions & 15 deletions package/src/utils/__tests__/ajax.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,15 +95,15 @@ describe("get", () => {

describe("patch", () => {
it("sends X-CSRF-TOKEN header", async () => {
xhrMock.post("http://localhost/users", (req, res) => {
xhrMock.patch("http://localhost/users", (req, res) => {
expect(req.header("X-CSRF-TOKEN")).toEqual(token)
return res.status(200).body('{"message":"Ok"}')
})
await patch("/users")
})

it("sends Content-Type header", async () => {
xhrMock.post("http://localhost/users", (req, res) => {
xhrMock.patch("http://localhost/users", (req, res) => {
expect(req.header("Content-Type")).toEqual(
"application/json; charset=utf-8"
)
Expand All @@ -113,26 +113,16 @@ describe("patch", () => {
})

it("sends Accept header", async () => {
xhrMock.post("http://localhost/users", (req, res) => {
xhrMock.patch("http://localhost/users", (req, res) => {
expect(req.header("Accept")).toEqual("application/json")
return res.status(200).body('{"message":"Ok"}')
})
await patch("/users")
})

it("sends method override data", async () => {
xhrMock.post("http://localhost/users", (req, res) => {
expect(req.body()).toEqual('{"_method":"patch"}')
return res.status(200).body('{"message":"Ok"}')
})
await patch("/users")
})

it("sends JSON data", async () => {
xhrMock.post("http://localhost/users", (req, res) => {
expect(req.body()).toEqual(
'{"email":"mail@example.com","_method":"patch"}'
)
xhrMock.patch("http://localhost/users", (req, res) => {
expect(req.body()).toEqual('{"email":"mail@example.com"}')
return res.status(200).body('{"message":"Ok"}')
})
await patch("/users", { email: "mail@example.com" })
Expand Down
4 changes: 2 additions & 2 deletions package/src/utils/ajax.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ export function get(url, params) {
return ajax("GET", url, params)
}

export function patch(url, data = {}) {
return ajax("POST", url, { ...data, _method: "patch" })
export function patch(url, data) {
return ajax("PATCH", url, data)
}

export function post(url, data) {
Expand Down

0 comments on commit 0a832c4

Please sign in to comment.