@@ -82,9 +82,14 @@ describe("auth", () => {
8282
8383 it ( "should return null when token is expired" , async ( ) => {
8484 const expiredTokenData : OidcTokenData = {
85+ id : "expired-token-id" ,
86+ createdAt : new Date ( ) ,
87+ updatedAt : new Date ( ) ,
88+ providerId : "provider-id" ,
89+ accountId : "account-id" ,
8590 accessToken : "expired-token" ,
8691 userId : "user-123" ,
87- expiresAt : Date . now ( ) - 1000 , // Expired 1 second ago
92+ accessTokenExpiresAt : Date . now ( ) - 1000 , // Expired 1 second ago
8893 } ;
8994
9095 const encryptedPayload = await encrypt (
@@ -102,9 +107,14 @@ describe("auth", () => {
102107
103108 it ( "should return null when token belongs to different user" , async ( ) => {
104109 const tokenData : OidcTokenData = {
110+ id : "valid-token-id" ,
111+ createdAt : new Date ( ) ,
112+ updatedAt : new Date ( ) ,
113+ providerId : "provider-id" ,
114+ accountId : "account-id" ,
105115 accessToken : "valid-token" ,
106116 userId : "user-456" , // Different user
107- expiresAt : Date . now ( ) + 3600000 ,
117+ accessTokenExpiresAt : Date . now ( ) + 3600000 ,
108118 } ;
109119
110120 const encryptedPayload = await encrypt (
@@ -120,9 +130,14 @@ describe("auth", () => {
120130
121131 it ( "should return access token when valid" , async ( ) => {
122132 const tokenData : OidcTokenData = {
133+ id : "valid-token-id" ,
134+ createdAt : new Date ( ) ,
135+ updatedAt : new Date ( ) ,
136+ providerId : "provider-id" ,
137+ accountId : "account-id" ,
123138 accessToken : "valid-access-token-123" ,
124139 userId : "user-123" ,
125- expiresAt : Date . now ( ) + 3600000 , // Valid for 1 hour
140+ accessTokenExpiresAt : Date . now ( ) + 3600000 , // Valid for 1 hour
126141 } ;
127142
128143 const encryptedPayload = await encrypt (
@@ -138,7 +153,7 @@ describe("auth", () => {
138153
139154 it ( "should return null when token data is invalid" , async ( ) => {
140155 // Create invalid token data (missing required fields)
141- const invalidData = { accessToken : "token" } ; // Missing userId and expiresAt
156+ const invalidData = { accessToken : "token" } ; // Missing userId and accessTokenExpiresAt
142157 const invalidPayload = await encrypt (
143158 invalidData as OidcTokenData ,
144159 process . env . BETTER_AUTH_SECRET as string ,
@@ -181,26 +196,36 @@ describe("auth", () => {
181196 describe ( "OidcTokenData Type Guard" , ( ) => {
182197 it ( "should validate correct OidcTokenData structure" , ( ) => {
183198 const validData : OidcTokenData = {
199+ id : "valid-token-id" ,
200+ createdAt : new Date ( ) ,
201+ updatedAt : new Date ( ) ,
202+ providerId : "provider-id" ,
203+ accountId : "account-id" ,
184204 accessToken : "token" ,
185205 userId : "user-123" ,
186- expiresAt : Date . now ( ) + 3600000 ,
206+ accessTokenExpiresAt : Date . now ( ) + 3600000 ,
187207 refreshToken : "refresh-token" ,
188208 } ;
189209
190210 // Type guard is private, so we test indirectly through getOidcProviderAccessToken
191211 expect ( validData ) . toHaveProperty ( "accessToken" ) ;
192212 expect ( validData ) . toHaveProperty ( "userId" ) ;
193- expect ( validData ) . toHaveProperty ( "expiresAt " ) ;
213+ expect ( validData ) . toHaveProperty ( "accessTokenExpiresAt " ) ;
194214 expect ( typeof validData . accessToken ) . toBe ( "string" ) ;
195215 expect ( typeof validData . userId ) . toBe ( "string" ) ;
196- expect ( typeof validData . expiresAt ) . toBe ( "number" ) ;
216+ expect ( typeof validData . accessTokenExpiresAt ) . toBe ( "number" ) ;
197217 } ) ;
198218
199219 it ( "should handle optional refreshToken" , ( ) => {
200220 const dataWithoutRefresh : OidcTokenData = {
221+ id : "valid-token-id" ,
222+ createdAt : new Date ( ) ,
223+ updatedAt : new Date ( ) ,
224+ providerId : "provider-id" ,
225+ accountId : "account-id" ,
201226 accessToken : "token" ,
202227 userId : "user-123" ,
203- expiresAt : Date . now ( ) + 3600000 ,
228+ accessTokenExpiresAt : Date . now ( ) + 3600000 ,
204229 } ;
205230
206231 expect ( dataWithoutRefresh . refreshToken ) . toBeUndefined ( ) ;
0 commit comments