Skip to content

Commit 4d162bf

Browse files
committed
added tests for mutations and started looking at tests for connections
1 parent f320dac commit 4d162bf

File tree

2 files changed

+37
-4
lines changed

2 files changed

+37
-4
lines changed

test/analysis/buildTypeWeights.test.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -314,8 +314,8 @@ describe('Test buildTypeWeightsFromSchema function', () => {
314314
type Character {
315315
id: ID!
316316
name: String!
317-
friends(first:Int after: String): [Character]
318-
friendsConnection (first: Int): FriendsConnection
317+
friends(first: Int): [Character]
318+
friendsConnection(first: Int, after: ID): FriendsConnection!
319319
}
320320
type FriendsConnection {
321321
totalCount: Int
@@ -345,7 +345,8 @@ describe('Test buildTypeWeightsFromSchema function', () => {
345345
fields: {
346346
id: { weight: 0 },
347347
name: { weight: 0 },
348-
friends: { resolveTo: 'friendsConnection' },
348+
friends: { resolveTo: 'character', weight: expect.any(Function) },
349+
friendsConnection: { resolveTo: 'friendsConnection' },
349350
},
350351
},
351352
friendsConnection: {

test/analysis/typeComplexityAnalysis.test.ts

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ import { TypeWeightObject, Variables } from '../../src/@types/buildTypeWeights';
7878
stars: Int!
7979
commentary: String
8080
}
81+
82+
8183
8284
*
8385
* TODO: extend this schema to include mutations, subscriptions and pagination
@@ -86,7 +88,8 @@ import { TypeWeightObject, Variables } from '../../src/@types/buildTypeWeights';
8688
type Subscription {
8789
reviewAdded(episode: Episode): Review
8890
}
89-
type FriendsConnection {
91+
92+
type FriendsConnection {
9093
totalCount: Int
9194
edges: [FriendsEdge]
9295
friends: [Character]
@@ -918,6 +921,9 @@ describe('Test getQueryTypeComplexity function', () => {
918921
expect(getQueryTypeComplexity(parse(query), variables, typeWeights)).toBe(5); // 1 Query + 4 search results
919922
});
920923

924+
// TODO: create tests for an implementation of the connection pagination convention -- need soln for unbounded lists
925+
xdescribe('connection pagination convention', () => {});
926+
921927
// TODO: directives @skip, @include and custom directives
922928
});
923929

@@ -933,6 +939,32 @@ describe('Test getQueryTypeComplexity function', () => {
933939
}`;
934940
expect(getQueryTypeComplexity(parse(query), variables, typeWeights)).toBe(11); // Mutation 10 + review 1
935941
});
942+
943+
test('mutation with no feilds queried', () => {
944+
variables = { review: { stars: 5, commentary: 'good' } };
945+
query = `mutation createReviewMutation($review: ReviewInput!) {
946+
createReview(episode: Empire, review: $review)
947+
}`;
948+
expect(getQueryTypeComplexity(parse(query), variables, typeWeights)).toBe(11); // Mutation 10 + review 1
949+
});
950+
951+
test('mutation and query definitons', () => {
952+
variables = { review: { stars: 5, commentary: 'good' } };
953+
query = `mutation createReviewMutation($review: ReviewInput!) {
954+
createReview(episode: Empire, review: $review) {
955+
stars
956+
commentary
957+
episode
958+
}
959+
}
960+
961+
query {
962+
hero(episode: EMPIRE) {
963+
name
964+
}
965+
}`;
966+
expect(getQueryTypeComplexity(parse(query), variables, typeWeights)).toBe(13); // Mutation 10 + review 1 + query 1 + character 1
967+
});
936968
});
937969

938970
xdescribe('Calculates the correct type complexity for subscriptions', () => {});

0 commit comments

Comments
 (0)