@@ -142,92 +142,91 @@ async function expectDatabaseWithRecords(agent: Agent | TenantAgent) {
142142}
143143
144144describe ( 'Askar to Drizzle Migration' , ( ) => {
145- test . each ( [ 'sqlite' , 'postgres' ] as const ) (
146- '%s askar to drizzle successful migration and deletion' ,
147- async ( databaseType ) => {
148- const storeId = `askar ${ databaseType } to drizzle ${ databaseType } successful migration ${ Math . random ( ) } `
149-
150- const postgresDatabase = databaseType === 'postgres' ? await createDrizzlePostgresTestDatabase ( ) : undefined
151- const database = postgresDatabase ?. drizzle ?? ( await inMemoryDrizzleSqliteDatabase ( ) )
152-
153- const drizzleModule = new DrizzleStorageModule ( {
154- bundles : [ coreBundle , didcommBundle , actionMenuBundle , anoncredsBundle ] ,
155- database,
156- } )
157-
158- const askarModule = new AskarModule ( {
159- askar,
160- store : {
161- id : storeId ,
162- key : 'GfwU1DC7gEZNs3w41tjBiZYj7BNToDoFEqKY6wZXqs1A' ,
163- keyDerivationMethod : 'raw' ,
164- database : databaseType === 'postgres' ? askarPostgresStorageConfig : undefined ,
165- } ,
166- } )
145+ test . each ( [
146+ 'sqlite' ,
147+ 'postgres' ,
148+ ] as const ) ( '%s askar to drizzle successful migration and deletion' , async ( databaseType ) => {
149+ const storeId = `askar ${ databaseType } to drizzle ${ databaseType } successful migration ${ Math . random ( ) } `
167150
168- await pushDrizzleSchema ( drizzleModule )
151+ const postgresDatabase = databaseType === 'postgres' ? await createDrizzlePostgresTestDatabase ( ) : undefined
152+ const database = postgresDatabase ?. drizzle ?? ( await inMemoryDrizzleSqliteDatabase ( ) )
169153
170- const migrator = await AskarToDrizzleStorageMigrator . initialize ( {
171- drizzleModule,
172- askarModule,
173- agentDependencies,
174- logger : testLogger ,
175- } )
154+ const drizzleModule = new DrizzleStorageModule ( {
155+ bundles : [ coreBundle , didcommBundle , actionMenuBundle , anoncredsBundle ] ,
156+ database,
157+ } )
176158
177- const askarAgent = new Agent ( {
178- dependencies : agentDependencies ,
179- config : {
180- logger : testLogger ,
181- } ,
182- modules : {
183- askar : askarModule ,
184- w3cCredentials : new W3cCredentialsModule ( {
185- documentLoader : customDocumentLoader ,
186- } ) ,
187- } ,
188- } )
189- await askarAgent . initialize ( )
159+ const askarModule = new AskarModule ( {
160+ askar,
161+ store : {
162+ id : storeId ,
163+ key : 'GfwU1DC7gEZNs3w41tjBiZYj7BNToDoFEqKY6wZXqs1A' ,
164+ keyDerivationMethod : 'raw' ,
165+ database : databaseType === 'postgres' ? askarPostgresStorageConfig : undefined ,
166+ } ,
167+ } )
190168
191- await populateDatabaseWithRecords ( askarAgent )
169+ await pushDrizzleSchema ( drizzleModule )
192170
193- await migrator . migrate ( )
171+ const migrator = await AskarToDrizzleStorageMigrator . initialize ( {
172+ drizzleModule,
173+ askarModule,
174+ agentDependencies,
175+ logger : testLogger ,
176+ } )
194177
195- const drizzleAgent = new Agent ( {
196- dependencies : agentDependencies ,
197- config : {
198- logger : testLogger ,
199- } ,
200- modules : {
201- drizzle : drizzleModule ,
202- } ,
203- } )
204- await drizzleAgent . initialize ( )
178+ const drizzleAgent = new Agent ( {
179+ dependencies : agentDependencies ,
180+ config : {
181+ logger : testLogger ,
182+ } ,
183+ modules : {
184+ drizzle : drizzleModule ,
185+ } ,
186+ } )
187+ await drizzleAgent . initialize ( )
205188
206- // Now expect all the populated records to be available in the Drizzle database
207- await expectDatabaseWithRecords ( drizzleAgent )
189+ const askarAgent = new Agent ( {
190+ dependencies : agentDependencies ,
191+ config : {
192+ logger : testLogger ,
193+ } ,
194+ modules : {
195+ w3cCredentials : new W3cCredentialsModule ( {
196+ documentLoader : customDocumentLoader ,
197+ } ) ,
198+ askar : askarModule ,
199+ } ,
200+ } )
201+ await askarAgent . initialize ( )
208202
209- // We also still expect all the populated records to be available in the Askar database
210- await expectDatabaseWithRecords ( askarAgent )
203+ await populateDatabaseWithRecords ( askarAgent )
204+ await migrator . migrate ( )
211205
212- // After succesfull migration we delete the storage records
213- await migrator . deleteStorageRecords ( )
206+ // Now expect all the populated records to be available in the Drizzle database
207+ await expectDatabaseWithRecords ( drizzleAgent )
214208
215- // It should not have deleted the keys
216- expect ( await askarAgent . kms . getPublicKey ( { keyId : 'consistent-kid' } ) ) . toEqual ( {
217- crv : 'Ed25519' ,
218- kid : 'consistent-kid' ,
219- kty : 'OKP' ,
220- x : 'Df70zEA2tkZXPZxgc0KcM3s_vjut-PP_6QnM5AfLNfo' ,
221- } )
209+ // We also still expect all the populated records to be available in the Askar database
210+ await expectDatabaseWithRecords ( askarAgent )
222211
223- // But it should have deleted the other records
224- expect ( await askarAgent . genericRecords . getAll ( ) ) . toEqual ( [ ] )
212+ // After succesfull migration we delete the storage records
213+ await migrator . deleteStorageRecords ( )
214+
215+ // It should not have deleted the keys
216+ expect ( await askarAgent . kms . getPublicKey ( { keyId : 'consistent-kid' } ) ) . toEqual ( {
217+ crv : 'Ed25519' ,
218+ kid : 'consistent-kid' ,
219+ kty : 'OKP' ,
220+ x : 'Df70zEA2tkZXPZxgc0KcM3s_vjut-PP_6QnM5AfLNfo' ,
221+ } )
225222
226- await postgresDatabase ?. teardown ( )
227- await askarAgent . shutdown ( )
228- await drizzleAgent . shutdown ( )
229- }
230- )
223+ // But it should have deleted the other records
224+ expect ( await askarAgent . genericRecords . getAll ( ) ) . toEqual ( [ ] )
225+
226+ await postgresDatabase ?. teardown ( )
227+ await askarAgent . shutdown ( )
228+ await drizzleAgent . shutdown ( )
229+ } )
231230
232231 test . each ( [ 'sqlite' , 'postgres' ] ) ( '%s askar to drizzle with tenants successful migration' , async ( databaseType ) => {
233232 const storeId = `${ Math . random ( ) } askar ${ databaseType } to drizzle ${ databaseType } with tenants successful migration`
@@ -267,10 +266,10 @@ describe('Askar to Drizzle Migration', () => {
267266 logger : testLogger ,
268267 } ,
269268 modules : {
270- askar : askarModule ,
271269 w3cCredentials : new W3cCredentialsModule ( {
272270 documentLoader : customDocumentLoader ,
273271 } ) ,
272+ askar : askarModule ,
274273 tenants : new TenantsModule ( ) ,
275274 } ,
276275 } )
0 commit comments