Skip to content
This repository has been archived by the owner on Nov 15, 2017. It is now read-only.

Commit

Permalink
More tests
Browse files Browse the repository at this point in the history
  • Loading branch information
swernerx committed Jun 14, 2017
1 parent b687c43 commit 9e4e823
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 7 deletions.
13 changes: 7 additions & 6 deletions src/api/common/Apollo.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ import { ApolloClient, createNetworkInterface, createBatchingNetworkInterface }
*
*
*/
export function createApolloClient({ headers, initialState = {}, batchRequests = false, trustNetwork = true })
export function createApolloClient(config = {})
{
const { headers, initialState = {}, batchRequests = false, trustNetwork = true, queryDeduplication = true } = config
const apolloUri = initialState.ssr && initialState.ssr.apolloUri

const hasApollo = apolloUri != null
const ssrMode = process.env.TARGET === "node"
var client

if (hasApollo)
Expand Down Expand Up @@ -40,17 +42,16 @@ export function createApolloClient({ headers, initialState = {}, batchRequests =
}

client = new ApolloClient({
ssrMode: process.env.TARGET === "node",
addTypename: false,
queryDeduplication: true,
ssrMode,
queryDeduplication,
networkInterface
})
}
else
{
client = new ApolloClient({
addTypename: false,
queryDeduplication: true
ssrMode,
queryDeduplication
})
}

Expand Down
13 changes: 13 additions & 0 deletions src/api/common/Apollo.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { createApolloClient } from "./Apollo"

test("Create Apollo Client - No Data", () => {
expect(createApolloClient()).toBeDefined()
})

test("Create Apollo Client - With Initial Data", () => {
expect(createApolloClient({ initialData: {} })).toBeDefined()
})

test("Create Apollo Client - With Initial Data and URL", () => {
expect(createApolloClient({ initialData: { ssr: { apolloUri: "http://my.apollo.uri" } } })).toBeDefined()
})
33 changes: 32 additions & 1 deletion src/api/common/State.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { createReduxStore } from "./State"
import { createReduxStore, createRootReducer } from "./State"
import { createApolloClient } from "./Apollo"

test("Create Redux Store - Basic", () => {
const reducers = {}
Expand All @@ -22,3 +23,33 @@ test("Create Redux Store - Empty Param", () => {
test("Create Redux Store - No Params", () => {
expect(createReduxStore()).toBeDefined()
})

test("Create Redux Store - With Apollo", () => {
const reducers = {}
const middlewares = []
const enhancers = []
const apolloClient = createApolloClient()

expect(createReduxStore({ reducers, middlewares, enhancers, apolloClient })).toBeDefined()
})

test("Create Redux Store - With Apollo and URL", () => {
const reducers = {}
const middlewares = []
const enhancers = []
const apolloClient = createApolloClient({ initialData: { ssr: { apolloUri: "http://my.apollo.uri" } } })

expect(createReduxStore({ reducers, middlewares, enhancers, apolloClient })).toBeDefined()
})

test("Create Root Reducer", () => {
expect(createRootReducer()).toBeDefined()
})

test("Create Root Reducer with one reducer", () => {
function dummy(prevState) {
return prevState
}

expect(createRootReducer({ dummy })).toBeDefined()
})

0 comments on commit 9e4e823

Please sign in to comment.