-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
531f8c9
commit c8c4536
Showing
1 changed file
with
73 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
}) | ||
}) |