Skip to content

Commit 5954f2f

Browse files
committed
[tests] Fix & narrow results where needed now
1 parent 86b4022 commit 5954f2f

9 files changed

+53
-59
lines changed

test/engagement-changeset-aware.e2e-spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ const readLanguageEngagement = (app: TestApp, id: string, changeset?: string) =>
5353
graphql(
5454
`
5555
query engagement($id: ID!, $changeset: ID) {
56-
engagement(id: $id, changeset: $changeset) {
56+
engagement: languageEngagement(id: $id, changeset: $changeset) {
5757
...languageEngagement
5858
changeset {
5959
id

test/engagement.e2e-spec.ts

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { faker } from '@faker-js/faker';
22
import { some } from 'lodash';
33
import { DateTime, Interval } from 'luxon';
4-
import { generateId, type ID, Role } from '~/common';
4+
import { generateId, Role } from '~/common';
55
import { graphql } from '~/graphql';
66
import {
77
type CreateInternshipEngagement,
@@ -209,7 +209,7 @@ describe('Engagement e2e', () => {
209209
expect(actual.lastReactivatedAt.value).toBeNull();
210210
});
211211

212-
it('reads a an language engagement by id', async () => {
212+
it('reads a language engagement by id', async () => {
213213
project = await createProject(app);
214214
const upload = await requestFileUpload(app);
215215
const fakeFile = await uploadFileContents(app, upload.url);
@@ -227,7 +227,7 @@ describe('Engagement e2e', () => {
227227
graphql(
228228
`
229229
query engagement($id: ID!) {
230-
engagement(id: $id) {
230+
engagement: languageEngagement(id: $id) {
231231
...languageEngagement
232232
}
233233
}
@@ -284,6 +284,7 @@ describe('Engagement e2e', () => {
284284
`
285285
query engagement($id: ID!) {
286286
engagement(id: $id) {
287+
__typename
287288
...internshipEngagement
288289
}
289290
}
@@ -294,6 +295,7 @@ describe('Engagement e2e', () => {
294295
id: internshipEngagement.id,
295296
},
296297
);
298+
if (actual.__typename !== 'InternshipEngagement') throw new Error();
297299

298300
expect(actual.id).toBe(internshipEngagement.id);
299301
expect(actual.intern).toMatchObject(internshipEngagement.intern);
@@ -490,7 +492,7 @@ describe('Engagement e2e', () => {
490492
graphql(
491493
`
492494
query engagement($id: ID!) {
493-
engagement(id: $id) {
495+
engagement: languageEngagement(id: $id) {
494496
...languageEngagement
495497
}
496498
}
@@ -532,18 +534,18 @@ describe('Engagement e2e', () => {
532534
`
533535
query engagement($id: ID!) {
534536
engagement(id: $id) {
535-
...languageEngagement
537+
...engagement
536538
}
537539
}
538540
`,
539-
[fragments.languageEngagement],
541+
[fragments.engagement],
540542
),
541543
{
542544
id: languageEngagement.id,
543545
},
544546
);
545547

546-
expect(result?.engagement?.ceremony?.value?.id).toBeDefined();
548+
expect(result.engagement.ceremony.value?.id).toBeDefined();
547549
});
548550

549551
it('updates ceremony for language engagement', async () => {
@@ -561,19 +563,18 @@ describe('Engagement e2e', () => {
561563
`
562564
query engagement($id: ID!) {
563565
engagement(id: $id) {
564-
...languageEngagement
566+
...engagement
565567
}
566568
}
567569
`,
568-
[fragments.languageEngagement],
570+
[fragments.engagement],
569571
),
570572
{
571573
id: languageEngagement.id,
572574
},
573575
);
574-
expect(
575-
languageEngagementRead?.engagement?.ceremony?.value?.id,
576-
).toBeDefined();
576+
const ceremony = languageEngagementRead.engagement.ceremony.value;
577+
expect(ceremony).toBeDefined();
577578

578579
await registerUser(app, { roles: [Role.FieldOperationsDirector] });
579580
const date = '2020-05-13';
@@ -598,7 +599,7 @@ describe('Engagement e2e', () => {
598599
{
599600
input: {
600601
ceremony: {
601-
id: languageEngagementRead?.engagement?.ceremony?.value?.id,
602+
id: ceremony.id,
602603
planned: true,
603604
estimatedDate: date,
604605
},
@@ -627,19 +628,18 @@ describe('Engagement e2e', () => {
627628
`
628629
query engagement($id: ID!) {
629630
engagement(id: $id) {
630-
...internshipEngagement
631+
...engagement
631632
}
632633
}
633634
`,
634-
[fragments.internshipEngagement],
635+
[fragments.engagement],
635636
),
636637
{
637638
id: ie.id,
638639
},
639640
);
640-
expect(
641-
internshipEngagementRead?.engagement?.ceremony?.value?.id,
642-
).toBeDefined();
641+
const ceremony = internshipEngagementRead.engagement.ceremony.value;
642+
expect(ceremony).toBeDefined();
643643

644644
await registerUser(app, { roles: [Role.FieldOperationsDirector] });
645645
const date = '2020-05-13';
@@ -664,7 +664,7 @@ describe('Engagement e2e', () => {
664664
{
665665
input: {
666666
ceremony: {
667-
id: internshipEngagementRead?.engagement?.ceremony?.value?.id,
667+
id: ceremony.id,
668668
planned: true,
669669
estimatedDate: date,
670670
},
@@ -690,11 +690,11 @@ describe('Engagement e2e', () => {
690690
`
691691
query engagement($id: ID!) {
692692
engagement(id: $id) {
693-
...languageEngagement
693+
...engagement
694694
}
695695
}
696696
`,
697-
[fragments.languageEngagement],
697+
[fragments.engagement],
698698
),
699699
{
700700
id: languageEngagement.id,
@@ -884,6 +884,7 @@ describe('Engagement e2e', () => {
884884
graphql(`
885885
query EngagementById($id: ID!) {
886886
engagement(id: $id) {
887+
__typename
887888
... on InternshipEngagement {
888889
id
889890
methodologies {
@@ -897,7 +898,7 @@ describe('Engagement e2e', () => {
897898
id: internshipEngagement.id,
898899
},
899900
);
900-
expect(internshipEngagement.id).toBeDefined();
901+
if (actual.__typename !== 'InternshipEngagement') throw new Error();
901902
expect(actual.methodologies).toBeDefined();
902903
expect(actual.methodologies.value).toMatchObject([]);
903904
});
@@ -1117,7 +1118,7 @@ describe('Engagement e2e', () => {
11171118
project: { engagements },
11181119
} = await app.graphql.query(
11191120
graphql(`
1120-
query ($id: ID!) {
1121+
query EngagementStatus($id: ID!) {
11211122
project(id: $id) {
11221123
id
11231124
engagements {
@@ -1136,10 +1137,8 @@ describe('Engagement e2e', () => {
11361137
step: expectedNewStatus,
11371138
},
11381139
);
1139-
const actual = engagements.items.find(
1140-
(e: { id: ID }) => e.id === engagement.id,
1141-
);
1142-
expect(actual.status.value).toBe(expectedNewStatus);
1140+
const actual = engagements.items.find((e) => e.id === engagement.id);
1141+
expect(actual?.status.value).toBe(expectedNewStatus);
11431142
},
11441143
);
11451144

test/file.e2e-spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ describe('File e2e', () => {
144144

145145
const created = await uploadFile(app, root.id, fakeFile);
146146
const fetched = await getFileNode(app, created.id);
147-
if (fetched.__typename !== 'File') fail();
147+
if (fetched.__typename !== 'File') throw new Error();
148148
for (const file of [created, fetched]) {
149149
expect(file.id).toBeDefined();
150150
expect(file.name).toEqual(fakeFile.name);
@@ -169,7 +169,7 @@ describe('File e2e', () => {
169169

170170
// Maybe get version from file.children when implemented
171171
const version = await getFileNode(app, upload.id);
172-
if (version.__typename !== 'FileVersion') fail();
172+
if (version.__typename !== 'FileVersion') throw new Error();
173173

174174
expect(version.id).toBeDefined();
175175
expect(version.name).toEqual(fakeFile.name);

test/partnership-changeset-aware.e2e-spec.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -207,8 +207,8 @@ describe('Partnership Changeset Aware e2e', () => {
207207
projectId: project.id,
208208
});
209209

210-
// Delete partnereship in changeset
211-
let result = await app.graphql.mutate(
210+
// Delete partnership in changeset
211+
await app.graphql.mutate(
212212
graphql(`
213213
mutation deletePartnership($id: ID!, $changeset: ID) {
214214
deletePartnership(id: $id, changeset: $changeset) {
@@ -221,11 +221,9 @@ describe('Partnership Changeset Aware e2e', () => {
221221
changeset: changeset.id,
222222
},
223223
);
224-
const actual = result.deletePartnership;
225-
expect(actual).toBeTruthy();
226224

227225
// List partnerships without changeset
228-
result = await readPartnerships(app, project.id);
226+
let result = await readPartnerships(app, project.id);
229227
expect(result.project.partnerships.items.length).toBe(2);
230228
// List partnerships with changeset
231229
result = await readPartnerships(app, project.id, changeset.id);

test/product.e2e-spec.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,8 @@ describe('Product e2e', () => {
106106
},
107107
);
108108
const actual = result.product;
109+
if (actual.__typename !== 'DirectScriptureProduct') throw new Error();
110+
109111
expect(actual?.unspecifiedScripture?.value).toMatchObject({
110112
book: 'Matthew',
111113
totalVerses: 10,
@@ -189,6 +191,8 @@ describe('Product e2e', () => {
189191
},
190192
);
191193
const actual = result.product;
194+
if (actual.__typename !== 'DerivativeScriptureProduct') throw new Error();
195+
192196
expect(actual.produces).toBeDefined();
193197
expect(actual.produces?.value).toBeDefined();
194198
expect(actual.produces?.value?.id).toBe(story.id);
@@ -270,6 +274,8 @@ describe('Product e2e', () => {
270274
},
271275
);
272276
const actual = result.product;
277+
if (actual.__typename !== 'DerivativeScriptureProduct') throw new Error();
278+
273279
expect(actual.scriptureReferencesOverride?.value).toBeDefined();
274280
expect(actual.scriptureReferencesOverride?.value).toEqual(
275281
expect.arrayContaining(randomScriptureReferences),
@@ -359,6 +365,8 @@ describe('Product e2e', () => {
359365
);
360366

361367
const actual = result.updateDirectScriptureProduct.product;
368+
if (actual.__typename !== 'DirectScriptureProduct') throw new Error();
369+
362370
expect(actual.mediums.value).toEqual(updateProduct.mediums);
363371
expect(actual.purposes.value).toEqual(updateProduct.purposes);
364372
expect(actual.methodology.value).toEqual(updateProduct.methodology);
@@ -443,8 +451,9 @@ describe('Product e2e', () => {
443451
},
444452
},
445453
);
446-
447454
const actual = result.updateDerivativeScriptureProduct.product;
455+
if (actual.__typename !== 'DerivativeScriptureProduct') throw new Error();
456+
448457
expect(actual.produces).toBeDefined();
449458
expect(actual.produces?.value).toBeDefined();
450459
expect(actual.produces?.value?.id).toBe(film.id);
@@ -530,6 +539,7 @@ describe('Product e2e', () => {
530539
);
531540

532541
const actual = result.updateDerivativeScriptureProduct.product;
542+
if (actual.__typename !== 'DerivativeScriptureProduct') throw new Error();
533543

534544
expect(actual.scriptureReferencesOverride?.value).toEqual(
535545
expect.arrayContaining(override),
@@ -615,6 +625,8 @@ describe('Product e2e', () => {
615625
);
616626

617627
const actual = result.updateDerivativeScriptureProduct.product;
628+
if (actual.__typename !== 'DerivativeScriptureProduct') throw new Error();
629+
618630
expect(actual.scriptureReferencesOverride?.value).toBeNull();
619631
expect(actual.produces?.value?.scriptureReferences?.value).toEqual(
620632
actual.scriptureReferences.value,
@@ -802,7 +814,7 @@ describe('Product e2e', () => {
802814
const { engagement: actual } = await app.graphql.query(
803815
graphql(`
804816
query engagement($id: ID!) {
805-
engagement(id: $id) {
817+
engagement: languageEngagement(id: $id) {
806818
... on LanguageEngagement {
807819
id
808820
products {

test/progress-report-media.e2e-spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ describe('ProgressReport Media e2e', () => {
101101
`),
102102
{ id: reportId },
103103
);
104-
if (report.__typename !== 'ProgressReport') fail();
104+
if (report.__typename !== 'ProgressReport') throw new Error();
105105
const { uploadableVariants } = report.media;
106106
const keys = uploadableVariants.map((v) => v.key);
107107
expect(keys).toEqual(['draft', 'translated', 'fpm']);
@@ -410,7 +410,7 @@ async function getFeaturedMedia(app: TestApp, id: IdOf<ProgressReport>) {
410410
),
411411
{ id },
412412
);
413-
if (report.__typename !== 'ProgressReport') fail();
413+
if (report.__typename !== 'ProgressReport') throw new Error();
414414
return report.featuredMedia;
415415
}
416416

test/project-workflow.e2e-spec.ts

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -140,29 +140,13 @@ describe('Project-Workflow e2e', () => {
140140

141141
return [location, fieldRegion];
142142
});
143-
await updateProject(app, {
143+
let result = await updateProject(app, {
144144
id: project.id,
145145
primaryLocationId: location.id,
146146
fieldRegionId: fieldRegion.id,
147147
});
148-
149-
let result = await app.graphql.query(
150-
graphql(
151-
`
152-
query project($id: ID!) {
153-
project(id: $id) {
154-
...project
155-
}
156-
}
157-
`,
158-
[fragments.project],
159-
),
160-
{
161-
id: project.id,
162-
},
163-
);
164-
expect(result.project.primaryLocation.value.id).toBe(location.id);
165-
expect(result.project.fieldRegion.value.id).toBe(fieldRegion.id);
148+
expect(result.primaryLocation.value.id).toBe(location.id);
149+
expect(result.fieldRegion.value.id).toBe(fieldRegion.id);
166150

167151
// Enter MOU dates
168152
await fieldOpsDirector.login();

test/utility/create-file.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ export async function getFileNodeChildren(
151151
input,
152152
},
153153
);
154-
if (result.fileNode.__typename === 'FileVersion') fail();
154+
if (result.fileNode.__typename === 'FileVersion') throw new Error();
155155

156156
const actual = result.fileNode.children;
157157

test/utility/fragments.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,7 @@ export type scriptureRange = FragmentOf<typeof scriptureRange>;
431431
export const product = graphql(
432432
`
433433
fragment product on Product {
434+
__typename
434435
id
435436
createdAt
436437
mediums {

0 commit comments

Comments
 (0)