refactor racing use cases
This commit is contained in:
@@ -1,18 +1,35 @@
|
||||
import { describe, it, expect, beforeEach } from 'vitest';
|
||||
import { GetSponsorshipPricingUseCase } from './GetSponsorshipPricingUseCase';
|
||||
import { describe, it, expect, beforeEach, vi } from 'vitest';
|
||||
import {
|
||||
GetSponsorshipPricingUseCase,
|
||||
GetSponsorshipPricingResult,
|
||||
GetSponsorshipPricingInput,
|
||||
GetSponsorshipPricingErrorCode,
|
||||
} from './GetSponsorshipPricingUseCase';
|
||||
import type { UseCaseOutputPort } from '@core/shared/application';
|
||||
import type { ApplicationErrorCode } from '@core/shared/errors/ApplicationErrorCode';
|
||||
|
||||
describe('GetSponsorshipPricingUseCase', () => {
|
||||
let useCase: GetSponsorshipPricingUseCase;
|
||||
let output: UseCaseOutputPort<GetSponsorshipPricingResult> & { present: ReturnType<typeof vi.fn> };
|
||||
|
||||
beforeEach(() => {
|
||||
useCase = new GetSponsorshipPricingUseCase();
|
||||
output = { present: vi.fn() } as unknown as UseCaseOutputPort<
|
||||
GetSponsorshipPricingResult
|
||||
> & { present: ReturnType<typeof vi.fn> };
|
||||
useCase = new GetSponsorshipPricingUseCase(output);
|
||||
});
|
||||
|
||||
it('should return sponsorship pricing tiers', async () => {
|
||||
const result = await useCase.execute();
|
||||
it('should present sponsorship pricing tiers', async () => {
|
||||
const input: GetSponsorshipPricingInput = {};
|
||||
|
||||
const result = await useCase.execute(input);
|
||||
|
||||
expect(result.isOk()).toBe(true);
|
||||
expect(result.unwrap()).toEqual({
|
||||
expect(result.unwrap()).toBeUndefined();
|
||||
expect(output.present).toHaveBeenCalledTimes(1);
|
||||
expect(output.present).toHaveBeenCalledWith({
|
||||
entityType: 'season',
|
||||
entityId: '',
|
||||
pricing: [
|
||||
{ id: 'tier-bronze', level: 'Bronze', price: 100, currency: 'USD' },
|
||||
{ id: 'tier-silver', level: 'Silver', price: 250, currency: 'USD' },
|
||||
@@ -20,4 +37,25 @@ describe('GetSponsorshipPricingUseCase', () => {
|
||||
],
|
||||
});
|
||||
});
|
||||
|
||||
it('should return repository error when execution fails', async () => {
|
||||
const error = new Error('Something went wrong');
|
||||
const failingUseCase = new GetSponsorshipPricingUseCase({
|
||||
present: () => {
|
||||
throw error;
|
||||
},
|
||||
} as unknown as UseCaseOutputPort<GetSponsorshipPricingResult>);
|
||||
|
||||
const input: GetSponsorshipPricingInput = {};
|
||||
|
||||
const result = await failingUseCase.execute(input);
|
||||
|
||||
expect(result.isErr()).toBe(true);
|
||||
const err = result.unwrapErr() as ApplicationErrorCode<
|
||||
GetSponsorshipPricingErrorCode,
|
||||
{ message: string }
|
||||
>;
|
||||
expect(err.code).toBe('REPOSITORY_ERROR');
|
||||
expect(err.details.message).toBe('Something went wrong');
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user