Skip to content

Commit 43e0dd2

Browse files
committed
finish writing and proof reading tests
1 parent 96ab047 commit 43e0dd2

File tree

2 files changed

+33
-6
lines changed

2 files changed

+33
-6
lines changed

jest.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */
22
module.exports = {
3-
roots: ['./src'],
3+
roots: ['./test'],
44
preset: 'ts-jest',
55
testEnvironment: 'node',
66
moduleFileExtensions: ['js', 'ts'],

test/analysis/buildTypeWeights.test.ts

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import buildTypeWeightsFromSchema from '../../src/analysis/buildTypeWeights';
55
describe('Test buildTypeWeightsFromSchema function', () => {
66
let schema: GraphQLSchema;
77

8+
// this is dependant on the default type weight settings for the function
89
describe('creates the "type weight object" from a graphql schema object with...', () => {
910
test('a single query type', () => {
1011
schema = buildSchema(`
@@ -41,7 +42,10 @@ describe('Test buildTypeWeightsFromSchema function', () => {
4142
expect(buildTypeWeightsFromSchema(schema)).toEqual({
4243
User: {
4344
weight: 1,
44-
fields: {},
45+
fields: {
46+
name: 0,
47+
email: 0,
48+
},
4549
},
4650
Movie: {
4751
weight: 1,
@@ -139,6 +143,8 @@ describe('Test buildTypeWeightsFromSchema function', () => {
139143
}
140144
`);
141145

146+
// This expected output is using default type weight settings.
147+
// Each test will override values for feild weights configuration.
142148
expectedOutput = {
143149
Query: {
144150
weight: 1,
@@ -180,6 +186,18 @@ describe('Test buildTypeWeightsFromSchema function', () => {
180186

181187
expect(typeWeightObject).toEqual({ expectedOutput });
182188
});
189+
190+
test('scalar parameter', () => {
191+
const typeWeightObject = buildTypeWeightsFromSchema(schema, {
192+
scalar: 2,
193+
});
194+
195+
expectedOutput.user.fields.name = 2;
196+
expectedOutput.user.fields.email = 2;
197+
expectedOutput.movie.fields.name = 2;
198+
199+
expect(typeWeightObject).toEqual({ expectedOutput });
200+
});
183201
});
184202

185203
describe('throws an error if...', () => {
@@ -203,10 +221,19 @@ describe('Test buildTypeWeightsFromSchema function', () => {
203221
});
204222

205223
test('user configures the type weights with negative numbers', () => {
206-
expect(buildTypeWeightsFromSchema(schema, { object: -1 })).toThrow();
207-
expect(buildTypeWeightsFromSchema(schema, { mutation: -1 })).toThrow();
208-
expect(buildTypeWeightsFromSchema(schema, { connection: -1 })).toThrow();
209-
expect(buildTypeWeightsFromSchema(schema, { scalar: -1 })).toThrow();
224+
// check that the error thrown from the function includes the substring 'negative' to inform the user of negative problem
225+
expect(() => buildTypeWeightsFromSchema(schema, { object: -1 })).toThrowError(
226+
'negative'
227+
);
228+
expect(() => buildTypeWeightsFromSchema(schema, { mutation: -1 })).toThrowError(
229+
'negative'
230+
);
231+
expect(() => buildTypeWeightsFromSchema(schema, { connection: -1 })).toThrowError(
232+
'negative'
233+
);
234+
expect(() => buildTypeWeightsFromSchema(schema, { scalar: -1 })).toThrowError(
235+
'negative'
236+
);
210237
});
211238
});
212239
});

0 commit comments

Comments
 (0)