Skip to content

Commit f271167

Browse files
committed
Remove obsolete tests
1 parent 5609723 commit f271167

1 file changed

Lines changed: 21 additions & 186 deletions

File tree

packages/plugins/typescript/operations/tests/ts-documents.spec.ts

Lines changed: 21 additions & 186 deletions
Original file line numberDiff line numberDiff line change
@@ -45,51 +45,6 @@ describe('TypeScript Operations Plugin', () => {
4545
await validate(content);
4646
});
4747

48-
it('Should handle "namespacedImportName" and add it when specified', async () => {
49-
const ast = parse(/* GraphQL */ `
50-
query notifications {
51-
notifications {
52-
id
53-
54-
... on TextNotification {
55-
text
56-
textAlias: text
57-
}
58-
59-
... on TextNotification {
60-
text
61-
}
62-
63-
... on ImageNotification {
64-
imageUrl
65-
metadata {
66-
created: createdBy
67-
}
68-
}
69-
}
70-
}
71-
`);
72-
73-
const { content } = await plugin(
74-
schema,
75-
[{ location: 'test-file.ts', document: ast }],
76-
{ namespacedImportName: 'Types' },
77-
{ outputFile: '' }
78-
);
79-
80-
expect(content).toMatchInlineSnapshot(`
81-
"export type NotificationsQueryVariables = Exact<{ [key: string]: never; }>;
82-
83-
84-
export type NotificationsQuery = { notifications: Array<
85-
| { text: string, id: string, textAlias: string }
86-
| { imageUrl: string, id: string, metadata: { created: string } }
87-
> };
88-
"
89-
`);
90-
await validate(content, '', [`Cannot find namespace 'Types'.`]);
91-
});
92-
9348
it('Can merge an inline fragment with a spread', async () => {
9449
const testSchema = buildSchema(/* GraphQL */ `
9550
interface Comment {
@@ -153,61 +108,6 @@ describe('TypeScript Operations Plugin', () => {
153108
`);
154109
});
155110

156-
it('Should handle "namespacedImportName"', async () => {
157-
const testSchema = buildSchema(/* GraphQL */ `
158-
type Query {
159-
f: E
160-
user: User!
161-
}
162-
163-
enum E {
164-
A
165-
B
166-
}
167-
168-
scalar JSON
169-
170-
type User {
171-
id: ID!
172-
f: E
173-
j: JSON
174-
}
175-
`);
176-
const ast = parse(/* GraphQL */ `
177-
query test {
178-
f
179-
user {
180-
id
181-
f
182-
j
183-
}
184-
}
185-
`);
186-
187-
const { content } = await plugin(
188-
testSchema,
189-
[{ location: 'test-file.ts', document: ast }],
190-
{ namespacedImportName: 'Types' },
191-
{ outputFile: '' }
192-
);
193-
194-
expect(content).toMatchInlineSnapshot(
195-
`
196-
"export type E =
197-
| 'A'
198-
| 'B';
199-
200-
export type TestQueryVariables = Exact<{ [key: string]: never; }>;
201-
202-
203-
export type TestQuery = { f: Types.E | null, user: { id: string, f: Types.E | null, j: any | null } };
204-
"
205-
`
206-
);
207-
208-
await validate(content, '', [`Cannot find namespace 'Types'.`]);
209-
});
210-
211111
it('Should generate the correct output when using immutableTypes config', async () => {
212112
const ast = parse(/* GraphQL */ `
213113
query notifications {
@@ -499,16 +399,7 @@ describe('TypeScript Operations Plugin', () => {
499399
"
500400
`
501401
);
502-
expect(content).toMatchInlineSnapshot(`
503-
"export type inotificationsqueryvariables = Exact<{ [key: string]: never; }>;
504402

505-
506-
export type inotificationsquery = { notifications: Array<
507-
| { text: string, id: string }
508-
| { imageUrl: string, id: string, metadata: { createdBy: string } }
509-
> };
510-
"
511-
`);
512403
await validate(content);
513404
});
514405

@@ -630,21 +521,6 @@ describe('TypeScript Operations Plugin', () => {
630521
"export type NotificationsQueryVariables = Exact<{ [key: string]: never; }>;
631522
632523
633-
export type NotificationsQuery = { notifications: Array<
634-
| { id: string }
635-
| { id: string }
636-
> };
637-
638-
export type MyFragment = { notifications: Array<
639-
| { id: string }
640-
| { id: string }
641-
> };
642-
"
643-
`);
644-
expect(withUsage).toMatchInlineSnapshot(`
645-
"export type NotificationsQueryVariables = Exact<{ [key: string]: never; }>;
646-
647-
648524
export type NotificationsQuery = { notifications: Array<
649525
| { id: string }
650526
| { id: string }
@@ -777,21 +653,6 @@ describe('TypeScript Operations Plugin', () => {
777653
"export type NotificationsVariables = Exact<{ [key: string]: never; }>;
778654
779655
780-
export type Notifications = { notifications: Array<
781-
| { id: string }
782-
| { id: string }
783-
> };
784-
785-
export type My = { notifications: Array<
786-
| { id: string }
787-
| { id: string }
788-
> };
789-
"
790-
`);
791-
expect(withUsage).toMatchInlineSnapshot(`
792-
"export type NotificationsVariables = Exact<{ [key: string]: never; }>;
793-
794-
795656
export type Notifications = { notifications: Array<
796657
| { id: string }
797658
| { id: string }
@@ -1003,6 +864,7 @@ export type Q2Query = { search: Array<
1003864
await validate(content);
1004865
});
1005866

867+
// TODO: review
1006868
it('Should skip __typename when skipTypename is set to true', async () => {
1007869
const ast = parse(/* GraphQL */ `
1008870
query {
@@ -1101,25 +963,6 @@ export type Q2Query = { search: Array<
1101963
await validate(content);
1102964
});
1103965

1104-
it('Should add aliased __typename correctly with preResovleTypes', async () => {
1105-
const ast = parse(/* GraphQL */ `
1106-
query {
1107-
type: __typename
1108-
dummy
1109-
}
1110-
`);
1111-
1112-
const { content } = await plugin(schema, [{ location: 'test-file.ts', document: ast }], {}, { outputFile: '' });
1113-
expect(content).toMatchInlineSnapshot(`
1114-
"export type Unnamed_1_QueryVariables = Exact<{ [key: string]: never; }>;
1115-
1116-
1117-
export type Unnamed_1_Query = { dummy: string | null, type: 'Query' };
1118-
"
1119-
`);
1120-
await validate(content);
1121-
});
1122-
1123966
it('Should add __typename as non-optional when explicitly specified', async () => {
1124967
const ast = parse(/* GraphQL */ `
1125968
query {
@@ -1162,24 +1005,6 @@ export type Q2Query = { search: Array<
11621005
await validate(content);
11631006
});
11641007

1165-
it('Should add __typename as optional when its not specified', async () => {
1166-
const ast = parse(/* GraphQL */ `
1167-
query {
1168-
dummy
1169-
}
1170-
`);
1171-
1172-
const { content } = await plugin(schema, [{ location: 'test-file.ts', document: ast }], {}, { outputFile: '' });
1173-
expect(content).toMatchInlineSnapshot(`
1174-
"export type Unnamed_1_QueryVariables = Exact<{ [key: string]: never; }>;
1175-
1176-
1177-
export type Unnamed_1_Query = { dummy: string | null };
1178-
"
1179-
`);
1180-
await validate(content);
1181-
});
1182-
11831008
it('Should add __typename as non-optional when its explictly specified, even if skipTypename is true', async () => {
11841009
const ast = parse(/* GraphQL */ `
11851010
query {
@@ -1205,7 +1030,7 @@ export type Q2Query = { search: Array<
12051030
await validate(content);
12061031
});
12071032

1208-
it('Should add __typename correctly when unions are in use', async () => {
1033+
it('Should add __typename correctly when unions are in use and nonOptionalTypename=true', async () => {
12091034
const ast = parse(/* GraphQL */ `
12101035
query unionTest {
12111036
unionTest {
@@ -1220,21 +1045,26 @@ export type Q2Query = { search: Array<
12201045
}
12211046
`);
12221047

1223-
const { content } = await plugin(schema, [{ location: 'test-file.ts', document: ast }], {}, { outputFile: '' });
1048+
const { content } = await plugin(
1049+
schema,
1050+
[{ location: 'test-file.ts', document: ast }],
1051+
{ nonOptionalTypename: true },
1052+
{ outputFile: '' }
1053+
);
12241054
expect(content).toMatchInlineSnapshot(`
12251055
"export type UnionTestQueryVariables = Exact<{ [key: string]: never; }>;
12261056
12271057
1228-
export type UnionTestQuery = { unionTest:
1229-
| { id: string }
1230-
| { age: number | null }
1058+
export type UnionTestQuery = { __typename: 'Query', unionTest:
1059+
| { __typename: 'User', id: string }
1060+
| { __typename: 'Profile', age: number | null }
12311061
| null };
12321062
"
12331063
`);
12341064
await validate(content);
12351065
});
12361066

1237-
it('Should add __typename correctly when interfaces are in use', async () => {
1067+
it('Should add __typename correctly when interfaces are in use and nonOptionalTypename=true', async () => {
12381068
const ast = parse(/* GraphQL */ `
12391069
query notifications {
12401070
notifications {
@@ -1254,14 +1084,19 @@ export type Q2Query = { search: Array<
12541084
}
12551085
`);
12561086

1257-
const { content } = await plugin(schema, [{ location: 'test-file.ts', document: ast }], {}, { outputFile: '' });
1087+
const { content } = await plugin(
1088+
schema,
1089+
[{ location: 'test-file.ts', document: ast }],
1090+
{ nonOptionalTypename: true },
1091+
{ outputFile: '' }
1092+
);
12581093
expect(content).toMatchInlineSnapshot(`
12591094
"export type NotificationsQueryVariables = Exact<{ [key: string]: never; }>;
12601095
12611096
1262-
export type NotificationsQuery = { notifications: Array<
1263-
| { text: string, id: string }
1264-
| { imageUrl: string, id: string, metadata: { createdBy: string } }
1097+
export type NotificationsQuery = { __typename: 'Query', notifications: Array<
1098+
| { __typename: 'TextNotification', text: string, id: string }
1099+
| { __typename: 'ImageNotification', imageUrl: string, id: string, metadata: { __typename: 'ImageMetadata', createdBy: string } }
12651100
> };
12661101
"
12671102
`);

0 commit comments

Comments
 (0)