Skip to content

Commit

Permalink
Adds a user agent to the metaphysics fetch
Browse files Browse the repository at this point in the history
  • Loading branch information
orta committed Feb 20, 2018
1 parent cf72963 commit b855c04
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
22 changes: 22 additions & 0 deletions src/Utils/__test__/metaphysics.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
jest.mock("isomorphic-fetch")
import metaphysics from "../metaphysics"

declare const global: any
global.fetch = jest.fn(() =>
Promise.resolve({
status: 200,
json: () => Promise.resolve({ data: {} }),
})
)

it("Adds a user agent for reaction", () => {
expect.assertions(1)

return metaphysics("query {}").then(() => {
expect(global.fetch).toBeCalledWith(undefined, {
body: '{"query":"query {}"}',
headers: { "Content-Type": "application/json", "User-Agent": "Reaction" },
method: "POST",
})
})
})
8 changes: 6 additions & 2 deletions src/Utils/metaphysics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,19 @@ export function metaphysics<T>(
user?: User,
checkStatus: boolean = true
): Promise<T> {
const headers = {
"Content-Type": "application/json",
"User-Agent": "Reaction",
}
return fetch(sharify.data.METAPHYSICS_ENDPOINT, {
method: "POST",
headers: !!user
? {
"Content-Type": "application/json",
...headers,
"X-USER-ID": user && user.id,
"X-ACCESS-TOKEN": user && user.accessToken,
}
: { "Content-Type": "application/json" },
: headers,
body: JSON.stringify(payload),
})
.then(response => {
Expand Down

0 comments on commit b855c04

Please sign in to comment.