Skip to content

Commit 71dd46b

Browse files
committed
updated uniontypeweight object
1 parent 88e4e03 commit 71dd46b

File tree

1 file changed

+22
-9
lines changed

1 file changed

+22
-9
lines changed

test/analysis/typeComplexityAnalysis.test.ts

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -414,8 +414,9 @@ describe('Test getQueryTypeComplexity function', () => {
414414
});
415415
});
416416

417-
xdescribe('with inline fragments', () => {
417+
describe('with inline fragments', () => {
418418
describe('on union types', () => {
419+
let unionTypeWeights: TypeWeightObject;
419420
beforeAll(() => {
420421
// type Query {
421422
// hero(episode: Episode): Character
@@ -434,7 +435,7 @@ describe('Test getQueryTypeComplexity function', () => {
434435
// primaryFunction: String
435436
// friends(first: Int): [Character]
436437
// }
437-
typeWeights = {
438+
unionTypeWeights = {
438439
query: {
439440
weight: 1,
440441
fields: {
@@ -443,6 +444,10 @@ describe('Test getQueryTypeComplexity function', () => {
443444
},
444445
},
445446
},
447+
character: {
448+
weight: 1,
449+
fields: {},
450+
},
446451
human: {
447452
weight: 1,
448453
fields: {
@@ -485,7 +490,9 @@ describe('Test getQueryTypeComplexity function', () => {
485490
}
486491
}`;
487492
// Query 1 + 1 hero
488-
expect(getQueryTypeComplexity(parse(query), variables, typeWeights)).toBe(2);
493+
expect(getQueryTypeComplexity(parse(query), variables, unionTypeWeights)).toBe(
494+
2
495+
);
489496
});
490497

491498
test('that have differing complexities', () => {
@@ -506,7 +513,9 @@ describe('Test getQueryTypeComplexity function', () => {
506513
}`;
507514
// Query 1 + 1 hero + max(Droid 0, Human 3) = 5
508515
mockHumanFriendsFunction.mockReturnValueOnce(3);
509-
expect(getQueryTypeComplexity(parse(query), variables, typeWeights)).toBe(5);
516+
expect(getQueryTypeComplexity(parse(query), variables, unionTypeWeights)).toBe(
517+
5
518+
);
510519
});
511520

512521
test('that contain an object and a non-zero complexity', () => {
@@ -528,7 +537,9 @@ describe('Test getQueryTypeComplexity function', () => {
528537
mockCharacterFriendsFunction.mockReturnValueOnce(3);
529538
variables = { first: 3 };
530539
// Query 1 + 1 hero + 3 friends/character
531-
expect(getQueryTypeComplexity(parse(query), variables, typeWeights)).toBe(5);
540+
expect(getQueryTypeComplexity(parse(query), variables, unionTypeWeights)).toBe(
541+
5
542+
);
532543
});
533544

534545
test('that use a variable', () => {
@@ -550,7 +561,9 @@ describe('Test getQueryTypeComplexity function', () => {
550561
mockDroidFriendsFunction.mockReturnValueOnce(3);
551562
variables = { first: 3 };
552563
// Query 1 + 1 hero + max(Droid 3, Human 0) = 5
553-
expect(getQueryTypeComplexity(parse(query), variables, typeWeights)).toBe(5);
564+
expect(getQueryTypeComplexity(parse(query), variables, unionTypeWeights)).toBe(
565+
5
566+
);
554567
});
555568

556569
test('that do not have a TypeCondition', () => {
@@ -570,7 +583,7 @@ describe('Test getQueryTypeComplexity function', () => {
570583
}`;
571584
mockCharacterFriendsFunction.mockReturnValueOnce(3);
572585
// Query 1 + 1 hero + max(Character 3, Human 0) = 5
573-
expect(getQueryTypeComplexity(parse(query), {}, typeWeights)).toBe(5);
586+
expect(getQueryTypeComplexity(parse(query), {}, unionTypeWeights)).toBe(5);
574587
});
575588

576589
xtest('that include a directive', () => {
@@ -590,7 +603,7 @@ describe('Test getQueryTypeComplexity function', () => {
590603
}`;
591604
mockCharacterFriendsFunction.mockReturnValueOnce(3);
592605
// Query 1 + 1 hero + max(...Character 3, ...Human 0) = 5
593-
expect(getQueryTypeComplexity(parse(query), {}, typeWeights)).toBe(5);
606+
expect(getQueryTypeComplexity(parse(query), {}, unionTypeWeights)).toBe(5);
594607
});
595608

596609
test('and multiple fragments apply to the selection set', () => {
@@ -613,7 +626,7 @@ describe('Test getQueryTypeComplexity function', () => {
613626
mockCharacterFriendsFunction.mockReturnValueOnce(3);
614627
mockHumanFriendsFunction.mockReturnValueOnce(2);
615628
// Query 1 + 1 hero + ...Character 3 + ...Human 2 = 7
616-
expect(getQueryTypeComplexity(parse(query), {}, typeWeights)).toBe(7);
629+
expect(getQueryTypeComplexity(parse(query), {}, unionTypeWeights)).toBe(7);
617630
});
618631
});
619632

0 commit comments

Comments
 (0)