Skip to content

Commit 19b1962

Browse files
committed
addressed minor PR comments, added test to eightFunction for conflicting variable names, corrected weightFucntion expected results
1 parent 25ea00b commit 19b1962

File tree

2 files changed

+16
-10
lines changed

2 files changed

+16
-10
lines changed

test/analysis/typeComplexityAnalysis.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ const typeWeights: TypeWeightObject = {
137137
id: 0,
138138
name: 0,
139139
homePlanet: 0,
140-
appearsIn: jest.fn(), // FIXME: resolves to an unbounded list of enums. We aren't handling this yet
140+
appearsIn: 0,
141141
friends: mockHumanFriendsFunction,
142142
},
143143
},
@@ -147,7 +147,7 @@ const typeWeights: TypeWeightObject = {
147147
fields: {
148148
id: 0,
149149
name: 0,
150-
appearsIn: jest.fn(), // FIXME: resolves to an unbounded list of enums. We aren't handling this yet
150+
appearsIn: 0,
151151
friends: mockDroidFriendsFunction,
152152
},
153153
},
@@ -290,12 +290,12 @@ describe('Test getQueryTypeComplexity function', () => {
290290
variables = { first: 4 };
291291
mockWeightFunction.mockReturnValueOnce(4);
292292
query = `query queryVariables($first: Int) {reviews(episode: EMPIRE, first: $first) { stars, commentary } }`;
293-
expect(getQueryTypeComplexity(parse(query), variables, typeWeights)).toBe(5); // 1 Query + 3 reviews
293+
expect(getQueryTypeComplexity(parse(query), variables, typeWeights)).toBe(5); // 1 Query + 4 reviews
294294
expect(mockWeightFunction.mock.calls.length).toBe(2);
295295
expect(mockWeightFunction.mock.calls[1].length).toBe(1);
296296
});
297297

298-
xdescribe('with nested lists', () => {
298+
describe('with nested lists', () => {
299299
test('and simple nesting', () => {
300300
query = `
301301
query {
@@ -310,7 +310,7 @@ describe('Test getQueryTypeComplexity function', () => {
310310
}
311311
}`;
312312
mockHumanFriendsFunction.mockReturnValueOnce(5).mockReturnValueOnce(3);
313-
expect(getQueryTypeComplexity(parse(query), variables, typeWeights)).toBe(17); // 1 Query + 1 human/character + (5 friends/character X 3 friends/characters)
313+
expect(getQueryTypeComplexity(parse(query), {}, typeWeights)).toBe(17); // 1 Query + 1 human/character + (5 friends/character X 3 friends/characters)
314314
expect(mockHumanFriendsFunction.mock.calls.length).toBe(2);
315315
});
316316

test/analysis/weightFunction.test.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ describe('Weight Function correctly parses Argument Nodes if', () => {
4040
xtest('and a value is not provided with the query', () => {
4141
const query = `query { reviews(episode: NEWHOPE) { stars, episode } }`;
4242
const queryAST: DocumentNode = parse(query);
43-
expect(getQueryTypeComplexity(queryAST, {}, typeWeights)).toBe(5);
43+
expect(getQueryTypeComplexity(queryAST, {}, typeWeights)).toBe(6);
4444
});
4545

4646
test('and a scalar value is provided with the query', () => {
@@ -52,8 +52,8 @@ describe('Weight Function correctly parses Argument Nodes if', () => {
5252
xtest('and the argument is passed in as a variable', () => {
5353
const query = `query variableQuery ($items: Int){ reviews(episode: NEWHOPE, first: $items) { stars, episode } }`;
5454
const queryAST: DocumentNode = parse(query);
55-
expect(getQueryTypeComplexity(queryAST, { items: 7, first: 4 }, typeWeights)).toBe(8);
56-
expect(getQueryTypeComplexity(queryAST, { first: 4, items: 7 }, typeWeights)).toBe(8);
55+
expect(getQueryTypeComplexity(queryAST, { items: 7, first: 4 }, typeWeights)).toBe(9);
56+
expect(getQueryTypeComplexity(queryAST, { first: 4, items: 7 }, typeWeights)).toBe(9);
5757
});
5858
});
5959

@@ -74,7 +74,7 @@ describe('Weight Function correctly parses Argument Nodes if', () => {
7474
xtest('and the argument is passed in as a variable', () => {
7575
const query = `query variableQuery ($items: Int){ heroes(episode: NEWHOPE, first: $items) { stars, episode } }`;
7676
const queryAST: DocumentNode = parse(query);
77-
expect(getQueryTypeComplexity(queryAST, { items: 7 }, typeWeights)).toBe(8);
77+
expect(getQueryTypeComplexity(queryAST, { items: 7 }, typeWeights)).toBe(9);
7878
});
7979
});
8080

@@ -84,7 +84,13 @@ describe('Weight Function correctly parses Argument Nodes if', () => {
8484
});
8585
const query = `query { heroes(episode: NEWHOPE, first: 3) { stars, episode } }`;
8686
const queryAST: DocumentNode = parse(query);
87-
expect(getQueryTypeComplexity(queryAST, {}, customTypeWeights)).toBe(10);
87+
expect(getQueryTypeComplexity(queryAST, {}, customTypeWeights)).toBe(5);
88+
});
89+
90+
test('variable names matching limiting keywords do not interfere with scalar argument values', () => {
91+
const query = `query variableQuery ($items: Int){ heroes(episode: NEWHOPE, first: 3) { stars, episode } }`;
92+
const queryAST: DocumentNode = parse(query);
93+
expect(getQueryTypeComplexity(queryAST, { first: 7 }, typeWeights)).toBe(5);
8894
});
8995

9096
xtest('an invalid arg type is provided', () => {

0 commit comments

Comments
 (0)