Skip to content

Commit

Permalink
Merge pull request #226 from TogetherCrew/debug-hivemind-adapter
Browse files Browse the repository at this point in the history
chore: update logs
  • Loading branch information
Behzad-rabiei authored Nov 7, 2024
2 parents 2031349 + cce01c4 commit a837f0b
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 1 deletion.
40 changes: 40 additions & 0 deletions hivemind-adapter/src/bot-adapter/bot.adapter.service.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// src/bot-adapter/bot.adapter.service.spec.ts
import { Test, TestingModule } from '@nestjs/testing'
import { LoggerModule } from 'nestjs-pino'
import { RabbitMQService } from '../rabbitmq/rabbitmq.service'
import { BotAdapterService } from './bot.adapter.service'
import { PlatformService } from '../platform/platform.service'

const mockRabbitMQHost = 'mock-rabbitmq-host'
const mockRabbitMQPort = 'mock-rabbitmq-port'
const mockRabbitMQUser = 'mock-rabbitmq-user'
const mockRabbitMQPassword = 'mock-rabbitmq-password'

const mockRabbitMQService = {
get: jest.fn((key: string) => {
if (key === 'rabbitMQ.host') return mockRabbitMQHost
if (key === 'rabbitMQ.port') return mockRabbitMQPort
if (key === 'rabbitMQ.user') return mockRabbitMQUser
if (key === 'rabbitMQ.password') return mockRabbitMQPassword
}),
}

describe('BotAdapterService', () => {
let service: BotAdapterService
beforeAll(async () => {
const module: TestingModule = await Test.createTestingModule({
imports: [LoggerModule.forRoot()],
providers: [
BotAdapterService,
PlatformService,
{ provide: RabbitMQService, useValue: mockRabbitMQService },
],
}).compile()

service = module.get<BotAdapterService>(BotAdapterService)
})

it('should be defined', () => {
expect(service).toBeDefined()
})
})
2 changes: 1 addition & 1 deletion hivemind-adapter/src/bot-adapter/bot.adapter.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export class BotAdapterService {
})
const data = this.adaptDataToHivemind(interaction, platform.community)
this.rabbitMQService.publish(Queue.HIVEMIND, Event.HIVEMIND.QUESTION_RECEIVED, { ...data })
this.logger.info(msg, `QUESTION_COMMAND_RECEIVED event is processed`)
this.logger.info(data, `QUESTION_COMMAND_RECEIVED event is processed`)
}

private adaptDataToHivemind(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// src/hivemind-adapter/hivemind.adapter.service.spec.ts
import { Test, TestingModule } from '@nestjs/testing'
import { LoggerModule } from 'nestjs-pino'
import { HivemindAdapterService } from './hivemind.adapter.service'
import { RabbitMQService } from '../rabbitmq/rabbitmq.service'

const mockRabbitMQHost = 'mock-rabbitmq-host'
const mockRabbitMQPort = 'mock-rabbitmq-port'
const mockRabbitMQUser = 'mock-rabbitmq-user'
const mockRabbitMQPassword = 'mock-rabbitmq-password'

const mockRabbitMQService = {
get: jest.fn((key: string) => {
if (key === 'rabbitMQ.host') return mockRabbitMQHost
if (key === 'rabbitMQ.port') return mockRabbitMQPort
if (key === 'rabbitMQ.user') return mockRabbitMQUser
if (key === 'rabbitMQ.password') return mockRabbitMQPassword
}),
}

describe('HivemindAdapterService', () => {
let service: HivemindAdapterService
beforeAll(async () => {
const module: TestingModule = await Test.createTestingModule({
imports: [LoggerModule.forRoot()],
providers: [HivemindAdapterService, { provide: RabbitMQService, useValue: mockRabbitMQService }],
}).compile()

service = module.get<HivemindAdapterService>(HivemindAdapterService)
})

it('should be defined', () => {
expect(service).toBeDefined()
})
})

0 comments on commit a837f0b

Please sign in to comment.