-
Notifications
You must be signed in to change notification settings - Fork 18
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
0b662ab
commit 5c06158
Showing
6 changed files
with
258 additions
and
109 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
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 |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import { Test } from '@nestjs/testing'; | ||
import { SlackModule } from '../slack.module'; | ||
import { SlackService } from '../slack.service'; | ||
import * as nock from 'nock'; | ||
import { Inject, Injectable, Module } from '@nestjs/common'; | ||
import { SlackConfig } from '../types'; | ||
|
||
interface Config { | ||
slackWebhookUrl: string; | ||
} | ||
|
||
describe('slack.module', () => { | ||
const baseUrl = 'http://example.com'; | ||
|
||
it('should construct with useFactory', async () => { | ||
const app = await Test.createTestingModule({ | ||
imports: [ | ||
SlackModule.forRootAsync({ | ||
useFactory: () => { | ||
return { | ||
type: 'webhook', | ||
webhookOptions: { url: `${baseUrl}/webhook` }, | ||
}; | ||
}, | ||
}), | ||
], | ||
}).compile(); | ||
const service = app.get<SlackService>(SlackService); | ||
|
||
const scope = nock(baseUrl, { encodedQueryParams: true }) | ||
.post('/webhook', { | ||
text: 'hello-world', | ||
}) | ||
.reply(200, 'ok'); | ||
|
||
await service.postMessage({ text: 'hello-world' }); | ||
|
||
scope.done(); | ||
}); | ||
|
||
it('should construct with useClass', async () => { | ||
@Injectable() | ||
class ConfigClass { | ||
slackConfigModuleOptions(): SlackConfig { | ||
return { | ||
type: 'webhook', | ||
webhookOptions: { url: `${baseUrl}/webhook` }, | ||
}; | ||
} | ||
} | ||
|
||
@Module({ | ||
exports: [ConfigClass], | ||
providers: [ConfigClass], | ||
}) | ||
class TestModule {} | ||
|
||
const app = await Test.createTestingModule({ | ||
imports: [ | ||
SlackModule.forRootAsync({ | ||
imports: [TestModule], | ||
useClass: ConfigClass, | ||
}), | ||
], | ||
}).compile(); | ||
const service = app.get<SlackService>(SlackService); | ||
|
||
const scope = nock(baseUrl, { encodedQueryParams: true }) | ||
.post('/webhook', { | ||
text: 'hello-world', | ||
}) | ||
.reply(200, 'ok'); | ||
|
||
await service.postMessage({ text: 'hello-world' }); | ||
|
||
scope.done(); | ||
}); | ||
}); |
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,4 +1,5 @@ | ||
export const SLACK_MODULE_OPTIONS = 'SlackModuleOptions'; | ||
export const SLACK_MODULE_USER_OPTIONS = 'SlackModuleUserOptions'; | ||
export const SLACK_WEB_CLIENT = 'SlackWebClient'; | ||
export const SLACK_WEBHOOK_URL = 'SlackWebhookUrl'; | ||
export const GOOGLE_LOGGING = 'SlackGoogleLogging'; |
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
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
Oops, something went wrong.