@@ -78,6 +78,43 @@ describe("Authentication Configurations", () => {
7878 } ) ;
7979
8080 expectSuccess ( result ) ;
81+ expect ( result . projectDir ) . toBeDefined ( ) ;
82+ const projectDir = result . projectDir as string ;
83+ const authPackageJson = await fs . readJson (
84+ path . join ( projectDir , "packages/auth/package.json" ) ,
85+ ) ;
86+ expect ( authPackageJson . dependencies . mongodb ) . toBe ( "^7.2.0" ) ;
87+
88+ const dbIndex = await fs . readFile ( path . join ( projectDir , "packages/db/src/index.ts" ) , "utf8" ) ;
89+ expect ( dbIndex ) . toContain ( "await mongoose.connect(env.DATABASE_URL);" ) ;
90+ expect ( dbIndex ) . toContain ( "mongoose.connection.getClient().db()" ) ;
91+ expect ( dbIndex ) . not . toContain ( ".catch(" ) ;
92+ expect ( dbIndex ) . not . toContain ( "myDB" ) ;
93+
94+ const todosRoute = await fs . readFile (
95+ path . join ( projectDir , "apps/web/src/routes/todos.tsx" ) ,
96+ "utf8" ,
97+ ) ;
98+ expect ( todosRoute ) . toContain ( "type TodoId = string" ) ;
99+ expect ( todosRoute ) . toContain ( "const handleToggleTodo = (id: TodoId" ) ;
100+ expect ( todosRoute ) . toContain ( "const handleDeleteTodo = (id: TodoId" ) ;
101+
102+ const todoRouter = await fs . readFile (
103+ path . join ( projectDir , "packages/api/src/routers/todo.ts" ) ,
104+ "utf8" ,
105+ ) ;
106+ expect ( todoRouter ) . toContain ( 'import "@better-auth-mongodb/db";' ) ;
107+ expect ( todoRouter ) . toContain ( "id: todo.id.toString()" ) ;
108+
109+ const authModels = await fs . readFile (
110+ path . join ( projectDir , "packages/db/src/models/auth.model.ts" ) ,
111+ "utf8" ,
112+ ) ;
113+ expect ( authModels ) . toContain ( "const { ObjectId } = Schema.Types" ) ;
114+ expect ( authModels ) . toContain ( "_id: { type: ObjectId, auto: true }" ) ;
115+ expect ( authModels ) . toContain ( 'userId: { type: ObjectId, ref: "User", required: true }' ) ;
116+ expect ( authModels ) . toContain ( "sessionSchema.index({ userId: 1 })" ) ;
117+ expect ( authModels ) . toContain ( "verificationSchema.index({ identifier: 1 })" ) ;
81118 } ) ;
82119
83120 it ( "should add nextCookies plugin for Next.js self backend" , async ( ) => {
@@ -187,6 +224,50 @@ describe("Authentication Configurations", () => {
187224 } ) ;
188225
189226 expectSuccess ( result ) ;
227+ if ( ! result . projectDir ) {
228+ throw new Error ( "Expected projectDir to be defined" ) ;
229+ }
230+
231+ const packageJson = await fs . readJson ( path . join ( result . projectDir , "package.json" ) ) ;
232+ const backendPackageJson = await fs . readJson (
233+ path . join ( result . projectDir , "packages/backend/package.json" ) ,
234+ ) ;
235+ const webPackageJson = await fs . readJson (
236+ path . join ( result . projectDir , "apps/web/package.json" ) ,
237+ ) ;
238+ const authFile = await fs . readFile (
239+ path . join ( result . projectDir , "packages/backend/convex/auth.ts" ) ,
240+ "utf8" ,
241+ ) ;
242+ const httpFile = await fs . readFile (
243+ path . join ( result . projectDir , "packages/backend/convex/http.ts" ) ,
244+ "utf8" ,
245+ ) ;
246+ const authClientFile = await fs . readFile (
247+ path . join ( result . projectDir , "apps/web/src/lib/auth-client.ts" ) ,
248+ "utf8" ,
249+ ) ;
250+ const convexTsconfig = await fs . readFile (
251+ path . join ( result . projectDir , "packages/backend/convex/tsconfig.json" ) ,
252+ "utf8" ,
253+ ) ;
254+ const convexEnvFile = await fs . readFile (
255+ path . join ( result . projectDir , "packages/backend/.env.local" ) ,
256+ "utf8" ,
257+ ) ;
258+
259+ expect ( packageJson . workspaces . catalog [ "better-auth" ] ) . toBe ( "~1.6.9" ) ;
260+ expect ( packageJson . workspaces . catalog [ "@convex-dev/better-auth" ] ) . toBe ( "^0.12.2" ) ;
261+ expect ( backendPackageJson . dependencies [ "better-auth" ] ) . toBe ( "catalog:" ) ;
262+ expect ( webPackageJson . dependencies [ "better-auth" ] ) . toBe ( "catalog:" ) ;
263+ expect ( authFile ) . toContain ( "baseURL: process.env.CONVEX_SITE_URL" ) ;
264+ expect ( httpFile ) . toContain ( "authComponent.registerRoutes(http, createAuth, { cors: true })" ) ;
265+ expect ( authClientFile ) . toContain ( "plugins: [convexClient(), crossDomainClient()]" ) ;
266+ expect ( convexTsconfig ) . toContain ( '"types": ["node"]' ) ;
267+ expect ( convexEnvFile ) . toContain (
268+ "# npx convex env set CONVEX_SITE_URL https://<YOUR_CONVEX_SITE_URL>" ,
269+ ) ;
270+ expect ( convexEnvFile ) . toContain ( "# CONVEX_SITE_URL=" ) ;
190271 } ) ;
191272
192273 it ( "should scaffold react-router with Convex Better Auth wiring" , async ( ) => {
@@ -227,7 +308,7 @@ describe("Authentication Configurations", () => {
227308
228309 expect ( rootFile ) . toContain ( "ConvexBetterAuthProvider" ) ;
229310 expect ( rootFile ) . toContain ( 'import { authClient } from "@/lib/auth-client";' ) ;
230- expect ( authClientFile ) . toContain ( "crossDomainClient (), convexClient ()" ) ;
311+ expect ( authClientFile ) . toContain ( "convexClient (), crossDomainClient ()" ) ;
231312 expect ( dashboardFile ) . toContain ( "Authenticated" ) ;
232313 expect ( dashboardFile ) . toContain ( "Unauthenticated" ) ;
233314 } ) ;
0 commit comments