1
+ /**
2
+ * @jest -environment ./packages/backend/jest.tigerbeetle-environment.ts
3
+ */
4
+
1
5
import assert from 'assert'
2
6
import { CreateAccountError as CreateTbAccountError } from 'tigerbeetle-node'
3
7
import { v4 as uuid } from 'uuid'
@@ -9,7 +13,6 @@ import { IocContract } from '@adonisjs/fold'
9
13
import { initIocContainer } from '../../'
10
14
import { AppServices } from '../../app'
11
15
import { truncateTables } from '../../tests/tableManager'
12
- import { startTigerbeetleContainer } from '../../tests/tigerbeetle'
13
16
import { AccountFactory , FactoryAccount } from '../../tests/accountFactory'
14
17
import { isTransferError , TransferError } from '../errors'
15
18
import {
@@ -20,7 +23,7 @@ import {
20
23
Withdrawal
21
24
} from '../service'
22
25
23
- describe ( 'Accounting Service' , ( ) : void => {
26
+ describe ( 'Tigerbeetle Accounting Service' , ( ) : void => {
24
27
let deps : IocContract < AppServices >
25
28
let appContainer : TestContainer
26
29
let accountingService : AccountingService
@@ -33,10 +36,14 @@ describe('Accounting Service', (): void => {
33
36
}
34
37
35
38
beforeAll ( async ( ) : Promise < void > => {
36
- const { port } = await startTigerbeetleContainer ( )
37
- Config . tigerbeetleReplicaAddresses = [ port . toString ( ) ]
39
+ const tigerbeetlePort = ( global as unknown as { tigerbeetlePort : number } )
40
+ . tigerbeetlePort
38
41
39
- deps = await initIocContainer ( { ...Config , useTigerbeetle : true } )
42
+ deps = initIocContainer ( {
43
+ ...Config ,
44
+ tigerbeetleReplicaAddresses : [ tigerbeetlePort . toString ( ) ] ,
45
+ useTigerbeetle : true
46
+ } )
40
47
appContainer = await createTestApp ( deps )
41
48
accountingService = await deps . use ( 'accountingService' )
42
49
accountFactory = new AccountFactory ( accountingService , newLedger )
@@ -48,7 +55,6 @@ describe('Accounting Service', (): void => {
48
55
49
56
afterAll ( async ( ) : Promise < void > => {
50
57
await appContainer . shutdown ( )
51
- // TODO: find a way to gracefully stop TB container without running into a thread panic
52
58
} )
53
59
54
60
describe ( 'Create Liquidity Account' , ( ) : void => {
@@ -83,11 +89,11 @@ describe('Accounting Service', (): void => {
83
89
} ,
84
90
LiquidityAccountType . ASSET
85
91
)
86
- ) . rejects . toThrowError ( 'unable to create account, invalid id' )
92
+ ) . rejects . toThrow ( 'unable to create account, invalid id' )
87
93
} )
88
94
89
95
test ( 'Create throws on error' , async ( ) : Promise < void > => {
90
- const tigerbeetle = await deps . use ( 'tigerbeetle' )
96
+ const tigerbeetle = await deps . use ( 'tigerbeetle' ) !
91
97
jest . spyOn ( tigerbeetle , 'createAccounts' ) . mockResolvedValueOnce ( [
92
98
{
93
99
index : 0 ,
@@ -106,7 +112,7 @@ describe('Accounting Service', (): void => {
106
112
} ,
107
113
LiquidityAccountType . ASSET
108
114
)
109
- ) . rejects . toThrowError (
115
+ ) . rejects . toThrow (
110
116
new TigerbeetleCreateAccountError (
111
117
CreateTbAccountError . exists_with_different_ledger
112
118
)
0 commit comments