mirror of
https://github.com/wassname/talk.git
synced 2026-08-11 11:27:10 +08:00
Narrow down arguments in stub
This commit is contained in:
@@ -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),
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user