72 lines
2.1 KiB
TypeScript
72 lines
2.1 KiB
TypeScript
import {
|
|
AD_REPOSITORY,
|
|
INPUT_DATETIME_TRANSFORMER,
|
|
} from '@modules/ad/ad.di-tokens';
|
|
import { UpdateAdCommand } from '@modules/ad/core/application/commands/update-ad/update-ad.command';
|
|
import { UpdateAdService } from '@modules/ad/core/application/commands/update-ad/update-ad.service';
|
|
import { AdEntity } from '@modules/ad/core/domain/ad.entity';
|
|
import { Status } from '@modules/ad/core/domain/ad.types';
|
|
import { EventEmitter2 } from '@nestjs/event-emitter';
|
|
import { Test, TestingModule } from '@nestjs/testing';
|
|
import { mockInputDateTimeTransformer } from '../ad.mocks';
|
|
import { punctualCreateAdRequest } from '../interface/ad.fixtures';
|
|
import { punctualPassengerCreateAdProps } from './ad.fixtures';
|
|
|
|
const mockAdRepository = {
|
|
findOneById: jest.fn().mockImplementation(
|
|
async (id) =>
|
|
new AdEntity({
|
|
id,
|
|
props: { ...punctualPassengerCreateAdProps(), status: Status.VALID },
|
|
}),
|
|
),
|
|
update: jest.fn(),
|
|
};
|
|
|
|
const mockEventEmitter = {
|
|
emitAsync: jest.fn(),
|
|
};
|
|
|
|
describe('create-ad.service', () => {
|
|
let updateAdService: UpdateAdService;
|
|
|
|
beforeAll(async () => {
|
|
const module: TestingModule = await Test.createTestingModule({
|
|
providers: [
|
|
{
|
|
provide: AD_REPOSITORY,
|
|
useValue: mockAdRepository,
|
|
},
|
|
{
|
|
provide: INPUT_DATETIME_TRANSFORMER,
|
|
useValue: mockInputDateTimeTransformer(),
|
|
},
|
|
{
|
|
provide: EventEmitter2,
|
|
useValue: mockEventEmitter,
|
|
},
|
|
UpdateAdService,
|
|
],
|
|
}).compile();
|
|
|
|
updateAdService = module.get<UpdateAdService>(UpdateAdService);
|
|
});
|
|
|
|
it('should be defined', () => {
|
|
expect(updateAdService).toBeDefined();
|
|
});
|
|
|
|
describe('execute', () => {
|
|
it('should update the ad in the repository and emit an event', async () => {
|
|
const command = new UpdateAdCommand({
|
|
adId: '200d61a8-d878-4378-a609-c19ea71633d2',
|
|
...punctualCreateAdRequest(),
|
|
});
|
|
|
|
await updateAdService.execute(command);
|
|
expect(mockAdRepository.update).toHaveBeenCalled();
|
|
expect(mockEventEmitter.emitAsync).toHaveBeenCalled();
|
|
});
|
|
});
|
|
});
|