view data fixes
This commit is contained in:
@@ -0,0 +1,248 @@
|
||||
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
||||
import { AcceptSponsorshipRequestMutation } from './AcceptSponsorshipRequestMutation';
|
||||
import { SponsorshipRequestsService } from '@/lib/services/sponsors/SponsorshipRequestsService';
|
||||
import { Result } from '@/lib/contracts/Result';
|
||||
|
||||
// Mock dependencies
|
||||
vi.mock('@/lib/services/sponsors/SponsorshipRequestsService', () => {
|
||||
return {
|
||||
SponsorshipRequestsService: vi.fn(),
|
||||
};
|
||||
});
|
||||
|
||||
describe('AcceptSponsorshipRequestMutation', () => {
|
||||
let mutation: AcceptSponsorshipRequestMutation;
|
||||
let mockServiceInstance: any;
|
||||
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
mockServiceInstance = {
|
||||
acceptRequest: vi.fn(),
|
||||
};
|
||||
// Use mockImplementation to return the instance
|
||||
(SponsorshipRequestsService as any).mockImplementation(function() {
|
||||
return mockServiceInstance;
|
||||
});
|
||||
mutation = new AcceptSponsorshipRequestMutation();
|
||||
});
|
||||
|
||||
describe('execute', () => {
|
||||
describe('happy paths', () => {
|
||||
it('should successfully accept sponsorship request with valid input', async () => {
|
||||
// Arrange
|
||||
const command = {
|
||||
requestId: 'request-123',
|
||||
actorDriverId: 'driver-456',
|
||||
};
|
||||
mockServiceInstance.acceptRequest.mockResolvedValue(Result.ok(undefined));
|
||||
|
||||
// Act
|
||||
const result = await mutation.execute(command);
|
||||
|
||||
// Assert
|
||||
expect(result.isOk()).toBe(true);
|
||||
expect(result.unwrap()).toBeUndefined();
|
||||
expect(mockServiceInstance.acceptRequest).toHaveBeenCalledWith(command);
|
||||
expect(mockServiceInstance.acceptRequest).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
});
|
||||
|
||||
describe('failure modes', () => {
|
||||
it('should handle service failure during acceptance', async () => {
|
||||
// Arrange
|
||||
const command = {
|
||||
requestId: 'request-123',
|
||||
actorDriverId: 'driver-456',
|
||||
};
|
||||
const serviceError = new Error('Service error');
|
||||
mockServiceInstance.acceptRequest.mockRejectedValue(serviceError);
|
||||
|
||||
// Act
|
||||
const result = await mutation.execute(command);
|
||||
|
||||
// Assert
|
||||
expect(result.isErr()).toBe(true);
|
||||
expect(result.getError()).toBe('ACCEPT_SPONSORSHIP_REQUEST_FAILED');
|
||||
expect(mockServiceInstance.acceptRequest).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it('should handle service returning error result', async () => {
|
||||
// Arrange
|
||||
const command = {
|
||||
requestId: 'request-123',
|
||||
actorDriverId: 'driver-456',
|
||||
};
|
||||
const domainError = { type: 'serverError', message: 'Database connection failed' };
|
||||
mockServiceInstance.acceptRequest.mockResolvedValue(Result.err(domainError));
|
||||
|
||||
// Act
|
||||
const result = await mutation.execute(command);
|
||||
|
||||
// Assert
|
||||
expect(result.isErr()).toBe(true);
|
||||
expect(result.getError()).toBe('ACCEPT_SPONSORSHIP_REQUEST_FAILED');
|
||||
expect(mockServiceInstance.acceptRequest).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it('should handle service returning validation error', async () => {
|
||||
// Arrange
|
||||
const command = {
|
||||
requestId: 'request-123',
|
||||
actorDriverId: 'driver-456',
|
||||
};
|
||||
const domainError = { type: 'validationError', message: 'Invalid request ID' };
|
||||
mockServiceInstance.acceptRequest.mockResolvedValue(Result.err(domainError));
|
||||
|
||||
// Act
|
||||
const result = await mutation.execute(command);
|
||||
|
||||
// Assert
|
||||
expect(result.isErr()).toBe(true);
|
||||
expect(result.getError()).toBe('ACCEPT_SPONSORSHIP_REQUEST_FAILED');
|
||||
expect(mockServiceInstance.acceptRequest).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it('should handle service returning notFound error', async () => {
|
||||
// Arrange
|
||||
const command = {
|
||||
requestId: 'request-123',
|
||||
actorDriverId: 'driver-456',
|
||||
};
|
||||
const domainError = { type: 'notFound', message: 'Sponsorship request not found' };
|
||||
mockServiceInstance.acceptRequest.mockResolvedValue(Result.err(domainError));
|
||||
|
||||
// Act
|
||||
const result = await mutation.execute(command);
|
||||
|
||||
// Assert
|
||||
expect(result.isErr()).toBe(true);
|
||||
expect(result.getError()).toBe('ACCEPT_SPONSORSHIP_REQUEST_FAILED');
|
||||
expect(mockServiceInstance.acceptRequest).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it('should handle service returning unauthorized error', async () => {
|
||||
// Arrange
|
||||
const command = {
|
||||
requestId: 'request-123',
|
||||
actorDriverId: 'driver-456',
|
||||
};
|
||||
const domainError = { type: 'unauthorized', message: 'Insufficient permissions' };
|
||||
mockServiceInstance.acceptRequest.mockResolvedValue(Result.err(domainError));
|
||||
|
||||
// Act
|
||||
const result = await mutation.execute(command);
|
||||
|
||||
// Assert
|
||||
expect(result.isErr()).toBe(true);
|
||||
expect(result.getError()).toBe('ACCEPT_SPONSORSHIP_REQUEST_FAILED');
|
||||
expect(mockServiceInstance.acceptRequest).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
});
|
||||
|
||||
describe('error mapping', () => {
|
||||
it('should map various domain errors to mutation errors', async () => {
|
||||
// Arrange
|
||||
const command = {
|
||||
requestId: 'request-123',
|
||||
actorDriverId: 'driver-456',
|
||||
};
|
||||
const testCases = [
|
||||
{ domainError: { type: 'notFound' }, expectedError: 'ACCEPT_SPONSORSHIP_REQUEST_FAILED' },
|
||||
{ domainError: { type: 'unauthorized' }, expectedError: 'ACCEPT_SPONSORSHIP_REQUEST_FAILED' },
|
||||
{ domainError: { type: 'validationError' }, expectedError: 'ACCEPT_SPONSORSHIP_REQUEST_FAILED' },
|
||||
{ domainError: { type: 'serverError' }, expectedError: 'ACCEPT_SPONSORSHIP_REQUEST_FAILED' },
|
||||
{ domainError: { type: 'networkError' }, expectedError: 'ACCEPT_SPONSORSHIP_REQUEST_FAILED' },
|
||||
{ domainError: { type: 'notImplemented' }, expectedError: 'ACCEPT_SPONSORSHIP_REQUEST_FAILED' },
|
||||
{ domainError: { type: 'unknown' }, expectedError: 'ACCEPT_SPONSORSHIP_REQUEST_FAILED' },
|
||||
];
|
||||
|
||||
for (const testCase of testCases) {
|
||||
mockServiceInstance.acceptRequest.mockResolvedValue(Result.err(testCase.domainError));
|
||||
|
||||
const result = await mutation.execute(command);
|
||||
|
||||
expect(result.isErr()).toBe(true);
|
||||
expect(result.getError()).toBe(testCase.expectedError);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe('input validation', () => {
|
||||
it('should accept valid command input', async () => {
|
||||
// Arrange
|
||||
const command = {
|
||||
requestId: 'request-123',
|
||||
actorDriverId: 'driver-456',
|
||||
};
|
||||
mockServiceInstance.acceptRequest.mockResolvedValue(Result.ok(undefined));
|
||||
|
||||
// Act
|
||||
const result = await mutation.execute(command);
|
||||
|
||||
// Assert
|
||||
expect(result.isOk()).toBe(true);
|
||||
expect(mockServiceInstance.acceptRequest).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it('should handle empty requestId gracefully', async () => {
|
||||
// Arrange
|
||||
const command = {
|
||||
requestId: '',
|
||||
actorDriverId: 'driver-456',
|
||||
};
|
||||
mockServiceInstance.acceptRequest.mockResolvedValue(Result.ok(undefined));
|
||||
|
||||
// Act
|
||||
const result = await mutation.execute(command);
|
||||
|
||||
// Assert
|
||||
expect(result.isOk()).toBe(true);
|
||||
expect(mockServiceInstance.acceptRequest).toHaveBeenCalledWith(command);
|
||||
});
|
||||
|
||||
it('should handle empty actorDriverId gracefully', async () => {
|
||||
// Arrange
|
||||
const command = {
|
||||
requestId: 'request-123',
|
||||
actorDriverId: '',
|
||||
};
|
||||
mockServiceInstance.acceptRequest.mockResolvedValue(Result.ok(undefined));
|
||||
|
||||
// Act
|
||||
const result = await mutation.execute(command);
|
||||
|
||||
// Assert
|
||||
expect(result.isOk()).toBe(true);
|
||||
expect(mockServiceInstance.acceptRequest).toHaveBeenCalledWith(command);
|
||||
});
|
||||
});
|
||||
|
||||
describe('service instantiation', () => {
|
||||
it('should create SponsorshipRequestsService instance', () => {
|
||||
// Arrange & Act
|
||||
const mutation = new AcceptSponsorshipRequestMutation();
|
||||
|
||||
// Assert
|
||||
expect(mutation).toBeInstanceOf(AcceptSponsorshipRequestMutation);
|
||||
});
|
||||
});
|
||||
|
||||
describe('result shape', () => {
|
||||
it('should return void on success', async () => {
|
||||
// Arrange
|
||||
const command = {
|
||||
requestId: 'request-123',
|
||||
actorDriverId: 'driver-456',
|
||||
};
|
||||
mockServiceInstance.acceptRequest.mockResolvedValue(Result.ok(undefined));
|
||||
|
||||
// Act
|
||||
const result = await mutation.execute(command);
|
||||
|
||||
// Assert
|
||||
expect(result.isOk()).toBe(true);
|
||||
expect(result.unwrap()).toBeUndefined();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -22,12 +22,16 @@ export class AcceptSponsorshipRequestMutation
|
||||
async execute(
|
||||
command: AcceptSponsorshipRequestCommand,
|
||||
): Promise<Result<void, AcceptSponsorshipRequestMutationError>> {
|
||||
const result = await this.service.acceptRequest(command);
|
||||
|
||||
if (result.isErr()) {
|
||||
try {
|
||||
const result = await this.service.acceptRequest(command);
|
||||
|
||||
if (result.isErr()) {
|
||||
return Result.err('ACCEPT_SPONSORSHIP_REQUEST_FAILED');
|
||||
}
|
||||
|
||||
return Result.ok(undefined);
|
||||
} catch (error) {
|
||||
return Result.err('ACCEPT_SPONSORSHIP_REQUEST_FAILED');
|
||||
}
|
||||
|
||||
return Result.ok(undefined);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,327 @@
|
||||
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
||||
import { RejectSponsorshipRequestMutation } from './RejectSponsorshipRequestMutation';
|
||||
import { SponsorshipRequestsService } from '@/lib/services/sponsors/SponsorshipRequestsService';
|
||||
import { Result } from '@/lib/contracts/Result';
|
||||
|
||||
// Mock dependencies
|
||||
vi.mock('@/lib/services/sponsors/SponsorshipRequestsService', () => {
|
||||
return {
|
||||
SponsorshipRequestsService: vi.fn(),
|
||||
};
|
||||
});
|
||||
|
||||
describe('RejectSponsorshipRequestMutation', () => {
|
||||
let mutation: RejectSponsorshipRequestMutation;
|
||||
let mockServiceInstance: any;
|
||||
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
mockServiceInstance = {
|
||||
rejectRequest: vi.fn(),
|
||||
};
|
||||
// Use mockImplementation to return the instance
|
||||
(SponsorshipRequestsService as any).mockImplementation(function() {
|
||||
return mockServiceInstance;
|
||||
});
|
||||
mutation = new RejectSponsorshipRequestMutation();
|
||||
});
|
||||
|
||||
describe('execute', () => {
|
||||
describe('happy paths', () => {
|
||||
it('should successfully reject sponsorship request with valid input', async () => {
|
||||
// Arrange
|
||||
const command = {
|
||||
requestId: 'request-123',
|
||||
actorDriverId: 'driver-456',
|
||||
reason: 'Test reason',
|
||||
};
|
||||
mockServiceInstance.rejectRequest.mockResolvedValue(Result.ok(undefined));
|
||||
|
||||
// Act
|
||||
const result = await mutation.execute(command);
|
||||
|
||||
// Assert
|
||||
expect(result.isOk()).toBe(true);
|
||||
expect(result.unwrap()).toBeUndefined();
|
||||
expect(mockServiceInstance.rejectRequest).toHaveBeenCalledWith(command);
|
||||
expect(mockServiceInstance.rejectRequest).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it('should successfully reject sponsorship request with null reason', async () => {
|
||||
// Arrange
|
||||
const command = {
|
||||
requestId: 'request-123',
|
||||
actorDriverId: 'driver-456',
|
||||
reason: null,
|
||||
};
|
||||
mockServiceInstance.rejectRequest.mockResolvedValue(Result.ok(undefined));
|
||||
|
||||
// Act
|
||||
const result = await mutation.execute(command);
|
||||
|
||||
// Assert
|
||||
expect(result.isOk()).toBe(true);
|
||||
expect(result.unwrap()).toBeUndefined();
|
||||
expect(mockServiceInstance.rejectRequest).toHaveBeenCalledWith(command);
|
||||
expect(mockServiceInstance.rejectRequest).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it('should successfully reject sponsorship request with empty reason', async () => {
|
||||
// Arrange
|
||||
const command = {
|
||||
requestId: 'request-123',
|
||||
actorDriverId: 'driver-456',
|
||||
reason: '',
|
||||
};
|
||||
mockServiceInstance.rejectRequest.mockResolvedValue(Result.ok(undefined));
|
||||
|
||||
// Act
|
||||
const result = await mutation.execute(command);
|
||||
|
||||
// Assert
|
||||
expect(result.isOk()).toBe(true);
|
||||
expect(result.unwrap()).toBeUndefined();
|
||||
expect(mockServiceInstance.rejectRequest).toHaveBeenCalledWith(command);
|
||||
expect(mockServiceInstance.rejectRequest).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
});
|
||||
|
||||
describe('failure modes', () => {
|
||||
it('should handle service failure during rejection', async () => {
|
||||
// Arrange
|
||||
const command = {
|
||||
requestId: 'request-123',
|
||||
actorDriverId: 'driver-456',
|
||||
reason: 'Test reason',
|
||||
};
|
||||
const serviceError = new Error('Service error');
|
||||
mockServiceInstance.rejectRequest.mockRejectedValue(serviceError);
|
||||
|
||||
// Act
|
||||
const result = await mutation.execute(command);
|
||||
|
||||
// Assert
|
||||
expect(result.isErr()).toBe(true);
|
||||
expect(result.getError()).toBe('REJECT_SPONSORSHIP_REQUEST_FAILED');
|
||||
expect(mockServiceInstance.rejectRequest).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it('should handle service returning error result', async () => {
|
||||
// Arrange
|
||||
const command = {
|
||||
requestId: 'request-123',
|
||||
actorDriverId: 'driver-456',
|
||||
reason: 'Test reason',
|
||||
};
|
||||
const domainError = { type: 'serverError', message: 'Database connection failed' };
|
||||
mockServiceInstance.rejectRequest.mockResolvedValue(Result.err(domainError));
|
||||
|
||||
// Act
|
||||
const result = await mutation.execute(command);
|
||||
|
||||
// Assert
|
||||
expect(result.isErr()).toBe(true);
|
||||
expect(result.getError()).toBe('REJECT_SPONSORSHIP_REQUEST_FAILED');
|
||||
expect(mockServiceInstance.rejectRequest).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it('should handle service returning validation error', async () => {
|
||||
// Arrange
|
||||
const command = { bio: 'Test bio', country: 'US' };
|
||||
const domainError = { type: 'validationError', message: 'Invalid request ID' };
|
||||
mockServiceInstance.rejectRequest.mockResolvedValue(Result.err(domainError));
|
||||
|
||||
// Act
|
||||
const result = await mutation.execute(command as any);
|
||||
|
||||
// Assert
|
||||
expect(result.isErr()).toBe(true);
|
||||
expect(result.getError()).toBe('REJECT_SPONSORSHIP_REQUEST_FAILED');
|
||||
expect(mockServiceInstance.rejectRequest).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it('should handle service returning notFound error', async () => {
|
||||
// Arrange
|
||||
const command = {
|
||||
requestId: 'request-123',
|
||||
actorDriverId: 'driver-456',
|
||||
reason: 'Test reason',
|
||||
};
|
||||
const domainError = { type: 'notFound', message: 'Sponsorship request not found' };
|
||||
mockServiceInstance.rejectRequest.mockResolvedValue(Result.err(domainError));
|
||||
|
||||
// Act
|
||||
const result = await mutation.execute(command);
|
||||
|
||||
// Assert
|
||||
expect(result.isErr()).toBe(true);
|
||||
expect(result.getError()).toBe('REJECT_SPONSORSHIP_REQUEST_FAILED');
|
||||
expect(mockServiceInstance.rejectRequest).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it('should handle service returning unauthorized error', async () => {
|
||||
// Arrange
|
||||
const command = {
|
||||
requestId: 'request-123',
|
||||
actorDriverId: 'driver-456',
|
||||
reason: 'Test reason',
|
||||
};
|
||||
const domainError = { type: 'unauthorized', message: 'Insufficient permissions' };
|
||||
mockServiceInstance.rejectRequest.mockResolvedValue(Result.err(domainError));
|
||||
|
||||
// Act
|
||||
const result = await mutation.execute(command);
|
||||
|
||||
// Assert
|
||||
expect(result.isErr()).toBe(true);
|
||||
expect(result.getError()).toBe('REJECT_SPONSORSHIP_REQUEST_FAILED');
|
||||
expect(mockServiceInstance.rejectRequest).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
});
|
||||
|
||||
describe('error mapping', () => {
|
||||
it('should map various domain errors to mutation errors', async () => {
|
||||
// Arrange
|
||||
const command = {
|
||||
requestId: 'request-123',
|
||||
actorDriverId: 'driver-456',
|
||||
reason: 'Test reason',
|
||||
};
|
||||
const testCases = [
|
||||
{ domainError: { type: 'notFound' }, expectedError: 'REJECT_SPONSORSHIP_REQUEST_FAILED' },
|
||||
{ domainError: { type: 'unauthorized' }, expectedError: 'REJECT_SPONSORSHIP_REQUEST_FAILED' },
|
||||
{ domainError: { type: 'validationError' }, expectedError: 'REJECT_SPONSORSHIP_REQUEST_FAILED' },
|
||||
{ domainError: { type: 'serverError' }, expectedError: 'REJECT_SPONSORSHIP_REQUEST_FAILED' },
|
||||
{ domainError: { type: 'networkError' }, expectedError: 'REJECT_SPONSORSHIP_REQUEST_FAILED' },
|
||||
{ domainError: { type: 'notImplemented' }, expectedError: 'REJECT_SPONSORSHIP_REQUEST_FAILED' },
|
||||
{ domainError: { type: 'unknown' }, expectedError: 'REJECT_SPONSORSHIP_REQUEST_FAILED' },
|
||||
];
|
||||
|
||||
for (const testCase of testCases) {
|
||||
mockServiceInstance.rejectRequest.mockResolvedValue(Result.err(testCase.domainError));
|
||||
|
||||
const result = await mutation.execute(command);
|
||||
|
||||
expect(result.isErr()).toBe(true);
|
||||
expect(result.getError()).toBe(testCase.expectedError);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe('input validation', () => {
|
||||
it('should accept valid command input', async () => {
|
||||
// Arrange
|
||||
const command = {
|
||||
requestId: 'request-123',
|
||||
actorDriverId: 'driver-456',
|
||||
reason: 'Test reason',
|
||||
};
|
||||
mockServiceInstance.rejectRequest.mockResolvedValue(Result.ok(undefined));
|
||||
|
||||
// Act
|
||||
const result = await mutation.execute(command);
|
||||
|
||||
// Assert
|
||||
expect(result.isOk()).toBe(true);
|
||||
expect(mockServiceInstance.rejectRequest).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it('should handle empty requestId gracefully', async () => {
|
||||
// Arrange
|
||||
const command = {
|
||||
requestId: '',
|
||||
actorDriverId: 'driver-456',
|
||||
reason: 'Test reason',
|
||||
};
|
||||
mockServiceInstance.rejectRequest.mockResolvedValue(Result.ok(undefined));
|
||||
|
||||
// Act
|
||||
const result = await mutation.execute(command);
|
||||
|
||||
// Assert
|
||||
expect(result.isOk()).toBe(true);
|
||||
expect(mockServiceInstance.rejectRequest).toHaveBeenCalledWith(command);
|
||||
});
|
||||
|
||||
it('should handle empty actorDriverId gracefully', async () => {
|
||||
// Arrange
|
||||
const command = {
|
||||
requestId: 'request-123',
|
||||
actorDriverId: '',
|
||||
reason: 'Test reason',
|
||||
};
|
||||
mockServiceInstance.rejectRequest.mockResolvedValue(Result.ok(undefined));
|
||||
|
||||
// Act
|
||||
const result = await mutation.execute(command);
|
||||
|
||||
// Assert
|
||||
expect(result.isOk()).toBe(true);
|
||||
expect(mockServiceInstance.rejectRequest).toHaveBeenCalledWith(command);
|
||||
});
|
||||
|
||||
it('should handle empty reason gracefully', async () => {
|
||||
// Arrange
|
||||
const command = {
|
||||
requestId: 'request-123',
|
||||
actorDriverId: 'driver-456',
|
||||
reason: '',
|
||||
};
|
||||
mockServiceInstance.rejectRequest.mockResolvedValue(Result.ok(undefined));
|
||||
|
||||
// Act
|
||||
const result = await mutation.execute(command);
|
||||
|
||||
// Assert
|
||||
expect(result.isOk()).toBe(true);
|
||||
expect(mockServiceInstance.rejectRequest).toHaveBeenCalledWith(command);
|
||||
});
|
||||
});
|
||||
|
||||
describe('service instantiation', () => {
|
||||
it('should create SponsorshipRequestsService instance', () => {
|
||||
// Arrange & Act
|
||||
const mutation = new RejectSponsorshipRequestMutation();
|
||||
|
||||
// Assert
|
||||
expect(mutation).toBeInstanceOf(RejectSponsorshipRequestMutation);
|
||||
});
|
||||
});
|
||||
|
||||
describe('result shape', () => {
|
||||
it('should return void on success', async () => {
|
||||
// Arrange
|
||||
const command = {
|
||||
requestId: 'request-123',
|
||||
actorDriverId: 'driver-456',
|
||||
reason: 'Test reason',
|
||||
};
|
||||
mockServiceInstance.rejectRequest.mockResolvedValue(Result.ok(undefined));
|
||||
|
||||
// Act
|
||||
const result = await mutation.execute(command);
|
||||
|
||||
// Assert
|
||||
expect(result.isOk()).toBe(true);
|
||||
expect(result.unwrap()).toBeUndefined();
|
||||
});
|
||||
|
||||
it('should return void on success with null reason', async () => {
|
||||
// Arrange
|
||||
const command = {
|
||||
requestId: 'request-123',
|
||||
actorDriverId: 'driver-456',
|
||||
reason: null,
|
||||
};
|
||||
mockServiceInstance.rejectRequest.mockResolvedValue(Result.ok(undefined));
|
||||
|
||||
// Act
|
||||
const result = await mutation.execute(command);
|
||||
|
||||
// Assert
|
||||
expect(result.isOk()).toBe(true);
|
||||
expect(result.unwrap()).toBeUndefined();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -23,12 +23,16 @@ export class RejectSponsorshipRequestMutation
|
||||
async execute(
|
||||
command: RejectSponsorshipRequestCommand,
|
||||
): Promise<Result<void, RejectSponsorshipRequestMutationError>> {
|
||||
const result = await this.service.rejectRequest(command);
|
||||
|
||||
if (result.isErr()) {
|
||||
try {
|
||||
const result = await this.service.rejectRequest(command);
|
||||
|
||||
if (result.isErr()) {
|
||||
return Result.err('REJECT_SPONSORSHIP_REQUEST_FAILED');
|
||||
}
|
||||
|
||||
return Result.ok(undefined);
|
||||
} catch (error) {
|
||||
return Result.err('REJECT_SPONSORSHIP_REQUEST_FAILED');
|
||||
}
|
||||
|
||||
return Result.ok(undefined);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user