33 */
44
55import { sealingKeyId } from '@sim/security/encryption'
6- import { databaseMockFns } from '@sim/testing'
7- import { afterEach , beforeEach , describe , expect , it , vi } from 'vitest'
6+ import { databaseMockFns } from '@sim/testing/mocks/database.mock '
7+ import { beforeEach , describe , expect , it , vi } from 'vitest'
88
99const { mockPostgres } = vi . hoisted ( ( ) => ( { mockPostgres : vi . fn ( ) } ) )
1010
1111vi . mock ( 'postgres' , ( ) => ( { default : mockPostgres } ) )
1212/** The pass derives each column's sealing context from the real column definitions. */
1313vi . unmock ( '@sim/db/schema' )
1414
15- import { runSealAccountTokens } from '@/background/seal-account-tokens'
15+ import {
16+ runSealAccountTokens ,
17+ type SealAccountTokensPayload ,
18+ } from '@/background/seal-account-tokens'
1619
1720const ENCRYPTION_KEY = 'ab' . repeat ( 32 )
1821const WORKER_KEY_ID = sealingKeyId ( Buffer . from ( ENCRYPTION_KEY , 'hex' ) )
@@ -31,17 +34,20 @@ describe('runSealAccountTokens', () => {
3134 mockPostgres . mockImplementation ( emptyAccountTable )
3235 } )
3336
34- afterEach ( ( ) => {
35- vi . unstubAllEnvs ( )
36- } )
37-
3837 it ( 'refuses a real seal under a key id other than the worker’s, before connecting' , async ( ) => {
3938 await expect (
4039 runSealAccountTokens ( { mode : 'seal' , dryRun : false , expectedKeyId : 'deadbeef' } )
4140 ) . rejects . toThrow ( `ENCRYPTION_KEY has key id ${ WORKER_KEY_ID } , not the expected deadbeef` )
4241 expect ( mockPostgres ) . not . toHaveBeenCalled ( )
4342 } )
4443
44+ it ( 'refuses a payload without dryRun instead of treating it as a real run' , async ( ) => {
45+ const payload = { mode : 'seal' , expectedKeyId : WORKER_KEY_ID } as SealAccountTokensPayload
46+
47+ await expect ( runSealAccountTokens ( payload ) ) . rejects . toThrow ( 'dryRun must be a boolean' )
48+ expect ( mockPostgres ) . not . toHaveBeenCalled ( )
49+ } )
50+
4551 it ( 'refuses to seal while this worker writes plaintext tokens, before connecting' , async ( ) => {
4652 vi . stubEnv ( 'ENCRYPT_ACCOUNT_TOKENS' , 'false' )
4753
0 commit comments