Skip to content

Commit

Permalink
Test
Browse files Browse the repository at this point in the history
  • Loading branch information
icemedia001 committed Jan 28, 2025
1 parent 531f8c9 commit c8c4536
Showing 1 changed file with 73 additions and 73 deletions.
146 changes: 73 additions & 73 deletions src/App/utils/discordWebhookHandler.spec.ts
Original file line number Diff line number Diff line change
@@ -1,83 +1,83 @@
// import { Test, TestingModule } from '@nestjs/testing'
// import { HttpService } from '@nestjs/axios'
// import { ConfigService } from '@nestjs/config'
// import { DataSource } from 'typeorm'
// import WebhookHandler from './discordWebhookHandler'
// import { ActionTypes } from './utilTypes'
import { Test, TestingModule } from '@nestjs/testing'
import { HttpService } from '@nestjs/axios'
import { ConfigService } from '@nestjs/config'
import { DataSource } from 'typeorm'
import WebhookHandler from './discordWebhookHandler'
import { ActionTypes } from './utilTypes'

// describe('WebhookHandler', () => {
// let webhookHandler: WebhookHandler
// let httpService: HttpService
// let configService: ConfigService
// // let dataSource: DataSource
describe('WebhookHandler', () => {
let webhookHandler: WebhookHandler
let httpService: HttpService
let configService: ConfigService
// let dataSource: DataSource

// beforeEach(async () => {
// const module: TestingModule = await Test.createTestingModule({
// providers: [
// WebhookHandler,
// {
// provide: HttpService,
// useValue: {
// post: jest.fn(),
// },
// },
// {
// provide: ConfigService,
// useValue: {
// get: jest.fn(),
// },
// },
// {
// provide: DataSource,
// useValue: {
// getRepository: jest.fn().mockReturnValue({
// findOneBy: jest.fn(),
// find: jest.fn(),
// }),
// },
// },
// ],
// }).compile()
beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
providers: [
WebhookHandler,
{
provide: HttpService,
useValue: {
post: jest.fn(),
},
},
{
provide: ConfigService,
useValue: {
get: jest.fn(),
},
},
{
provide: DataSource,
useValue: {
getRepository: jest.fn().mockReturnValue({
findOneBy: jest.fn(),
find: jest.fn(),
}),
},
},
],
}).compile()

// webhookHandler = module.get<WebhookHandler>(WebhookHandler)
// httpService = module.get<HttpService>(HttpService)
// configService = module.get<ConfigService>(ConfigService)
// // dataSource = module.get<DataSource>(DataSource)
// })
webhookHandler = module.get<WebhookHandler>(WebhookHandler)
httpService = module.get<HttpService>(HttpService)
configService = module.get<ConfigService>(ConfigService)
// dataSource = module.get<DataSource>(DataSource)
})

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

// it('should handle ADMIN_ACTION correctly', async () => {
// const payload = {
// user: 'testUser',
// adminAction: 'HIDE_WIKI',
// urlId: '123',
// }
// jest.spyOn(configService, 'get').mockReturnValue('{}')
// jest.spyOn(httpService, 'post').mockReturnValue({
// subscribe: jest.fn(),
// } as any)
// it('should handle ADMIN_ACTION correctly', async () => {
// const payload = {
// user: 'testUser',
// adminAction: 'HIDE_WIKI',
// urlId: '123',
// }
// jest.spyOn(configService, 'get').mockReturnValue('{}')
// jest.spyOn(httpService, 'post').mockReturnValue({
// subscribe: jest.fn(),
// } as any)

// await webhookHandler.postWebhook(ActionTypes.ADMIN_ACTION, payload)
// await webhookHandler.postWebhook(ActionTypes.ADMIN_ACTION, payload)

// expect(httpService.post).toHaveBeenCalled()
// })
// expect(httpService.post).toHaveBeenCalled()
// })

// it('should handle FLAG_WIKI correctly', async () => {
// const payload = {
// user: 'testUser',
// urlId: '123',
// description: 'Test description',
// }
// jest.spyOn(configService, 'get').mockReturnValue('{}')
// jest.spyOn(httpService, 'post').mockReturnValue({
// subscribe: jest.fn(),
// } as any)
it('should handle FLAG_WIKI correctly', async () => {
const payload = {
user: 'testUser',
urlId: '123',
description: 'Test description',
}
jest.spyOn(configService, 'get').mockReturnValue('{}')
jest.spyOn(httpService, 'post').mockReturnValue({
subscribe: jest.fn(),
} as any)

// await webhookHandler.postWebhook(ActionTypes.FLAG_WIKI, payload)
await webhookHandler.postWebhook(ActionTypes.FLAG_WIKI, payload)

// expect(httpService.post).toHaveBeenCalled()
// })
// })
expect(httpService.post).toHaveBeenCalled()
})
})

0 comments on commit c8c4536

Please sign in to comment.