Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "Ajax: Send method override" #2271

Merged
merged 1 commit into from
Mar 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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