Narrow down arguments in stub

This commit is contained in:
Chi Vinh Le
2018-07-09 20:55:36 -03:00
parent 11de453aac
commit a18a9ab0c4
4 changed files with 92 additions and 69 deletions
+41 -35
View File
@@ -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),
},
};
@@ -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),
},
};
@@ -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]),
},
};
@@ -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),
},
};