@@ -70,6 +70,7 @@ jest.mock('@cardano-sdk/projection-typeorm', () => {
70
70
} ) ;
71
71
72
72
describe ( 'PgBossHttpService' , ( ) => {
73
+ const apiUrl = new URL ( 'http://unused/' ) ;
73
74
let connectionConfig$ : Observable < PgConnectionConfig > ;
74
75
let connectionConfig : PgConnectionConfig ;
75
76
let dataSource : DataSource ;
@@ -98,9 +99,37 @@ describe('PgBossHttpService', () => {
98
99
db = pool ;
99
100
} ) ;
100
101
101
- afterEach ( async ( ) => {
102
- await service ?. shutdown ( ) ;
103
- await dataSource . destroy ( ) . catch ( ( ) => void 0 ) ;
102
+ describe ( 'without existing database' , ( ) => {
103
+ describe ( 'initialize' , ( ) => {
104
+ it ( 'throws an error and does not initialize pgboss schema' , async ( ) => {
105
+ service = new PgBossHttpService (
106
+ {
107
+ apiUrl,
108
+ dbCacheTtl : 0 ,
109
+ lastRosEpochs : 10 ,
110
+ metadataFetchMode : StakePoolMetadataFetchMode . DIRECT ,
111
+ parallelJobs : 3 ,
112
+ queues : [ ] ,
113
+ schedules : [ ]
114
+ } ,
115
+ { connectionConfig$, db, logger }
116
+ ) ;
117
+ await expect ( async ( ) => {
118
+ await service ! . initialize ( ) ;
119
+ await service ! . start ( ) ;
120
+ } ) . rejects . toThrowError ( ) ;
121
+ const pool = new Pool ( {
122
+ // most of the props are the same as for typeorm
123
+ ...connectionConfig ,
124
+ ssl : undefined ,
125
+ user : connectionConfig . username
126
+ } ) ;
127
+ const pgbossSchema = await pool . query (
128
+ "SELECT schema_name FROM information_schema.schemata WHERE schema_name = 'pgboss'"
129
+ ) ;
130
+ expect ( pgbossSchema . rowCount ) . toBe ( 0 ) ;
131
+ } ) ;
132
+ } ) ;
104
133
} ) ;
105
134
106
135
describe ( 'with existing database' , ( ) => {
@@ -115,10 +144,15 @@ describe('PgBossHttpService', () => {
115
144
await dataSource . initialize ( ) ;
116
145
} ) ;
117
146
147
+ afterEach ( async ( ) => {
148
+ await service ?. shutdown ( ) ;
149
+ await dataSource . destroy ( ) . catch ( ( ) => void 0 ) ;
150
+ } ) ;
151
+
118
152
it ( 'health check is ok after start with a valid db connection' , async ( ) => {
119
153
service = new PgBossHttpService (
120
154
{
121
- apiUrl : new URL ( 'http://unused/' ) ,
155
+ apiUrl,
122
156
dbCacheTtl : 0 ,
123
157
lastRosEpochs : 10 ,
124
158
metadataFetchMode : StakePoolMetadataFetchMode . DIRECT ,
@@ -152,7 +186,7 @@ describe('PgBossHttpService', () => {
152
186
153
187
service = new PgBossHttpService (
154
188
{
155
- apiUrl : new URL ( 'http://unused/' ) ,
189
+ apiUrl,
156
190
dbCacheTtl : 0 ,
157
191
lastRosEpochs : 10 ,
158
192
metadataFetchMode : StakePoolMetadataFetchMode . DIRECT ,
0 commit comments