1- import { describe , it , expect , vi , beforeEach , afterEach } from "vitest" ;
1+ import { describe , it , expect , vi } from "vitest" ;
2+
23vi . mock ( "~/env.server" , ( ) => ( {
3- env : { } ,
4+ env : {
5+ RUN_REPLICATION_ENABLED : "0" ,
6+ RUN_REPLICATION_CLICKHOUSE_URL : undefined ,
7+ DATABASE_CONNECTION_LIMIT : 10 ,
8+ DATABASE_POOL_TIMEOUT : 60 ,
9+ DATABASE_CONNECTION_TIMEOUT : 20 ,
10+ } ,
411} ) ) ;
12+
513vi . mock ( "~/db.server" , ( ) => ( {
614 prisma : { } ,
715 $replica : { } ,
@@ -12,69 +20,51 @@ import type { ClickHouse } from "@internal/clickhouse";
1220import type { PrismaClient } from "@trigger.dev/database" ;
1321
1422describe ( "createRunsRepository" , ( ) => {
15- let mockClickhouse : ClickHouse ;
16- let mockPrisma : PrismaClient ;
17- let originalEnv : Record < string , unknown > ;
18-
19- beforeEach ( async ( ) => {
20- const envModule = await import ( "~/env.server" ) ;
21- originalEnv = { ...envModule . env } ;
22-
23- mockClickhouse = { } as ClickHouse ;
24- mockPrisma = { } as PrismaClient ;
25- } ) ;
26-
27- afterEach ( async ( ) => {
28- const envModule = await import ( "~/env.server" ) ;
29- Object . assign ( envModule . env , originalEnv ) ;
30- } ) ;
31-
32- it ( "should default to postgres when RUN_REPLICATION_ENABLED is not set" , async ( ) => {
33- const envModule = await import ( "~/env.server" ) ;
34- envModule . env . RUN_REPLICATION_ENABLED = "0" ;
35- envModule . env . RUN_REPLICATION_CLICKHOUSE_URL = "http://localhost:8123" ;
23+ const mockClickhouse = { } as ClickHouse ;
24+ const mockPrisma = { } as PrismaClient ;
3625
26+ it ( "should default to postgres when replication is disabled" , ( ) => {
3727 const repository = createRunsRepository ( {
3828 clickhouse : mockClickhouse ,
3929 prisma : mockPrisma ,
30+ isReplicationEnabled : false ,
31+ isClickHouseConfigured : true ,
4032 } ) ;
4133
4234 expect ( repository ) . toBeDefined ( ) ;
4335 expect ( repository . listRuns ) . toBeDefined ( ) ;
4436 } ) ;
4537
46- it ( "should default to postgres when RUN_REPLICATION_CLICKHOUSE_URL is not set" , async ( ) => {
47- const envModule = await import ( "~/env.server" ) ;
48- envModule . env . RUN_REPLICATION_ENABLED = "1" ;
49- envModule . env . RUN_REPLICATION_CLICKHOUSE_URL = undefined ;
50-
38+ it ( "should default to postgres when ClickHouse is not configured" , ( ) => {
5139 const repository = createRunsRepository ( {
5240 clickhouse : mockClickhouse ,
5341 prisma : mockPrisma ,
42+ isReplicationEnabled : true ,
43+ isClickHouseConfigured : false ,
5444 } ) ;
5545
5646 expect ( repository ) . toBeDefined ( ) ;
5747 expect ( repository . listRuns ) . toBeDefined ( ) ;
5848 } ) ;
5949
60- it ( "should default to clickhouse when both conditions are met" , async ( ) => {
61- const envModule = await import ( "~/env.server" ) ;
62- envModule . env . RUN_REPLICATION_ENABLED = "1" ;
63- envModule . env . RUN_REPLICATION_CLICKHOUSE_URL = "http://localhost:8123" ;
64-
50+ it ( "should default to clickhouse when both conditions are met" , ( ) => {
6551 const repository = createRunsRepository ( {
6652 clickhouse : mockClickhouse ,
6753 prisma : mockPrisma ,
54+ isReplicationEnabled : true ,
55+ isClickHouseConfigured : true ,
6856 } ) ;
6957
7058 expect ( repository ) . toBeDefined ( ) ;
7159 expect ( repository . listRuns ) . toBeDefined ( ) ;
7260 } ) ;
7361
74- it ( "should create a valid RunsRepository instance" , ( ) => {
62+ it ( "should create a valid RunsRepository instance with all required methods " , ( ) => {
7563 const repository = createRunsRepository ( {
7664 clickhouse : mockClickhouse ,
7765 prisma : mockPrisma ,
66+ isReplicationEnabled : false ,
67+ isClickHouseConfigured : false ,
7868 } ) ;
7969
8070 expect ( repository . listRuns ) . toBeDefined ( ) ;
0 commit comments