-
Notifications
You must be signed in to change notification settings - Fork 7
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
Showing
25 changed files
with
211 additions
and
65 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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "nestjs-slack-listener", | ||
"version": "1.0.2", | ||
"version": "1.0.4", | ||
"description": "NestJS Slack listeners and handlers", | ||
"author": "Chung Hwan Han <[email protected]>", | ||
"license": "MIT", | ||
|
@@ -74,25 +74,38 @@ | |
"pre-commit": "^1.2.2", | ||
"prettier": "2.6.1", | ||
"reflect-metadata": "^0.1.13", | ||
"supertest": "6.2.2", | ||
"supertest": "^6.3.0", | ||
"ts-jest": "27.1.4", | ||
"ts-node": "10.7.0", | ||
"tsc-watch": "5.0.3", | ||
"tsconfig-paths": "3.14.1", | ||
"typescript": "4.6.3" | ||
}, | ||
"jest": { | ||
"moduleDirectories": [ | ||
"node_modules", | ||
"src" | ||
], | ||
"moduleFileExtensions": [ | ||
"js", | ||
"json", | ||
"ts" | ||
], | ||
"rootDir": "src", | ||
"testRegex": ".spec.ts$", | ||
"roots": [ | ||
"src" | ||
], | ||
"testRegex": ".*\\.spec\\.ts$", | ||
"transform": { | ||
"^.+\\.(t|j)s$": "ts-jest" | ||
}, | ||
"collectCoverageFrom": [ | ||
"**/*.(t|j)s" | ||
], | ||
"coverageDirectory": "../coverage", | ||
"testEnvironment": "node" | ||
"testEnvironment": "node", | ||
"moduleNameMapper": { | ||
"gaxios": "gaxios", | ||
"src/(.*)": "<rootDir>/src/$1" | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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 +1 @@ | ||
export * from './handler'; | ||
export * from './slack'; |
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,3 +1,4 @@ | ||
export const SLACK_CONFIG_OPTIONS = 'SLACK_CONFIG_OPTIONS'; | ||
export const SLACK_INTERACTIVITY_HANDLER = 'SLACK_INTERACTIVITY_HANDLER'; | ||
export const SLACK_EVENT_HANDLER = 'SLACK_EVENT_HANDLER'; | ||
export const SLACK_CLIENT = 'SLACK_CLIENT'; |
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,4 @@ | ||
import { Inject } from '@nestjs/common'; | ||
import { SLACK_CLIENT } from '../constant/symbol'; | ||
|
||
export const InjectSlackClient = () => Inject(SLACK_CLIENT); |
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions
1
src/handler/decorators/index.ts → src/slack/decorators/index.ts
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,2 +1,3 @@ | ||
export * from './command.decorator'; | ||
export * from './handler.decorator'; | ||
export * from './client.decorator'; |
File renamed without changes.
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,4 @@ | ||
export * from './decorators'; | ||
export * from './interfaces'; | ||
export * from './types/client'; | ||
export * from './slack.module'; |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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,13 @@ | ||
import { Inject, Injectable } from '@nestjs/common'; | ||
import { WebClient } from '@slack/web-api'; | ||
import { SLACK_CONFIG_OPTIONS } from './constant/symbol'; | ||
import { SlackModuleOptions } from './interfaces'; | ||
|
||
@Injectable() | ||
export class SlackClientService { | ||
public readonly client: WebClient; | ||
|
||
constructor(@Inject(SLACK_CONFIG_OPTIONS) options: SlackModuleOptions) { | ||
this.client = new WebClient(options.botToken); | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
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,3 @@ | ||
import { WebClient } from '@slack/web-api'; | ||
|
||
export type SlackClient = WebClient; |
File renamed without changes.
This file was deleted.
Oops, something went wrong.
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,111 @@ | ||
import { Controller, Get, Injectable, Module } from '@nestjs/common'; | ||
import { NestFactory } from '@nestjs/core'; | ||
import { SlackClient, SlackEventListener, SlackModule } from 'src/slack'; | ||
import { InjectSlackClient } from 'src/slack/decorators'; | ||
import * as request from 'supertest'; | ||
|
||
describe('Slack Module Initialization', () => { | ||
describe('forRoot', () => { | ||
it('should compile only with botToken option', async () => { | ||
@Controller() | ||
@SlackEventListener() | ||
class TestController { | ||
@Get() | ||
get() { | ||
return ''; | ||
} | ||
} | ||
@Module({ | ||
imports: [SlackModule.forRoot({ botToken: 'test' })], | ||
controllers: [TestController], | ||
}) | ||
class TestModule {} | ||
|
||
const app = await NestFactory.create(TestModule); | ||
const server = app.getHttpServer(); | ||
|
||
await app.init(); | ||
await request(server).get('/').expect(200); | ||
await app.close(); | ||
}); | ||
it('should compile including slack client', async () => { | ||
@Injectable() | ||
class TestService { | ||
constructor(@InjectSlackClient() slack: SlackClient) { | ||
expect(slack).toBeDefined(); | ||
} | ||
getBotToken() { | ||
return 'test'; | ||
} | ||
} | ||
@Module({ | ||
imports: [ | ||
SlackModule.forRoot({ | ||
botToken: 'test', | ||
}), | ||
], | ||
providers: [TestService], | ||
}) | ||
class TestModule {} | ||
|
||
const app = await NestFactory.create(TestModule); | ||
|
||
await app.init(); | ||
await app.close(); | ||
}); | ||
}); | ||
describe('forRootAsync', () => { | ||
it('should compile only with botToken option', async () => { | ||
@Controller() | ||
@SlackEventListener() | ||
class TestController { | ||
@Get() | ||
get() { | ||
return ''; | ||
} | ||
} | ||
@Module({ | ||
imports: [ | ||
SlackModule.forRootAsync({ | ||
useFactory: () => ({ botToken: 'test' }), | ||
}), | ||
], | ||
controllers: [TestController], | ||
}) | ||
class TestModule {} | ||
|
||
const app = await NestFactory.create(TestModule); | ||
const server = app.getHttpServer(); | ||
|
||
await app.init(); | ||
await request(server).get('/').expect(200); | ||
await app.close(); | ||
}); | ||
|
||
it('should compile including slack client', async () => { | ||
@Injectable() | ||
class TestService { | ||
constructor(@InjectSlackClient() slack: SlackClient) { | ||
expect(slack).toBeDefined(); | ||
} | ||
getBotToken() { | ||
return 'test'; | ||
} | ||
} | ||
@Module({ | ||
imports: [ | ||
SlackModule.forRootAsync({ | ||
useFactory: () => ({ botToken: 'test' }), | ||
}), | ||
], | ||
providers: [TestService], | ||
}) | ||
class TestModule {} | ||
|
||
const app = await NestFactory.create(TestModule); | ||
|
||
await app.init(); | ||
await app.close(); | ||
}); | ||
}); | ||
}); |
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.