Skip to content

Commit 78178e5

Browse files
committed
Add test for native-numeric
1 parent c95b771 commit 78178e5

1 file changed

Lines changed: 61 additions & 2 deletions

File tree

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

Lines changed: 61 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ describe('TypeScript Operations Plugin - Enum', () => {
4949
validateTs(result, undefined, undefined, undefined, undefined, true);
5050
});
5151

52-
it('handles `native-numeric` enum', async () => {
52+
it('handles `native-numeric`', async () => {
5353
const schema = buildSchema(/* GraphQL */ `
5454
type Query {
5555
me: User
@@ -103,6 +103,65 @@ describe('TypeScript Operations Plugin - Enum', () => {
103103
validateTs(result, undefined, undefined, undefined, undefined, true);
104104
});
105105

106+
it('handles `native-numeric` enum with types prefix and suffix', async () => {
107+
const schema = buildSchema(/* GraphQL */ `
108+
type Query {
109+
me: User
110+
}
111+
112+
type User {
113+
id: ID!
114+
name: String!
115+
role: UserRole!
116+
createdAt: DateTime!
117+
}
118+
119+
enum UserRole {
120+
ADMIN
121+
CUSTOMER
122+
}
123+
124+
scalar DateTime
125+
`);
126+
const document = parse(/* GraphQL */ `
127+
query Me($role: UserRole!) {
128+
me {
129+
id
130+
}
131+
}
132+
`);
133+
134+
const result = mergeOutputs([
135+
await plugin(
136+
schema,
137+
[{ document }],
138+
{ enumType: 'native-numeric', typesPrefix: 'AA_', typesSuffix: '_ZZ' },
139+
{ outputFile: '' },
140+
),
141+
]);
142+
143+
expect(result).toMatchInlineSnapshot(`
144+
"/** Internal type. DO NOT USE DIRECTLY. */
145+
type Exact<T extends { [key: string]: unknown }> = { [K in keyof T]: T[K] };
146+
/** Internal type. DO NOT USE DIRECTLY. */
147+
export type Incremental<T> = T | { [P in keyof T]?: P extends ' $fragmentName' | '__typename' ? T[P] : never };
148+
export enum AA_UserRole_ZZ {
149+
Admin_ZZ = 0,
150+
Customer_ZZ = 1
151+
}
152+
153+
export type AA_MeQueryVariables_ZZ = Exact<{
154+
role: AA_UserRole_ZZ;
155+
}>;
156+
157+
158+
export type AA_MeQuery_ZZ = { me: { id: string } | null };
159+
"
160+
`);
161+
162+
validateTs(result, undefined, undefined, undefined, undefined, true);
163+
});
164+
106165
it('handles `const` enum', async () => {
107166
const schema = buildSchema(/* GraphQL */ `
108167
type Query {
@@ -164,7 +223,7 @@ describe('TypeScript Operations Plugin - Enum', () => {
164223
validateTs(result, undefined, undefined, undefined, undefined, true);
165224
});
166225

167-
it('handles `const` enum with prefix and suffix', async () => {
226+
it('handles `const` enum with types prefix and suffix', async () => {
168227
const schema = buildSchema(/* GraphQL */ `
169228
type Query {
170229
me: User

0 commit comments

Comments
 (0)