@@ -12,6 +12,8 @@ import {
1212 validateAndNormalizeRepositoryUrl ,
1313} from '../org-billing'
1414
15+ import type { Logger } from '@codebuff/types/logger'
16+
1517// Mock the database
1618const mockGrants = [
1719 {
@@ -40,6 +42,13 @@ const mockGrants = [
4042 } ,
4143]
4244
45+ const logger : Logger = {
46+ debug : ( ) => { } ,
47+ error : ( ) => { } ,
48+ info : ( ) => { } ,
49+ warn : ( ) => { } ,
50+ }
51+
4352describe ( 'Organization Billing' , ( ) => {
4453 beforeAll ( ( ) => {
4554 mockModule ( '@codebuff/common/db' , ( ) => ( {
@@ -91,11 +100,12 @@ describe('Organization Billing', () => {
91100 const quotaResetDate = new Date ( '2024-01-01' )
92101 const now = new Date ( '2024-06-01' )
93102
94- const result = await calculateOrganizationUsageAndBalance (
103+ const result = await calculateOrganizationUsageAndBalance ( {
95104 organizationId,
96105 quotaResetDate,
97106 now,
98- )
107+ logger,
108+ } )
99109
100110 // Total positive balance: 800
101111 // Total debt: 100
@@ -126,11 +136,12 @@ describe('Organization Billing', () => {
126136 const quotaResetDate = new Date ( '2024-01-01' )
127137 const now = new Date ( '2024-06-01' )
128138
129- const result = await calculateOrganizationUsageAndBalance (
139+ const result = await calculateOrganizationUsageAndBalance ( {
130140 organizationId,
131141 quotaResetDate,
132142 now,
133- )
143+ logger,
144+ } )
134145
135146 expect ( result . balance . totalRemaining ) . toBe ( 0 )
136147 expect ( result . balance . totalDebt ) . toBe ( 0 )
@@ -211,10 +222,11 @@ describe('Organization Billing', () => {
211222 const organizationId = 'org-123'
212223 const creditsToConsume = 100
213224
214- const result = await consumeOrganizationCredits (
225+ const result = await consumeOrganizationCredits ( {
215226 organizationId,
216227 creditsToConsume,
217- )
228+ logger,
229+ } )
218230
219231 expect ( result . consumed ) . toBe ( 100 )
220232 expect ( result . fromPurchased ) . toBe ( 0 ) // Organization credits are not "purchased" type
@@ -231,13 +243,14 @@ describe('Organization Billing', () => {
231243
232244 // Should not throw
233245 await expect (
234- grantOrganizationCredits (
246+ grantOrganizationCredits ( {
235247 organizationId,
236248 userId,
237249 amount,
238250 operationId,
239251 description,
240- ) ,
252+ logger,
253+ } ) ,
241254 ) . resolves . toBeUndefined ( )
242255 } )
243256
@@ -264,13 +277,14 @@ describe('Organization Billing', () => {
264277
265278 // Should not throw, should handle gracefully
266279 await expect (
267- grantOrganizationCredits (
280+ grantOrganizationCredits ( {
268281 organizationId,
269282 userId,
270283 amount,
271284 operationId,
272285 description,
273- ) ,
286+ logger,
287+ } ) ,
274288 ) . resolves . toBeUndefined ( )
275289 } )
276290 } )
0 commit comments