-
Notifications
You must be signed in to change notification settings - Fork 0
[25.02.08 / TASK-109 / TASK-94] Feature - 샘플 유저 로그인 로직 추가, 신규 유저 slack noti 추가 #17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,51 @@ | ||
| import axios from 'axios'; | ||
| import dotenv from 'dotenv'; | ||
|
|
||
| // 환경 변수 로드 (.env 파일) | ||
| dotenv.config(); | ||
|
|
||
| // 테스트 환경에서 SLACK_WEBHOOK_URL이 설정되어 있지 않으면 기본값 설정 | ||
| process.env.SLACK_WEBHOOK_URL = | ||
| process.env.SLACK_WEBHOOK_URL || 'https://dummy-slack-webhook-url.com'; | ||
|
|
||
| // axios 모듈을 mock 처리 | ||
| jest.mock('axios'); | ||
| const mockedAxios = axios as jest.Mocked<typeof axios>; | ||
|
|
||
| // 테스트 대상 모듈을 import 합니다. | ||
| // 주의: 모듈을 import하기 전에 process.env.SLACK_WEBHOOK_URL을 설정해야 합니다. | ||
| import { sendSlackMessage } from '@/modules/slack/slack.notifier'; | ||
|
|
||
| describe('sendSlackMessage', () => { | ||
| // 각 테스트 실행 전 mock 호출 기록 초기화 | ||
| beforeEach(() => { | ||
| jest.clearAllMocks(); | ||
| }); | ||
|
|
||
| test('정상적인 메시지 전송 - axios.post가 올바른 파라미터로 호출되어야 한다', async () => { | ||
| // Arrange: axios.post가 성공적으로 응답하도록 설정합니다. | ||
| const fakeResponse = { data: 'ok' }; | ||
| mockedAxios.post.mockResolvedValue(fakeResponse); | ||
|
|
||
| const testMessage = 'Test Slack message'; | ||
|
|
||
| // Act: sendSlackMessage 함수를 호출합니다. | ||
| await sendSlackMessage(testMessage); | ||
|
|
||
| // Assert: axios.post가 올바른 URL, payload, header로 호출되었는지 검증합니다. | ||
| expect(mockedAxios.post).toHaveBeenCalledWith( | ||
| process.env.SLACK_WEBHOOK_URL, | ||
| { text: testMessage }, | ||
| { headers: { 'Content-Type': 'application/json' } } | ||
| ); | ||
| }); | ||
Nuung marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| test('axios.post 호출 중 에러가 발생하면 sendSlackMessage가 예외를 throw 해야 한다', async () => { | ||
| // Arrange: axios.post가 에러를 발생시키도록 설정합니다. | ||
| const errorMessage = 'Network Error'; | ||
| mockedAxios.post.mockRejectedValue(new Error(errorMessage)); | ||
|
|
||
| // Act & Assert: sendSlackMessage 호출 시 에러가 발생하는지 확인합니다. | ||
| await expect(sendSlackMessage('Test error')).rejects.toThrow(errorMessage); | ||
| }); | ||
| }); | ||
This file contains hidden or 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,27 @@ | ||
| import axios from 'axios'; | ||
| import dotenv from 'dotenv'; | ||
|
|
||
| // 환경 변수 로드 (.env 파일) | ||
| dotenv.config(); | ||
|
|
||
| // 환경 변수 체크 | ||
| if (!process.env.SLACK_WEBHOOK_URL) { | ||
| throw new Error('SLACK_WEBHOOK_URL is not defined in environment variables.'); | ||
| } | ||
| const SLACK_WEBHOOK_URL: string = process.env.SLACK_WEBHOOK_URL; | ||
|
|
||
| interface SlackPayload { | ||
| text: string; | ||
| } | ||
|
|
||
| /** | ||
| * Slack으로 메시지를 전송합니다. | ||
| * @param message 전송할 메시지 텍스트 | ||
| */ | ||
| export async function sendSlackMessage(message: string): Promise<void> { | ||
| const payload: SlackPayload = { text: message }; | ||
| const response = await axios.post(SLACK_WEBHOOK_URL, payload, { | ||
| headers: { 'Content-Type': 'application/json' }, | ||
| }); | ||
| console.log(response); | ||
| } | ||
Nuung marked this conversation as resolved.
Show resolved
Hide resolved
|
||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.