Skip to content

Commit

Permalink
#26 Update bindings for Client.
Browse files Browse the repository at this point in the history
  • Loading branch information
parkerziegler committed Apr 6, 2019
1 parent 27653f8 commit b022e3a
Show file tree
Hide file tree
Showing 18 changed files with 188 additions and 657 deletions.
159 changes: 19 additions & 140 deletions __tests__/UrqlClient_test.re
Original file line number Diff line number Diff line change
@@ -1,29 +1,21 @@
open Jest;
open ReasonUrql;

let it = test;

describe("UrqlClient", () => {
describe("Client with only a url provided", () => {
let client = Client.make(~url="https://localhost:3000", ());

test("should instantiate a client instance", () =>
it("should instantiate a client instance", () =>
Expect.(expect(client) |> toMatchSnapshot)
);

test("should apply the provided url to urql's new Client constructor", () =>
Expect.(
expect(
Client.clientConfig(~url="https://localhost:3000", ())
->Client.urlGet,
)
|> toEqual("https://localhost:3000")
)
);

test("should expose an executeQuery operation", () =>
it("should expose an executeQuery operation", () =>
ExpectJs.(expect(Client.executeQuery) |> toBeTruthy)
);

test("should expose an executeMutation operation", () =>
it("should expose an executeMutation operation", () =>
ExpectJs.(expect(Client.executeMutation) |> toBeTruthy)
);
});
Expand All @@ -36,139 +28,26 @@ describe("UrqlClient", () => {
(),
);

let makeFetchOptions = Client.FetchObj(fetchOptions);

let client =
Client.make(
~url="https://localhost:3000",
~fetchOptions=makeFetchOptions,
(),
);

test("should instantiate a client instance with fetchOptions", () =>
Expect.(expect(client) |> toMatchSnapshot)
);

test(
"should apply the provided fetchOptions to urql's new Client constructor",
() =>
Expect.(
expect(
Client.clientConfig(
~url="https://localhost:3000",
~fetchOptions,
(),
)
->Client.fetchOptionsGet,
)
|> toEqual(
Some(
Fetch.RequestInit.make(
~method_=Post,
~headers=
Fetch.HeadersInit.make({
"Content-Type": "application/json",
}),
(),
),
),
)
)
);

test("should unwrap fetchOptions wrapped as FetchObj", () =>
Expect.(
expect(Client.unwrapFetchOptions(makeFetchOptions))
|> toEqual(fetchOptions)
)
);

test("should unwrap fetchOptions unwrapped as FetchFn", () => {
let makeFetchOptions = Client.FetchFn(() => fetchOptions);
Expect.(
expect(Client.unwrapFetchOptions(makeFetchOptions))
|> toEqual(fetchOptions)
);
});
});

describe("Client with initialCache provided", () => {
let initialCache = Js.Dict.empty();
Js.Dict.set(
initialCache,
"VmeRTX7j-",
"{ name: Dixie, likes: 1000, breed: Pit Bull }",
);

let client =
Client.make(~url="https://localhost:3000", ~initialCache, ());

test("should instantiate a client instance with initialCache", () =>
Expect.(expect(client) |> toMatchSnapshot)
);

test(
"should apply the provided initialCache to urql's new Client constructor",
() =>
Expect.(
expect(
Client.clientConfig(
~url="https://localhost:3000",
~initialCache,
(),
)
->Client.initialCacheGet,
)
|> toEqual(Some(initialCache))
)
);
});

describe("Client with cache provided", () => {
let client =
Client.make(
~url="https://localhost:3000",
~cache=TestUtils.testCache,
(),
);

test("should instantiate a client instance with cache", () =>
Expect.(expect(client) |> toMatchSnapshot)
);

test("should convert a cache record to a Js.t", () => {
let cacheJs = Client.cacheToJs(TestUtils.testCache);
ExpectJs.(
expect(cacheJs)
|> toContainProperties([|
"read",
"write",
"invalidate",
"invalidateAll",
"update",
|])
);
});

test("should expose a method to convert a cache from Js.t to record", () => {
let cache = Client.cacheFromJs(TestUtils.testCacheJs);
it(
"should instantiate a client instance with fetchOptions provided as FetchObj",
() => {
let client =
Client.make(
~url="https://localhost:3000",
~fetchOptions=Client.FetchObj(fetchOptions),
(),
);

Expect.(expect(cache) |> toEqual(TestUtils.testCache));
Expect.(expect(client) |> toMatchSnapshot);
});

test("should use an initialCache if provided", () => {
let initialCache = Js.Dict.empty();
Js.Dict.set(
initialCache,
"VmeRTX7j-",
"{ name: Dixie, likes: 1000, breed: Pit Bull }",
);

it(
"should instantiate a client instance with fetchOptions provided as FetchFn",
() => {
let client =
Client.make(
~url="https://localhost:3000",
~cache=TestUtils.testCache,
~initialCache,
~fetchOptions=Client.FetchFn(() => fetchOptions),
(),
);

Expand Down
10 changes: 0 additions & 10 deletions __tests__/UrqlProvider_test.re

This file was deleted.

118 changes: 33 additions & 85 deletions __tests__/__snapshots__/UrqlClient_test.bs.js.snap
Original file line number Diff line number Diff line change
@@ -1,64 +1,15 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`UrqlClient Client with cache provided should instantiate a client instance with cache 1`] = `
exports[`UrqlClient Client with fetchOptions provided should instantiate a client instance with fetchOptions provided as FetchFn 1`] = `
Client {
"cache": Object {
"invalidate": [Function],
"invalidateAll": [Function],
"read": [Function],
"update": [Function],
"write": [Function],
},
"executeMutation": [Function],
"executeQuery": [Function],
"fetchOptions": Object {
"integrity": "",
"referrerPolicy": "",
},
"refreshAllFromCache": [Function],
"store": Object {},
"subscriptions": Object {},
"updateSubscribers": [Function],
"url": "https://localhost:3000",
}
`;

exports[`UrqlClient Client with cache provided should use an initialCache if provided 1`] = `
Client {
"cache": Object {
"invalidate": [Function],
"invalidateAll": [Function],
"read": [Function],
"update": [Function],
"write": [Function],
},
"executeMutation": [Function],
"executeQuery": [Function],
"fetchOptions": Object {
"integrity": "",
"referrerPolicy": "",
},
"refreshAllFromCache": [Function],
"store": Object {
"VmeRTX7j-": "{ name: Dixie, likes: 1000, breed: Pit Bull }",
},
"subscriptions": Object {},
"updateSubscribers": [Function],
"url": "https://localhost:3000",
}
`;

exports[`UrqlClient Client with fetchOptions provided should instantiate a client instance with fetchOptions 1`] = `
Client {
"cache": Object {
"invalidate": [Function],
"invalidateAll": [Function],
"read": [Function],
"update": [Function],
"write": [Function],
},
"activeOperations": Object {},
"createOperationContext": [Function],
"createRequestOperation": [Function],
"dispatchOperation": [Function],
"exchange": [Function],
"executeMutation": [Function],
"executeQuery": [Function],
"executeSubscription": [Function],
"fetchOptions": Object {
"headers": Object {
"Content-Type": "application/json",
Expand All @@ -67,58 +18,55 @@ Client {
"method": "POST",
"referrerPolicy": "",
},
"refreshAllFromCache": [Function],
"store": Object {},
"subscriptions": Object {},
"updateSubscribers": [Function],
"operations$": [Function],
"reexecuteOperation": [Function],
"results$": [Function],
"url": "https://localhost:3000",
}
`;

exports[`UrqlClient Client with initialCache provided should instantiate a client instance with initialCache 1`] = `
exports[`UrqlClient Client with fetchOptions provided should instantiate a client instance with fetchOptions provided as FetchObj 1`] = `
Client {
"cache": Object {
"invalidate": [Function],
"invalidateAll": [Function],
"read": [Function],
"update": [Function],
"write": [Function],
},
"activeOperations": Object {},
"createOperationContext": [Function],
"createRequestOperation": [Function],
"dispatchOperation": [Function],
"exchange": [Function],
"executeMutation": [Function],
"executeQuery": [Function],
"executeSubscription": [Function],
"fetchOptions": Object {
"headers": Object {
"Content-Type": "application/json",
},
"integrity": "",
"method": "POST",
"referrerPolicy": "",
},
"refreshAllFromCache": [Function],
"store": Object {
"VmeRTX7j-": "{ name: Dixie, likes: 1000, breed: Pit Bull }",
},
"subscriptions": Object {},
"updateSubscribers": [Function],
"operations$": [Function],
"reexecuteOperation": [Function],
"results$": [Function],
"url": "https://localhost:3000",
}
`;

exports[`UrqlClient Client with only a url provided should instantiate a client instance 1`] = `
Client {
"cache": Object {
"invalidate": [Function],
"invalidateAll": [Function],
"read": [Function],
"update": [Function],
"write": [Function],
},
"activeOperations": Object {},
"createOperationContext": [Function],
"createRequestOperation": [Function],
"dispatchOperation": [Function],
"exchange": [Function],
"executeMutation": [Function],
"executeQuery": [Function],
"executeSubscription": [Function],
"fetchOptions": Object {
"integrity": "",
"referrerPolicy": "",
},
"refreshAllFromCache": [Function],
"store": Object {},
"subscriptions": Object {},
"updateSubscribers": [Function],
"operations$": [Function],
"reexecuteOperation": [Function],
"results$": [Function],
"url": "https://localhost:3000",
}
`;
Loading

0 comments on commit b022e3a

Please sign in to comment.