55// Union Validation Tests - shouldFail
66// Tests for invalid union field syntax
77
8- import {
9- getTodo ,
10- createTodo ,
11- } from "../generated" ;
8+ import { getTodo , createTodo } from "../generated" ;
129
1310// Test 1: Invalid union field syntax - using string instead of object notation
1411export const invalidUnionString = await createTodo ( {
@@ -18,55 +15,49 @@ export const invalidUnionString = await createTodo({
1815 content : { note : "test" } ,
1916 } ,
2017 fields : [
21- "id" ,
22- "title" ,
18+ "id" ,
19+ "title" ,
2320 // @ts -expect-error - "content" should require object notation for union fields
24- "content"
25- ]
21+ "content" ,
22+ ] ,
2623} ) ;
2724
2825// Test 2: Invalid union field in getTodo
2926export const getWithInvalidUnionString = await getTodo ( {
3027 input : { } ,
3128 fields : [
32- "id" ,
33- "title" ,
29+ "id" ,
30+ "title" ,
3431 // @ts -expect-error - "content" should require object notation for union fields
35- "content"
36- ]
32+ "content" ,
33+ ] ,
3734} ) ;
3835
3936// Test 3: Invalid array union field syntax
4037export const invalidArrayUnionString = await createTodo ( {
4138 input : {
42- title : "Invalid Array Union Syntax" ,
39+ title : "Invalid Array Union Syntax" ,
4340 userId : "123e4567-e89b-12d3-a456-426614174000" ,
4441 attachments : [ { url : "https://example.com" } ] ,
4542 } ,
4643 fields : [
47- "id" ,
48- "title" ,
44+ "id" ,
45+ "title" ,
4946 // @ts -expect-error - "attachments" should require object notation for union fields
50- "attachments"
51- ]
47+ "attachments" ,
48+ ] ,
5249} ) ;
5350
5451// Test 4: Invalid multiple union fields as strings
5552export const invalidBothUnionStrings = await createTodo ( {
5653 input : {
5754 title : "Invalid Both Union Syntax" ,
58- userId : "123e4567-e89b-12d3-a456-426614174000" ,
55+ userId : "123e4567-e89b-12d3-a456-426614174000" ,
5956 content : { note : "test" } ,
6057 attachments : [ { url : "https://example.com" } ] ,
6158 } ,
62- fields : [
63- "id" ,
64- "title" ,
65- // @ts -expect-error - "content" should require object notation
66- "content" ,
67- // @ts -expect-error - "attachments" should require object notation
68- "attachments"
69- ]
59+ // @ts -expect-error - "content" & "attachments" should require object notation for union fields
60+ fields : [ "id" , "title" , "content" , "attachments" ] ,
7061} ) ;
7162
7263// Test 5: Invalid union in calculation
@@ -81,11 +72,11 @@ export const invalidUnionInCalculation = await getTodo({
8172 "id" ,
8273 "title" ,
8374 // @ts -expect-error - "content" should require object notation even in calculations
84- "content"
85- ]
86- }
87- }
88- ]
75+ "content" ,
76+ ] ,
77+ } ,
78+ } ,
79+ ] ,
8980} ) ;
9081
9182// Test 6: Invalid union field with empty object
@@ -96,9 +87,9 @@ export const invalidUnionEmptyObject = await getTodo({
9687 "title" ,
9788 {
9889 // @ts -expect-error - content object cannot be empty, must specify fields
99- content : { }
100- }
101- ]
90+ content : { } ,
91+ } ,
92+ ] ,
10293} ) ;
10394
10495// Test 7: Invalid union field with wrong object structure
@@ -110,10 +101,10 @@ export const invalidUnionWrongStructure = await getTodo({
110101 {
111102 content : [
112103 // @ts -expect-error - "invalidMember" is not a valid union member
113- "invalidMember"
114- ]
115- }
116- ]
104+ "invalidMember" ,
105+ ] ,
106+ } ,
107+ ] ,
117108} ) ;
118109
119110// Test 8: Invalid nested union field syntax in complex structure
@@ -129,12 +120,12 @@ export const invalidNestedUnionSyntax = await getTodo({
129120 // @ts -expect-error - "content" should require object notation
130121 "content" ,
131122 {
132- user : [ "id" , "name" ]
133- }
134- ]
135- }
136- }
137- ]
123+ user : [ "id" , "name" ] ,
124+ } ,
125+ ] ,
126+ } ,
127+ } ,
128+ ] ,
138129} ) ;
139130
140131// Test 9: Invalid union member field selection
@@ -149,12 +140,12 @@ export const invalidUnionMemberFields = await getTodo({
149140 text : [
150141 "text" ,
151142 // @ts -expect-error - "nonExistentField" should not be valid for text member
152- "nonExistentField"
153- ]
154- }
155- ]
156- }
157- ]
143+ "nonExistentField" ,
144+ ] ,
145+ } ,
146+ ] ,
147+ } ,
148+ ] ,
158149} ) ;
159150
160151// Test 10: Invalid array union with wrong member
@@ -166,10 +157,10 @@ export const invalidArrayUnionMember = await getTodo({
166157 {
167158 attachments : [
168159 // @ts -expect-error - "invalidAttachmentType" is not a valid union member
169- "invalidAttachmentType"
170- ]
171- }
172- ]
160+ "invalidAttachmentType" ,
161+ ] ,
162+ } ,
163+ ] ,
173164} ) ;
174165
175166console . log ( "Union validation tests should FAIL compilation!" ) ;
0 commit comments