@@ -316,4 +316,110 @@ describe('useUserExperienceForm', () => {
316316 // Validation should fail for undefined startedAt
317317 expect ( isValid ) . toBe ( false ) ;
318318 } ) ;
319+
320+ it ( 'should validate repository with nullable id for custom repositories' , async ( ) => {
321+ const openSourceExperience : BaseUserExperience & {
322+ repository ?: {
323+ id : string | null ;
324+ owner : string | null ;
325+ name : string ;
326+ url : string ;
327+ image : string | null ;
328+ } ;
329+ } = {
330+ type : UserExperienceType . OpenSource ,
331+ title : 'Open Source Contributor' ,
332+ description : 'Contributing to projects' ,
333+ startedAt : new Date ( '2023-01-01' ) ,
334+ current : true ,
335+ repository : {
336+ id : null , // Custom repository has null id
337+ owner : 'myorg' ,
338+ name : 'myrepo' ,
339+ url : 'https://gitlab.com/myorg/myrepo' ,
340+ image : null ,
341+ } ,
342+ } ;
343+
344+ const { result } = renderHook (
345+ ( ) => useUserExperienceForm ( { defaultValues : openSourceExperience } ) ,
346+ { wrapper : createWrapper ( ) } ,
347+ ) ;
348+
349+ await act ( async ( ) => {
350+ const isValid = await result . current . methods . trigger ( 'repository' ) ;
351+ // Should be valid even with null id
352+ expect ( isValid ) . toBe ( true ) ;
353+ } ) ;
354+ } ) ;
355+
356+ it ( 'should validate repository with GitHub id' , async ( ) => {
357+ const openSourceExperience : BaseUserExperience & {
358+ repository ?: {
359+ id : string | null ;
360+ owner : string | null ;
361+ name : string ;
362+ url : string ;
363+ image : string | null ;
364+ } ;
365+ } = {
366+ type : UserExperienceType . OpenSource ,
367+ title : 'React Contributor' ,
368+ description : 'Contributing to React' ,
369+ startedAt : new Date ( '2023-01-01' ) ,
370+ current : true ,
371+ repository : {
372+ id : '10270250' , // GitHub repository has string id
373+ owner : 'facebook' ,
374+ name : 'react' ,
375+ url : 'https://github.com/facebook/react' ,
376+ image : 'https://avatars.githubusercontent.com/u/69631?v=4' ,
377+ } ,
378+ } ;
379+
380+ const { result } = renderHook (
381+ ( ) => useUserExperienceForm ( { defaultValues : openSourceExperience } ) ,
382+ { wrapper : createWrapper ( ) } ,
383+ ) ;
384+
385+ await act ( async ( ) => {
386+ const isValid = await result . current . methods . trigger ( 'repository' ) ;
387+ expect ( isValid ) . toBe ( true ) ;
388+ } ) ;
389+ } ) ;
390+
391+ it ( 'should require repository URL even for custom repositories' , async ( ) => {
392+ const openSourceExperience : BaseUserExperience & {
393+ repository ?: {
394+ id : string | null ;
395+ owner : string | null ;
396+ name : string ;
397+ url : string | null ;
398+ image : string | null ;
399+ } ;
400+ } = {
401+ type : UserExperienceType . OpenSource ,
402+ title : 'Open Source Contributor' ,
403+ startedAt : new Date ( '2023-01-01' ) ,
404+ current : true ,
405+ repository : {
406+ id : null ,
407+ owner : 'myorg' ,
408+ name : 'myrepo' ,
409+ url : null , // Missing URL should fail validation
410+ image : null ,
411+ } ,
412+ } ;
413+
414+ const { result } = renderHook (
415+ ( ) => useUserExperienceForm ( { defaultValues : openSourceExperience } ) ,
416+ { wrapper : createWrapper ( ) } ,
417+ ) ;
418+
419+ await act ( async ( ) => {
420+ const isValid = await result . current . methods . trigger ( 'repository' ) ;
421+ // Should be invalid without URL
422+ expect ( isValid ) . toBe ( false ) ;
423+ } ) ;
424+ } ) ;
319425} ) ;
0 commit comments