mirror of
https://github.com/Memo-2023/mana-monorepo.git
synced 2026-05-14 20:01:09 +02:00
fix(auth): add GuildPoolService mock to credits unit tests
Fix credits.service.spec and credits.controller.spec which failed because CreditsService now depends on GuildPoolService. Add mock provider and update useCredits → useCreditsWithSource references. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
b16e245fe3
commit
3a133555b8
3 changed files with 27 additions and 12 deletions
|
|
@ -56,13 +56,10 @@ describe('CreditsController', () => {
|
|||
const mockCreditsService = {
|
||||
getBalance: jest.fn(),
|
||||
useCredits: jest.fn(),
|
||||
useCreditsWithSource: jest.fn(),
|
||||
getTransactionHistory: jest.fn(),
|
||||
getPurchaseHistory: jest.fn(),
|
||||
getPackages: jest.fn(),
|
||||
allocateCredits: jest.fn(),
|
||||
getOrganizationBalance: jest.fn(),
|
||||
getEmployeeCreditBalance: jest.fn(),
|
||||
deductCredits: jest.fn(),
|
||||
};
|
||||
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
|
|
@ -142,12 +139,15 @@ describe('CreditsController', () => {
|
|||
newBalance: 90,
|
||||
};
|
||||
|
||||
creditsService.useCredits.mockResolvedValue(expectedResult as any);
|
||||
creditsService.useCreditsWithSource.mockResolvedValue(expectedResult as any);
|
||||
|
||||
const result = await controller.useCredits(mockUser, useCreditsDto);
|
||||
|
||||
expect(result).toEqual(expectedResult);
|
||||
expect(creditsService.useCredits).toHaveBeenCalledWith(mockUser.userId, useCreditsDto);
|
||||
expect(creditsService.useCreditsWithSource).toHaveBeenCalledWith(
|
||||
mockUser.userId,
|
||||
useCreditsDto
|
||||
);
|
||||
});
|
||||
|
||||
it('should pass idempotency key for duplicate prevention', async () => {
|
||||
|
|
@ -159,11 +159,11 @@ describe('CreditsController', () => {
|
|||
idempotencyKey,
|
||||
});
|
||||
|
||||
creditsService.useCredits.mockResolvedValue({ success: true } as any);
|
||||
creditsService.useCreditsWithSource.mockResolvedValue({ success: true } as any);
|
||||
|
||||
await controller.useCredits(mockUser, useCreditsDto);
|
||||
|
||||
expect(creditsService.useCredits).toHaveBeenCalledWith(
|
||||
expect(creditsService.useCreditsWithSource).toHaveBeenCalledWith(
|
||||
mockUser.userId,
|
||||
expect.objectContaining({ idempotencyKey })
|
||||
);
|
||||
|
|
@ -176,7 +176,7 @@ describe('CreditsController', () => {
|
|||
description: 'Image generation',
|
||||
});
|
||||
|
||||
creditsService.useCredits.mockRejectedValue(
|
||||
creditsService.useCreditsWithSource.mockRejectedValue(
|
||||
new BadRequestException('Insufficient credits')
|
||||
);
|
||||
|
||||
|
|
@ -197,11 +197,11 @@ describe('CreditsController', () => {
|
|||
},
|
||||
});
|
||||
|
||||
creditsService.useCredits.mockResolvedValue({ success: true } as any);
|
||||
creditsService.useCreditsWithSource.mockResolvedValue({ success: true } as any);
|
||||
|
||||
await controller.useCredits(mockUser, useCreditsDto);
|
||||
|
||||
expect(creditsService.useCredits).toHaveBeenCalledWith(
|
||||
expect(creditsService.useCreditsWithSource).toHaveBeenCalledWith(
|
||||
mockUser.userId,
|
||||
expect.objectContaining({
|
||||
metadata: {
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ import { ConfigService } from '@nestjs/config';
|
|||
import { BadRequestException, NotFoundException, ConflictException } from '@nestjs/common';
|
||||
import { CreditsService } from './credits.service';
|
||||
import { StripeService } from '../stripe/stripe.service';
|
||||
import { GuildPoolService } from './guild-pool.service';
|
||||
import { createMockConfigService } from '../__tests__/utils/test-helpers';
|
||||
import {
|
||||
mockUserFactory,
|
||||
|
|
@ -74,6 +75,17 @@ describe('CreditsService', () => {
|
|||
handleWebhook: jest.fn(),
|
||||
};
|
||||
|
||||
const mockGuildPoolService = {
|
||||
initializeGuildPool: jest.fn(),
|
||||
getGuildPoolBalance: jest.fn(),
|
||||
fundGuildPool: jest.fn(),
|
||||
useGuildCredits: jest.fn(),
|
||||
getGuildTransactions: jest.fn(),
|
||||
setSpendingLimit: jest.fn(),
|
||||
getSpendingLimits: jest.fn(),
|
||||
getMemberSpendingSummary: jest.fn(),
|
||||
};
|
||||
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
providers: [
|
||||
CreditsService,
|
||||
|
|
@ -85,6 +97,10 @@ describe('CreditsService', () => {
|
|||
provide: StripeService,
|
||||
useValue: mockStripeService,
|
||||
},
|
||||
{
|
||||
provide: GuildPoolService,
|
||||
useValue: mockGuildPoolService,
|
||||
},
|
||||
],
|
||||
}).compile();
|
||||
|
||||
|
|
|
|||
|
|
@ -23,7 +23,6 @@ export class CreditsService {
|
|||
private configService: ConfigService,
|
||||
@Inject(forwardRef(() => StripeService))
|
||||
private stripeService: StripeService,
|
||||
@Inject(forwardRef(() => GuildPoolService))
|
||||
private guildPoolService: GuildPoolService
|
||||
) {}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue