Merge branch 'messagerConstants' into 'main'
Messager constants See merge request v3/service/ad!22
This commit is contained in:
		
						commit
						b472aeaf05
					
				| 
						 | 
				
			
			@ -1,12 +1,12 @@
 | 
			
		|||
{
 | 
			
		||||
  "name": "@mobicoop/ad",
 | 
			
		||||
  "version": "2.1.0",
 | 
			
		||||
  "version": "2.1.1",
 | 
			
		||||
  "lockfileVersion": 3,
 | 
			
		||||
  "requires": true,
 | 
			
		||||
  "packages": {
 | 
			
		||||
    "": {
 | 
			
		||||
      "name": "@mobicoop/ad",
 | 
			
		||||
      "version": "2.1.0",
 | 
			
		||||
      "version": "2.1.1",
 | 
			
		||||
      "license": "AGPL",
 | 
			
		||||
      "dependencies": {
 | 
			
		||||
        "@grpc/grpc-js": "^1.8.14",
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,6 +1,6 @@
 | 
			
		|||
{
 | 
			
		||||
  "name": "@mobicoop/ad",
 | 
			
		||||
  "version": "2.1.0",
 | 
			
		||||
  "version": "2.1.1",
 | 
			
		||||
  "description": "Mobicoop V3 Ad",
 | 
			
		||||
  "author": "sbriat",
 | 
			
		||||
  "private": true,
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -0,0 +1,2 @@
 | 
			
		|||
export const SERVICE_NAME = 'ad';
 | 
			
		||||
export const HEALTH_CRITICAL_LOGGING_KEY = 'logging.ad.health.crit';
 | 
			
		||||
| 
						 | 
				
			
			@ -13,6 +13,7 @@ import { AD_REPOSITORY } from '@modules/ad/ad.di-tokens';
 | 
			
		|||
import { MESSAGE_PUBLISHER } from '@modules/messager/messager.di-tokens';
 | 
			
		||||
import { HealthModuleOptions } from '@mobicoop/health-module/dist/core/domain/types/health.types';
 | 
			
		||||
import { MessagePublisherPort } from '@mobicoop/ddd-library';
 | 
			
		||||
import { HEALTH_CRITICAL_LOGGING_KEY, SERVICE_NAME } from './app.constants';
 | 
			
		||||
 | 
			
		||||
@Module({
 | 
			
		||||
  imports: [
 | 
			
		||||
| 
						 | 
				
			
			@ -47,8 +48,8 @@ import { MessagePublisherPort } from '@mobicoop/ddd-library';
 | 
			
		|||
        adRepository: HealthRepositoryPort,
 | 
			
		||||
        messagePublisher: MessagePublisherPort,
 | 
			
		||||
      ): Promise<HealthModuleOptions> => ({
 | 
			
		||||
        serviceName: 'ad',
 | 
			
		||||
        criticalLoggingKey: 'logging.ad.health.crit',
 | 
			
		||||
        serviceName: SERVICE_NAME,
 | 
			
		||||
        criticalLoggingKey: HEALTH_CRITICAL_LOGGING_KEY,
 | 
			
		||||
        checkRepositories: [
 | 
			
		||||
          {
 | 
			
		||||
            name: 'AdRepository',
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -0,0 +1 @@
 | 
			
		|||
export const MESSAGER_AD_CREATED_ROUTING_KEY = 'ad.created';
 | 
			
		||||
| 
						 | 
				
			
			@ -3,6 +3,7 @@ import { OnEvent } from '@nestjs/event-emitter';
 | 
			
		|||
import { AdCreatedDomainEvent } from '../../domain/events/ad-created.domain-events';
 | 
			
		||||
import { MessagePublisherPort } from '@mobicoop/ddd-library';
 | 
			
		||||
import { AD_MESSAGE_PUBLISHER } from '@modules/ad/ad.di-tokens';
 | 
			
		||||
import { MESSAGER_AD_CREATED_ROUTING_KEY } from '@modules/ad/ad.constants';
 | 
			
		||||
 | 
			
		||||
@Injectable()
 | 
			
		||||
export class PublishMessageWhenAdIsCreatedDomainEventHandler {
 | 
			
		||||
| 
						 | 
				
			
			@ -13,6 +14,9 @@ export class PublishMessageWhenAdIsCreatedDomainEventHandler {
 | 
			
		|||
 | 
			
		||||
  @OnEvent(AdCreatedDomainEvent.name, { async: true, promisify: true })
 | 
			
		||||
  async handle(event: AdCreatedDomainEvent): Promise<any> {
 | 
			
		||||
    this.messagePublisher.publish('ad.created', JSON.stringify(event));
 | 
			
		||||
    this.messagePublisher.publish(
 | 
			
		||||
      MESSAGER_AD_CREATED_ROUTING_KEY,
 | 
			
		||||
      JSON.stringify(event),
 | 
			
		||||
    );
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -3,6 +3,7 @@ import { PublishMessageWhenAdIsCreatedDomainEventHandler } from '@modules/ad/cor
 | 
			
		|||
import { AdCreatedDomainEvent } from '@modules/ad/core/domain/events/ad-created.domain-events';
 | 
			
		||||
import { Test, TestingModule } from '@nestjs/testing';
 | 
			
		||||
import { AD_MESSAGE_PUBLISHER } from '@modules/ad/ad.di-tokens';
 | 
			
		||||
import { MESSAGER_AD_CREATED_ROUTING_KEY } from '@modules/ad/ad.constants';
 | 
			
		||||
 | 
			
		||||
const mockMessagePublisher = {
 | 
			
		||||
  publish: jest.fn().mockImplementation(),
 | 
			
		||||
| 
						 | 
				
			
			@ -80,7 +81,7 @@ describe('Publish message when ad is created domain event handler', () => {
 | 
			
		|||
    expect(publishMessageWhenAdIsCreatedDomainEventHandler).toBeDefined();
 | 
			
		||||
    expect(mockMessagePublisher.publish).toHaveBeenCalledTimes(1);
 | 
			
		||||
    expect(mockMessagePublisher.publish).toHaveBeenCalledWith(
 | 
			
		||||
      'ad.created',
 | 
			
		||||
      MESSAGER_AD_CREATED_ROUTING_KEY,
 | 
			
		||||
      '{"id":"some-domain-event-id","aggregateId":"some-aggregate-id","userId":"some-user-id","driver":false,"passenger":true,"frequency":"PUNCTUAL","fromDate":"2023-06-28","toDate":"2023-06-28","schedule":[{"day":3,"time":"07:15","margin":900}],"seatsProposed":3,"seatsRequested":1,"strict":false,"waypoints":[{"position":0,"houseNumber":"5","street":"Avenue Foch","locality":"Nancy","postalCode":"54000","country":"France","lat":48.689445,"lon":6.1765102},{"position":1,"locality":"Paris","postalCode":"75000","country":"France","lat":48.8566,"lon":2.3522}],"metadata":{"timestamp":1687928400000,"correlationId":"some-correlation-id"}}',
 | 
			
		||||
    );
 | 
			
		||||
  });
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -6,6 +6,7 @@ import {
 | 
			
		|||
  MessageBrokerPublisher,
 | 
			
		||||
} from '@mobicoop/message-broker-module';
 | 
			
		||||
import { ConfigModule, ConfigService } from '@nestjs/config';
 | 
			
		||||
import { SERVICE_NAME } from '@src/app.constants';
 | 
			
		||||
 | 
			
		||||
const imports = [
 | 
			
		||||
  MessageBrokerModule.forRootAsync({
 | 
			
		||||
| 
						 | 
				
			
			@ -16,7 +17,7 @@ const imports = [
 | 
			
		|||
    ): Promise<MessageBrokerModuleOptions> => ({
 | 
			
		||||
      uri: configService.get<string>('MESSAGE_BROKER_URI'),
 | 
			
		||||
      exchange: configService.get<string>('MESSAGE_BROKER_EXCHANGE'),
 | 
			
		||||
      name: 'ad',
 | 
			
		||||
      name: SERVICE_NAME,
 | 
			
		||||
    }),
 | 
			
		||||
  }),
 | 
			
		||||
];
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue