diff --git a/src/core/client/stream/test/loadMore.spec.tsx b/src/core/client/stream/test/loadMore.spec.tsx index 2ff3d5a87..0971e899e 100644 --- a/src/core/client/stream/test/loadMore.spec.tsx +++ b/src/core/client/stream/test/loadMore.spec.tsx @@ -10,47 +10,53 @@ import AppQuery from "talk-stream/queries/AppQuery"; import createEnvironment from "./createEnvironment"; import { assets, comments } from "./fixtures"; +const connectionStub = sinon.stub(); +connectionStub.withArgs({ first: 5, orderBy: "CREATED_AT_DESC" }).returns({ + edges: [ + { + node: comments[0], + cursor: comments[0].createdAt, + }, + { + node: comments[1], + cursor: comments[1].createdAt, + }, + ], + pageInfo: { + endCursor: comments[1].createdAt, + hasNextPage: true, + }, +}); +connectionStub + .withArgs({ + first: 10, + orderBy: "CREATED_AT_DESC", + after: comments[1].createdAt, + }) + .returns({ + edges: [ + { + node: comments[2], + cursor: comments[2].createdAt, + }, + ], + pageInfo: { + endCursor: comments[2].createdAt, + hasNextPage: false, + }, + }); + const assetStub = { ...assets[0], - comments: { - edges: sinon - .stub() - .onFirstCall() - .returns([ - { - node: comments[0], - cursor: comments[0].createdAt, - }, - { - node: comments[1], - cursor: comments[1].createdAt, - }, - ]) - .onSecondCall() - .returns([ - { - node: comments[2], - cursor: comments[2].createdAt, - }, - ]), - pageInfo: sinon - .stub() - .onFirstCall() - .returns({ - endCursor: comments[1].createdAt, - hasNextPage: true, - }) - .onSecondCall() - .returns({ - endCursor: comments[2].createdAt, - hasNextPage: false, - }), - }, + comments: connectionStub, }; const resolvers = { Query: { - asset: () => assetStub, + asset: sinon + .stub() + .withArgs(undefined, { id: assetStub.id }) + .returns(assetStub), }, }; diff --git a/src/core/client/stream/test/renderReplies.spec.tsx b/src/core/client/stream/test/renderReplies.spec.tsx index 359c2465d..b1d6b43c2 100644 --- a/src/core/client/stream/test/renderReplies.spec.tsx +++ b/src/core/client/stream/test/renderReplies.spec.tsx @@ -1,6 +1,7 @@ import React from "react"; import TestRenderer from "react-test-renderer"; import { RecordProxy } from "relay-runtime"; +import sinon from "sinon"; import { timeout } from "talk-common/utils"; import { TalkContext, TalkContextProvider } from "talk-framework/lib/bootstrap"; @@ -11,7 +12,10 @@ import { assetWithReplies } from "./fixtures"; const resolvers = { Query: { - asset: () => assetWithReplies, + asset: sinon + .stub() + .withArgs(undefined, { id: assetWithReplies.id }) + .returns(assetWithReplies), }, }; diff --git a/src/core/client/stream/test/renderStream.spec.tsx b/src/core/client/stream/test/renderStream.spec.tsx index d30e32d51..c5027bd7f 100644 --- a/src/core/client/stream/test/renderStream.spec.tsx +++ b/src/core/client/stream/test/renderStream.spec.tsx @@ -1,6 +1,7 @@ import React from "react"; import TestRenderer from "react-test-renderer"; import { RecordProxy } from "relay-runtime"; +import sinon from "sinon"; import { timeout } from "talk-common/utils"; import { TalkContext, TalkContextProvider } from "talk-framework/lib/bootstrap"; @@ -11,7 +12,10 @@ import { assets } from "./fixtures"; const resolvers = { Query: { - asset: () => assets[0], + asset: sinon + .stub() + .withArgs(undefined, { id: assets[0].id }) + .returns(assets[0]), }, }; diff --git a/src/core/client/stream/test/showAllReplies.spec.tsx b/src/core/client/stream/test/showAllReplies.spec.tsx index df7ac1ebb..665679b76 100644 --- a/src/core/client/stream/test/showAllReplies.spec.tsx +++ b/src/core/client/stream/test/showAllReplies.spec.tsx @@ -10,38 +10,41 @@ import AppQuery from "talk-stream/queries/AppQuery"; import createEnvironment from "./createEnvironment"; import { assets, comments } from "./fixtures"; +const connectionStub = sinon.stub(); +connectionStub.withArgs({ first: 5, orderBy: "CREATED_AT_ASC" }).returns({ + edges: [ + { + node: comments[1], + cursor: comments[1].createdAt, + }, + ], + pageInfo: { + endCursor: comments[1].createdAt, + hasNextPage: true, + }, +}); +connectionStub + .withArgs({ + first: sinon.match(n => n > 10000), + orderBy: "CREATED_AT_ASC", + after: comments[1].createdAt, + }) + .returns({ + edges: [ + { + node: comments[2], + cursor: comments[2].createdAt, + }, + ], + pageInfo: { + endCursor: comments[2].createdAt, + hasNextPage: false, + }, + }); + const commentStub = { ...comments[0], - replies: { - edges: sinon - .stub() - .onFirstCall() - .returns([ - { - node: comments[1], - cursor: comments[1].createdAt, - }, - ]) - .onSecondCall() - .returns([ - { - node: comments[2], - cursor: comments[2].createdAt, - }, - ]), - pageInfo: sinon - .stub() - .onFirstCall() - .returns({ - endCursor: comments[1].createdAt, - hasNextPage: true, - }) - .onSecondCall() - .returns({ - endCursor: comments[2].createdAt, - hasNextPage: false, - }), - }, + replies: connectionStub, }; const assetStub = { @@ -61,8 +64,14 @@ const assetStub = { const resolvers = { Query: { - comment: () => commentStub, - asset: () => assetStub, + comment: sinon + .stub() + .withArgs(undefined, { id: commentStub.id }) + .returns(commentStub), + asset: sinon + .stub() + .withArgs(undefined, { id: assetStub.id }) + .returns(assetStub), }, };