Skip to content

Commit 86b4022

Browse files
committed
[tests] Infer gql result types & use fragment types
1 parent cd09af3 commit 86b4022

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+216
-443
lines changed

test/authentication.e2e-spec.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import {
1414
registerUser,
1515
type TestApp,
1616
} from './utility';
17-
import { type RawUser } from './utility/fragments';
1817

1918
describe('Authentication e2e', () => {
2019
let app: TestApp;
@@ -105,7 +104,7 @@ describe('Authentication e2e', () => {
105104
},
106105
);
107106

108-
const actual: RawUser = result.user;
107+
const actual = result.user;
109108
expect(actual).toBeTruthy();
110109
expect(isValidId(actual.id)).toBe(true);
111110
expect(actual.email.value).toBe(fakeUser.email.toLowerCase());

test/education.e2e-spec.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,18 @@ import { faker } from '@faker-js/faker';
22
import { times } from 'lodash';
33
import { isValidId, Role } from '~/common';
44
import { graphql } from '~/graphql';
5-
import { type User } from '../src/components/user/dto';
6-
import { type Education } from '../src/components/user/education/dto';
75
import {
86
createEducation,
97
createSession,
108
createTestApp,
9+
fragments,
1110
registerUser,
1211
type TestApp,
1312
} from './utility';
14-
import { fragments } from './utility/fragments';
1513

1614
describe('Education e2e', () => {
1715
let app: TestApp;
18-
let user: User;
16+
let user: fragments.user;
1917

2018
beforeAll(async () => {
2119
app = await createTestApp();
@@ -105,7 +103,7 @@ describe('Education e2e', () => {
105103
id: education.id,
106104
},
107105
);
108-
const actual: Education | undefined = result.deleteEducation;
106+
const actual = result.deleteEducation;
109107
expect(actual).toBeTruthy();
110108
});
111109

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { CalendarDate, type ID, Role } from '~/common';
22
import { graphql } from '~/graphql';
33
import { EngagementStatus } from '../src/components/engagement/dto';
4-
import { type Language } from '../src/components/language/dto';
54
import { ProjectChangeRequestType } from '../src/components/project-change-request/dto';
65
import {
76
approveProjectChangeRequest,
@@ -15,12 +14,12 @@ import {
1514
createSession,
1615
createTestApp,
1716
errors,
17+
fragments,
1818
registerUser,
1919
runAsAdmin,
2020
type TestApp,
2121
updateProject,
2222
} from './utility';
23-
import { fragments } from './utility/fragments';
2423
import { forceProjectTo } from './utility/transition-project';
2524

2625
const readEngagements = (app: TestApp, id: string, changeset?: string) =>
@@ -140,7 +139,7 @@ const activeProject = async (app: TestApp, projectId: ID) => {
140139

141140
describe('Engagement Changeset Aware e2e', () => {
142141
let app: TestApp;
143-
let language: Language;
142+
let language: fragments.language;
144143

145144
beforeAll(async () => {
146145
app = await createTestApp();

test/engagement.e2e-spec.ts

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,10 @@ import { graphql } from '~/graphql';
66
import {
77
type CreateInternshipEngagement,
88
EngagementStatus,
9-
type InternshipEngagement,
109
InternshipPosition,
11-
type LanguageEngagement,
1210
} from '../src/components/engagement/dto';
13-
import { type Language } from '../src/components/language/dto';
14-
import { type Location } from '../src/components/location/dto';
1511
import { ProductMethodology } from '../src/components/product/dto';
16-
import {
17-
type Project,
18-
ProjectStep,
19-
ProjectType,
20-
} from '../src/components/project/dto';
21-
import { type User } from '../src/components/user/dto';
12+
import { ProjectStep, ProjectType } from '../src/components/project/dto';
2213
import {
2314
createDirectProduct,
2415
createFundingAccount,
@@ -34,7 +25,6 @@ import {
3425
errors,
3526
fragments,
3627
getUserFromSession,
37-
type Raw,
3828
registerUser,
3929
requestFileUpload,
4030
runAsAdmin,
@@ -56,13 +46,13 @@ import {
5646

5747
describe('Engagement e2e', () => {
5848
let app: TestApp;
59-
let project: Raw<Project>;
60-
let internshipProject: Raw<Project>;
61-
let language: Language;
62-
let location: Location;
49+
let project: fragments.project;
50+
let internshipProject: fragments.project;
51+
let language: fragments.language;
52+
let location: fragments.location;
6353
let user: TestUser;
64-
let intern: Partial<User>;
65-
let mentor: Partial<User>;
54+
let intern: { id: string };
55+
let mentor: { id: string };
6656

6757
beforeAll(async () => {
6858
app = await createTestApp();
@@ -139,8 +129,7 @@ describe('Engagement e2e', () => {
139129
},
140130
);
141131

142-
const actual: LanguageEngagement =
143-
result.createLanguageEngagement.engagement;
132+
const actual = result.createLanguageEngagement.engagement;
144133
expect(actual.id).toBeDefined();
145134
expect(actual.firstScripture.value).toBeNull();
146135
expect(actual.lukePartnership.value).toBeNull();
@@ -207,8 +196,7 @@ describe('Engagement e2e', () => {
207196
},
208197
);
209198

210-
const actual: InternshipEngagement =
211-
result.createInternshipEngagement.engagement;
199+
const actual = result.createInternshipEngagement.engagement;
212200
expect(actual.id).toBeDefined();
213201
expect(actual.countryOfOrigin.value).toBeNull();
214202
expect(actual.mentor.value).toBeNull();
@@ -463,7 +451,7 @@ describe('Engagement e2e', () => {
463451
},
464452
);
465453

466-
const actual: boolean | undefined = result.deleteEngagement;
454+
const actual = result.deleteEngagement;
467455
expect(actual).toBeTruthy();
468456
await app.graphql
469457
.query(

test/file.e2e-spec.ts

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,32 +16,27 @@ import {
1616
FileNodeType,
1717
type RequestUploadOutput,
1818
} from '../src/components/file/dto';
19-
import { type User } from '../src/components/user/dto';
2019
import {
2120
createFileVersion,
2221
createSession,
2322
createTestApp,
2423
errors,
2524
type FakeFile,
25+
type fragments,
2626
generateFakeFile,
2727
getFileNode,
2828
getFileNodeChildren,
2929
registerUser,
3030
requestFileUpload,
3131
runInIsolatedSession,
3232
type TestApp,
33+
type TestUser,
3334
uploadFileContents,
3435
} from './utility';
3536
import {
3637
createDirectory,
3738
createRootDirectory,
3839
} from './utility/create-directory';
39-
import {
40-
type RawDirectory,
41-
type RawFile,
42-
type RawFileNode,
43-
type RawFileVersion,
44-
} from './utility/fragments';
4540

4641
export async function uploadFile(
4742
app: TestApp,
@@ -122,7 +117,7 @@ describe('File e2e', () => {
122117
let app: TestApp;
123118
let bucket: LocalBucket;
124119
let root: Directory;
125-
let me: User;
120+
let me: TestUser;
126121

127122
beforeAll(async () => {
128123
app = await createTestApp();
@@ -148,7 +143,8 @@ describe('File e2e', () => {
148143
const fakeFile = generateFakeFile();
149144

150145
const created = await uploadFile(app, root.id, fakeFile);
151-
const fetched = (await getFileNode(app, created.id)) as RawFile;
146+
const fetched = await getFileNode(app, created.id);
147+
if (fetched.__typename !== 'File') fail();
152148
for (const file of [created, fetched]) {
153149
expect(file.id).toBeDefined();
154150
expect(file.name).toEqual(fakeFile.name);
@@ -172,7 +168,8 @@ describe('File e2e', () => {
172168
const file = await uploadFile(app, root.id, fakeFile, upload);
173169

174170
// Maybe get version from file.children when implemented
175-
const version = (await getFileNode(app, upload.id)) as RawFileVersion;
171+
const version = await getFileNode(app, upload.id);
172+
if (version.__typename !== 'FileVersion') fail();
176173

177174
expect(version.id).toBeDefined();
178175
expect(version.name).toEqual(fakeFile.name);
@@ -216,8 +213,8 @@ describe('File e2e', () => {
216213
});
217214

218215
async function assertFileChanges(
219-
updated: RawFile,
220-
initial: RawFile,
216+
updated: fragments.file,
217+
initial: fragments.file,
221218
input: FakeFile,
222219
) {
223220
expect(updated.id).toEqual(initial.id);
@@ -275,15 +272,15 @@ describe('File e2e', () => {
275272
const upload = await requestFileUpload(app);
276273
const file = await uploadFile(app, root.id, {}, upload);
277274
// Maybe get version from file.children when implemented
278-
const version = (await getFileNode(app, upload.id)) as RawFileVersion;
275+
const version = await getFileNode(app, upload.id);
279276
await deleteNode(app, version.id);
280277
await expectNodeNotFound(app, version.id);
281278
await expectNodeNotFound(app, file.id);
282279
});
283280

284281
describe('directory children', () => {
285-
let dir: RawDirectory;
286-
let expectedChildren: RawFileNode[];
282+
let dir: fragments.directory;
283+
let expectedChildren: fragments.fileNode[];
287284
let expectedTotalChildren: number;
288285
let expectedTotalDirs: number;
289286
let expectedTotalFiles: number;
@@ -396,7 +393,7 @@ describe('File e2e', () => {
396393
});
397394

398395
describe('file children', () => {
399-
let file: RawFile;
396+
let file: fragments.file;
400397
const expectedVersionIds: ID[] = [];
401398
let expectedTotalVersions: number;
402399

test/film.e2e-spec.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { faker } from '@faker-js/faker';
22
import { times } from 'lodash';
33
import { isValidId, Role } from '~/common';
44
import { graphql } from '~/graphql';
5-
import { type Film } from '../src/components/film/dto';
65
import { ScriptureRange } from '../src/components/scripture/dto';
76
import {
87
createFilm,
@@ -117,7 +116,7 @@ describe('Film e2e', () => {
117116
id: fm.id,
118117
},
119118
);
120-
const actual: Film | undefined = result.deleteFilm;
119+
const actual = result.deleteFilm;
121120
expect(actual).toBeTruthy();
122121
});
123122

test/funding-account.e2e-spec.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { faker } from '@faker-js/faker';
22
import { times } from 'lodash';
33
import { isValidId, Role } from '~/common';
44
import { graphql } from '~/graphql';
5-
import { type FundingAccount } from '../src/components/funding-account/dto';
65
import {
76
createFundingAccount,
87
createSession,
@@ -109,7 +108,7 @@ describe('FundingAccount e2e', () => {
109108
id: st.id,
110109
},
111110
);
112-
const actual: FundingAccount | undefined = result.deleteFundingAccount;
111+
const actual = result.deleteFundingAccount;
113112
expect(actual).toBeTruthy();
114113
});
115114

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ import {
1111
createRegion,
1212
createSession,
1313
createTestApp,
14+
fragments,
1415
loginAsAdmin,
1516
type TestApp,
1617
} from './utility';
17-
import { fragments } from './utility/fragments';
1818
import { forceProjectTo } from './utility/transition-project';
1919

2020
const readLanguage = (app: TestApp, id: string, changeset?: string) =>

test/language.e2e-spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ import {
1111
createSession,
1212
createTestApp,
1313
errors,
14+
fragments,
1415
loginAsAdmin,
1516
type TestApp,
1617
} from './utility';
17-
import { fragments } from './utility/fragments';
1818

1919
describe('Language e2e', () => {
2020
let app: TestApp;

test/location.e2e-spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ describe('Location e2e', () => {
9999
id: st.id,
100100
},
101101
);
102-
const actual: Location | undefined = result.deleteLocation;
102+
const actual = result.deleteLocation;
103103
expect(actual).toBeTruthy();
104104
});
105105

0 commit comments

Comments
 (0)