@@ -6,12 +6,14 @@ import { inCrossOriginIframe } from '../../../../utils';
66import { getCookieDomain } from '../../getCookieDomain' ;
77import { getSecureAttribute } from '../../getSecureAttribute' ;
88import { createClientUatCookie } from '../clientUat' ;
9+ import { requiresSameSiteNone } from '../requireSameSiteNone' ;
910
1011vi . mock ( '@clerk/shared/cookie' ) ;
1112vi . mock ( '@clerk/shared/date' ) ;
1213vi . mock ( '../../../../utils' ) ;
1314vi . mock ( '../../getCookieDomain' ) ;
1415vi . mock ( '../../getSecureAttribute' ) ;
16+ vi . mock ( '../requireSameSiteNone' ) ;
1517
1618describe ( 'createClientUatCookie' , ( ) => {
1719 const mockCookieSuffix = 'test-suffix' ;
@@ -26,6 +28,7 @@ describe('createClientUatCookie', () => {
2628 mockGet . mockReset ( ) ;
2729 ( addYears as ReturnType < typeof vi . fn > ) . mockReturnValue ( mockExpires ) ;
2830 ( inCrossOriginIframe as ReturnType < typeof vi . fn > ) . mockReturnValue ( false ) ;
31+ ( requiresSameSiteNone as ReturnType < typeof vi . fn > ) . mockReturnValue ( false ) ;
2932 ( getCookieDomain as ReturnType < typeof vi . fn > ) . mockReturnValue ( mockDomain ) ;
3033 ( getSecureAttribute as ReturnType < typeof vi . fn > ) . mockReturnValue ( true ) ;
3134 ( createCookieHandler as ReturnType < typeof vi . fn > ) . mockImplementation ( ( ) => ( {
@@ -125,4 +128,22 @@ describe('createClientUatCookie', () => {
125128
126129 expect ( result ) . toBe ( 0 ) ;
127130 } ) ;
131+
132+ it ( 'should set cookies with SameSite=None when the host requires it' , ( ) => {
133+ ( requiresSameSiteNone as ReturnType < typeof vi . fn > ) . mockReturnValue ( true ) ;
134+ const cookieHandler = createClientUatCookie ( mockCookieSuffix ) ;
135+ cookieHandler . set ( {
136+ id : 'test-client' ,
137+ updatedAt : new Date ( '2024-01-01' ) ,
138+ signedInSessions : [ 'session1' ] ,
139+ } ) ;
140+
141+ expect ( mockSet ) . toHaveBeenCalledWith ( '1704067200' , {
142+ domain : mockDomain ,
143+ expires : mockExpires ,
144+ sameSite : 'None' ,
145+ secure : true ,
146+ partitioned : false ,
147+ } ) ;
148+ } ) ;
128149} ) ;
0 commit comments