22 clearMockedModules ,
33 mockModule ,
44} from '@codebuff/common/testing/mock-modules'
5- import { afterAll , afterEach , beforeAll , describe , expect , it } from 'bun:test'
5+ import { afterEach , beforeEach , describe , expect , it } from 'bun:test'
66
77import {
88 calculateOrganizationUsageAndBalance ,
@@ -80,12 +80,11 @@ const createDbMock = (options?: {
8080}
8181
8282describe ( 'Organization Billing' , ( ) => {
83- beforeAll ( async ( ) => {
84- await mockModule ( '@codebuff/common /db' , ( ) => ( {
83+ beforeEach ( async ( ) => {
84+ await mockModule ( '@codebuff/internal /db' , ( ) => ( {
8585 default : createDbMock ( ) ,
8686 } ) )
87-
88- await mockModule ( '@codebuff/common/db/transaction' , ( ) => ( {
87+ await mockModule ( '@codebuff/internal/db/transaction' , ( ) => ( {
8988 withSerializableTransaction : async ( {
9089 callback,
9190 } : {
@@ -94,16 +93,10 @@ describe('Organization Billing', () => {
9493 } ) )
9594 } )
9695
97- afterAll ( ( ) => {
96+ afterEach ( ( ) => {
9897 clearMockedModules ( )
9998 } )
10099
101- afterEach ( async ( ) => {
102- await mockModule ( '@codebuff/common/db' , ( ) => ( {
103- default : createDbMock ( ) ,
104- } ) )
105- } )
106-
107100 describe ( 'calculateOrganizationUsageAndBalance' , ( ) => {
108101 it ( 'should calculate balance correctly with positive and negative balances' , async ( ) => {
109102 const organizationId = 'org-123'
@@ -130,7 +123,7 @@ describe('Organization Billing', () => {
130123
131124 it ( 'should handle organization with no grants' , async ( ) => {
132125 // Mock empty grants
133- await mockModule ( '@codebuff/common /db' , ( ) => ( {
126+ await mockModule ( '@codebuff/internal /db' , ( ) => ( {
134127 default : createDbMock ( { grants : [ ] } ) ,
135128 } ) )
136129
@@ -258,7 +251,7 @@ describe('Organization Billing', () => {
258251
259252 it ( 'should handle duplicate operation IDs gracefully' , async ( ) => {
260253 // Mock database constraint error
261- await mockModule ( '@codebuff/common /db' , ( ) => ( {
254+ await mockModule ( '@codebuff/internal /db' , ( ) => ( {
262255 default : createDbMock ( {
263256 insert : ( ) => ( {
264257 values : ( ) => {
0 commit comments