@@ -19,6 +19,7 @@ describe('createClientUatCookie', () => {
1919 const mockCookieSuffix = 'test-suffix' ;
2020 const mockExpires = new Date ( '2024-12-31' ) ;
2121 const mockDomain = 'test.domain' ;
22+ const defaultOptions = { usePartitionedCookies : ( ) => false } ;
2223 const mockSet = vi . fn ( ) ;
2324 const mockRemove = vi . fn ( ) ;
2425 const mockGet = vi . fn ( ) ;
@@ -39,14 +40,14 @@ describe('createClientUatCookie', () => {
3940 } ) ;
4041
4142 it ( 'should create both suffixed and non-suffixed cookie handlers' , ( ) => {
42- createClientUatCookie ( mockCookieSuffix ) ;
43+ createClientUatCookie ( mockCookieSuffix , defaultOptions ) ;
4344 expect ( createCookieHandler ) . toHaveBeenCalledTimes ( 2 ) ;
4445 expect ( createCookieHandler ) . toHaveBeenCalledWith ( '__client_uat' ) ;
4546 expect ( createCookieHandler ) . toHaveBeenCalledWith ( '__client_uat_test-suffix' ) ;
4647 } ) ;
4748
4849 it ( 'should set cookies with correct parameters in non-cross-origin context' , ( ) => {
49- const cookieHandler = createClientUatCookie ( mockCookieSuffix ) ;
50+ const cookieHandler = createClientUatCookie ( mockCookieSuffix , defaultOptions ) ;
5051 cookieHandler . set ( {
5152 id : 'test-client' ,
5253 updatedAt : new Date ( '2024-01-01' ) ,
@@ -65,7 +66,7 @@ describe('createClientUatCookie', () => {
6566
6667 it ( 'should set cookies with None sameSite in cross-origin context' , ( ) => {
6768 ( inCrossOriginIframe as ReturnType < typeof vi . fn > ) . mockReturnValue ( true ) ;
68- const cookieHandler = createClientUatCookie ( mockCookieSuffix ) ;
69+ const cookieHandler = createClientUatCookie ( mockCookieSuffix , defaultOptions ) ;
6970 cookieHandler . set ( {
7071 id : 'test-client' ,
7172 updatedAt : new Date ( '2024-01-01' ) ,
@@ -82,7 +83,7 @@ describe('createClientUatCookie', () => {
8283 } ) ;
8384
8485 it ( 'should set value to 0 when client is undefined' , ( ) => {
85- const cookieHandler = createClientUatCookie ( mockCookieSuffix ) ;
86+ const cookieHandler = createClientUatCookie ( mockCookieSuffix , defaultOptions ) ;
8687 cookieHandler . set ( undefined ) ;
8788
8889 expect ( mockSet ) . toHaveBeenCalledWith ( '0' , {
@@ -95,7 +96,7 @@ describe('createClientUatCookie', () => {
9596 } ) ;
9697
9798 it ( 'should set value to 0 when client has no signed in sessions' , ( ) => {
98- const cookieHandler = createClientUatCookie ( mockCookieSuffix ) ;
99+ const cookieHandler = createClientUatCookie ( mockCookieSuffix , defaultOptions ) ;
99100 cookieHandler . set ( {
100101 id : 'test-client' ,
101102 updatedAt : new Date ( '2024-01-01' ) ,
@@ -114,7 +115,7 @@ describe('createClientUatCookie', () => {
114115 it ( 'should get cookie value from suffixed cookie first, then fallback to non-suffixed' , ( ) => {
115116 mockGet . mockImplementationOnce ( ( ) => '1234567890' ) . mockImplementationOnce ( ( ) => '9876543210' ) ;
116117
117- const cookieHandler = createClientUatCookie ( mockCookieSuffix ) ;
118+ const cookieHandler = createClientUatCookie ( mockCookieSuffix , defaultOptions ) ;
118119 const result = cookieHandler . get ( ) ;
119120
120121 expect ( result ) . toBe ( 1234567890 ) ;
@@ -123,15 +124,15 @@ describe('createClientUatCookie', () => {
123124 it ( 'should return 0 when no cookie value is present' , ( ) => {
124125 mockGet . mockImplementationOnce ( ( ) => undefined ) . mockImplementationOnce ( ( ) => undefined ) ;
125126
126- const cookieHandler = createClientUatCookie ( mockCookieSuffix ) ;
127+ const cookieHandler = createClientUatCookie ( mockCookieSuffix , defaultOptions ) ;
127128 const result = cookieHandler . get ( ) ;
128129
129130 expect ( result ) . toBe ( 0 ) ;
130131 } ) ;
131132
132133 it ( 'should set cookies with SameSite=None when the host requires it' , ( ) => {
133134 ( requiresSameSiteNone as ReturnType < typeof vi . fn > ) . mockReturnValue ( true ) ;
134- const cookieHandler = createClientUatCookie ( mockCookieSuffix ) ;
135+ const cookieHandler = createClientUatCookie ( mockCookieSuffix , defaultOptions ) ;
135136 cookieHandler . set ( {
136137 id : 'test-client' ,
137138 updatedAt : new Date ( '2024-01-01' ) ,
@@ -146,4 +147,21 @@ describe('createClientUatCookie', () => {
146147 partitioned : false ,
147148 } ) ;
148149 } ) ;
150+
151+ it ( 'should set partitioned cookies when usePartitionedCookies returns true' , ( ) => {
152+ const cookieHandler = createClientUatCookie ( mockCookieSuffix , { usePartitionedCookies : ( ) => true } ) ;
153+ cookieHandler . set ( {
154+ id : 'test-client' ,
155+ updatedAt : new Date ( '2024-01-01' ) ,
156+ signedInSessions : [ 'session1' ] ,
157+ } ) ;
158+
159+ expect ( mockSet ) . toHaveBeenCalledWith ( '1704067200' , {
160+ domain : mockDomain ,
161+ expires : mockExpires ,
162+ sameSite : 'None' ,
163+ secure : true ,
164+ partitioned : true ,
165+ } ) ;
166+ } ) ;
149167} ) ;
0 commit comments