Skip to content

Commit

Permalink
Removed tests because irrelevant
Browse files Browse the repository at this point in the history
  • Loading branch information
alexstrat committed Jan 19, 2021
1 parent d0aafd4 commit 3081c0f
Showing 1 changed file with 0 additions and 129 deletions.
129 changes: 0 additions & 129 deletions packages/mock/tests/mocking-compatibility.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1116,26 +1116,6 @@ describe('Mock retro-compatibility', () => {
});
});

test('lets you mock a list of specific variable length', () => {
let jsSchema = buildSchemaFromTypeDefinitions(shorthand);
const mockMap = {
RootQuery: () => ({
returnListOfIntArg: (a: Record<string, any>) =>
new MockList(a.l),
}),
Int: () => 12,
};
jsSchema = addMocksToSchema({ schema: jsSchema, mocks: mockMap });
const testQuery = `{
l3: returnListOfIntArg(l: 3)
l5: returnListOfIntArg(l: 5)
}`;
return graphql(jsSchema, testQuery).then((res) => {
expect(res.data.l3.length).toBe(3);
expect(res.data.l5.length).toBe(5);
});
});

test('lets you provide a function for your MockList', () => {
let jsSchema = buildSchemaFromTypeDefinitions(shorthand);
const mockMap = {
Expand Down Expand Up @@ -1188,115 +1168,6 @@ describe('Mock retro-compatibility', () => {
});
});

test('lets you use arguments in nested MockList', () => {
let jsSchema = buildSchemaFromTypeDefinitions(shorthand);
const mockMap = {
RootQuery: () => ({
returnListOfListOfIntArg: () =>
new MockList(
2,
(_o: any, a: Record<string, any>) => new MockList(a.l),
),
}),
Int: () => 12,
};
jsSchema = addMocksToSchema({ schema: jsSchema, mocks: mockMap });
const testQuery = `{
returnListOfListOfIntArg(l: 1)
}`;
const expected = {
returnListOfListOfIntArg: [[12], [12]],
};
return graphql(jsSchema, testQuery).then((res) => {
expect(res.data).toEqual(expected);
});
});

test('works for a slightly more elaborate example', () => {
const short = `
type Thread {
id: ID!
name: String!
posts(page: Int = 0, num: Int = 1): [Post]
}
type Post {
id: ID!
user: User!
text: String!
}
type User {
id: ID!
name: String
}
type RootQuery {
thread(id: ID): Thread
threads(page: Int = 0, num: Int = 1): [Thread]
}
schema {
query: RootQuery
}
`;
let jsSchema = buildSchemaFromTypeDefinitions(short);
const ITEMS_PER_PAGE = 2;
// This mock map demonstrates default merging on objects and nested lists.
// thread on root query will have id a.id, and missing properties
// come from the Thread mock type
// TODO: this tests too many things at once, it should really be broken up
// it was really useful to have this though, because it made me find many
// unintuitive corner-cases
const mockMap = {
RootQuery: () => ({
thread: (a: Record<string, any>) => ({ id: a.id }),
threads: (a: Record<string, any>) =>
new MockList(ITEMS_PER_PAGE * a.num),
}),
Thread: () => ({
name: 'Lorem Ipsum',
posts: (a: Record<string, any>) =>
new MockList(
ITEMS_PER_PAGE * a.num,
(_oi: any, ai: Record<string, any>) => ({
id: ai.num,
}),
),
}),
Post: () => ({
id: '41ae7bd',
text: 'superlongpost',
}),
Int: () => 123,
};
jsSchema = addMocksToSchema({ schema: jsSchema, mocks: mockMap });
const testQuery = `query abc{
thread(id: "67"){
id
name
posts(num: 2){
id
text
}
}
}`;
const expected = {
thread: {
id: '67',
name: 'Lorem Ipsum',
posts: [
{ id: '2', text: 'superlongpost' },
{ id: '2', text: 'superlongpost' },
{ id: '2', text: 'superlongpost' },
{ id: '2', text: 'superlongpost' },
],
},
};
return graphql(jsSchema, testQuery).then((res) => {
expect(res.data).toEqual(expected);
});
});

test('works for resolvers returning javascript Dates', () => {
const typeDefs = `
scalar Date
Expand Down

0 comments on commit 3081c0f

Please sign in to comment.