Skip to content

Commit

Permalink
Merge pull request #122 from tlconnor/fixAcceptHeader
Browse files Browse the repository at this point in the history
Default Accept and Content-Type headers to application/vnd.api+json
  • Loading branch information
wadetandy authored Nov 30, 2018
2 parents 2196041 + 1d0af3c commit d854bab
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
6 changes: 3 additions & 3 deletions src/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -671,8 +671,8 @@ export class JSORMBase {
static fetchOptions(): RequestInit {
const options = {
headers: {
Accept: "application/json",
["Content-Type"]: "application/json"
Accept: "application/vnd.api+json",
["Content-Type"]: "application/vnd.api+json"
} as any
}

Expand Down Expand Up @@ -941,4 +941,4 @@ export const isModelInstance = (arg: any): arg is JSORMBase => {
return false
}
return isModelClass(arg.constructor.currentClass)
}
}
8 changes: 4 additions & 4 deletions test/integration/fetch-middleware.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,8 @@ describe("fetch middleware", () => {
expect(before.url).to.eq("http://example.com/api/v1/authors")
expect(before.options).to.deep.eq({
headers: {
Accept: "application/json",
"Content-Type": "application/json",
Accept: "application/vnd.api+json",
"Content-Type": "application/vnd.api+json",
"CUSTOM-HEADER": "whatever"
},
method: "GET"
Expand Down Expand Up @@ -309,9 +309,9 @@ describe("fetch middleware", () => {
expect(before.url).to.eq("http://example.com/api/v1/authors")
expect(before.options).to.deep.eq({
headers: {
Accept: "application/json",
Accept: "application/vnd.api+json",
"CUSTOM-HEADER": "whatever",
"Content-Type": "application/json"
"Content-Type": "application/vnd.api+json"
},
body: JSON.stringify({ data: { type: "authors" } }),
method: "POST"
Expand Down
4 changes: 2 additions & 2 deletions test/unit/model.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1485,8 +1485,8 @@ describe("Model", () => {

it("includes the content headers", () => {
const headers: any = Author.fetchOptions().headers
expect(headers.Accept).to.eq("application/json")
expect(headers["Content-Type"]).to.eq("application/json")
expect(headers.Accept).to.eq("application/vnd.api+json")
expect(headers["Content-Type"]).to.eq("application/vnd.api+json")
})
})
})

0 comments on commit d854bab

Please sign in to comment.