-
Notifications
You must be signed in to change notification settings - Fork 110
feat: create slack channel #3315
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 9 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
1af1a3c
feat: create slack channel
rebelchris a4dfa80
Merge branch 'main' into feat-slack-channel
rebelchris dbc1ec5
fix: error throwing
rebelchris 6dd1172
Merge remote-tracking branch 'origin/feat-slack-channel' into feat-sl…
rebelchris 46a919c
feat: add garmr
rebelchris 3162cb3
feat: add garmr
rebelchris c386972
fix: add test issue
rebelchris 21e9b92
Merge branch 'main' of github.com:dailydotdev/daily-api into feat-sla…
rebelchris ee5b825
fix: test cases using slack
rebelchris e973480
fix: pr feedback
rebelchris f41b8ee
Merge branch 'main' into feat-slack-channel
rebelchris 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 |
|---|---|---|
|
|
@@ -30,7 +30,10 @@ import { | |
| opportunityFeedbackQuestionsFixture, | ||
| organizationsFixture, | ||
| } from '../fixture/opportunity'; | ||
| import { OpportunityUser } from '../../src/entity/opportunities/user'; | ||
| import { | ||
| OpportunityUser, | ||
| OpportunityUserRecruiter, | ||
| } from '../../src/entity/opportunities/user'; | ||
| import { | ||
| OpportunityMatchStatus, | ||
| OpportunityUserType, | ||
|
|
@@ -75,6 +78,28 @@ import { OpportunityJob } from '../../src/entity/opportunities/OpportunityJob'; | |
| import * as brokkrCommon from '../../src/common/brokkr'; | ||
| import { randomUUID } from 'node:crypto'; | ||
|
|
||
| // Mock Slack WebClient | ||
| const mockConversationsCreate = jest.fn(); | ||
| const mockConversationsInviteShared = jest.fn(); | ||
| const mockConversationsJoin = jest.fn(); | ||
|
|
||
| jest.mock('@slack/web-api', () => ({ | ||
| ...(jest.requireActual('@slack/web-api') as Record<string, unknown>), | ||
| WebClient: jest.fn().mockImplementation(() => ({ | ||
| conversations: { | ||
| get create() { | ||
| return mockConversationsCreate; | ||
| }, | ||
| get inviteShared() { | ||
| return mockConversationsInviteShared; | ||
| }, | ||
| get join() { | ||
| return mockConversationsJoin; | ||
| }, | ||
| }, | ||
| })), | ||
| })); | ||
|
|
||
| const deleteFileFromBucket = jest.spyOn(googleCloud, 'deleteFileFromBucket'); | ||
| const uploadEmploymentAgreementFromBuffer = jest.spyOn( | ||
| googleCloud, | ||
|
|
@@ -5390,3 +5415,157 @@ describe('mutation parseOpportunity', () => { | |
| ); | ||
| }); | ||
| }); | ||
|
|
||
| describe('mutation createSharedSlackChannel', () => { | ||
| const MUTATION = /* GraphQL */ ` | ||
| mutation CreateSharedSlackChannel($email: String!, $channelName: String!) { | ||
| createSharedSlackChannel(email: $email, channelName: $channelName) { | ||
| _ | ||
| } | ||
| } | ||
| `; | ||
|
|
||
| beforeEach(() => { | ||
| // Reset all mocks before each test | ||
| mockConversationsCreate.mockReset(); | ||
| mockConversationsInviteShared.mockReset(); | ||
| }); | ||
|
|
||
| it('should require authentication', async () => { | ||
| await testMutationErrorCode( | ||
| client, | ||
| { | ||
| mutation: MUTATION, | ||
| variables: { | ||
| email: '[email protected]', | ||
| channelName: 'test-channel', | ||
| }, | ||
| }, | ||
| 'UNAUTHENTICATED', | ||
| ); | ||
| }); | ||
|
|
||
| it('should forbid non-recruiters from creating slack channels', async () => { | ||
| loggedUser = '5'; // User 5 is not a recruiter in fixtures | ||
|
|
||
| await testMutationErrorCode( | ||
| client, | ||
| { | ||
| mutation: MUTATION, | ||
| variables: { | ||
| email: '[email protected]', | ||
| channelName: 'test-channel', | ||
| }, | ||
| }, | ||
| 'FORBIDDEN', | ||
| ); | ||
| }); | ||
|
|
||
| it('should create slack channel and invite user successfully', async () => { | ||
| loggedUser = '1'; | ||
|
|
||
| // Create a recruiter record for the logged-in user | ||
| await con.getRepository(OpportunityUserRecruiter).save({ | ||
| opportunityId: '550e8400-e29b-41d4-a716-446655440001', | ||
| userId: '1', | ||
| type: OpportunityUserType.Recruiter, | ||
| }); | ||
|
|
||
| // Mock successful Slack API responses | ||
| mockConversationsCreate.mockResolvedValue({ | ||
| ok: true, | ||
| channel: { | ||
| id: 'C1234567890', | ||
| name: 'test-channel', | ||
| }, | ||
| }); | ||
|
|
||
| mockConversationsInviteShared.mockResolvedValue({ | ||
| ok: true, | ||
| }); | ||
|
|
||
| const res = await client.mutate(MUTATION, { | ||
| variables: { | ||
| email: '[email protected]', | ||
| channelName: 'test-channel', | ||
| }, | ||
| }); | ||
|
|
||
| expect(res.errors).toBeFalsy(); | ||
| expect(res.data.createSharedSlackChannel).toEqual({ _: true }); | ||
|
|
||
| // Verify Slack API calls were made | ||
| expect(mockConversationsCreate).toHaveBeenCalledWith({ | ||
| name: 'test-channel', | ||
| is_private: false, | ||
| }); | ||
| expect(mockConversationsInviteShared).toHaveBeenCalledWith({ | ||
| channel: 'C1234567890', | ||
| emails: ['[email protected]'], | ||
| external_limited: true, | ||
| }); | ||
| }); | ||
|
|
||
| it('should handle slack channel creation failure', async () => { | ||
| loggedUser = '1'; | ||
|
|
||
| // Create a recruiter record for the logged-in user | ||
| await con.getRepository(OpportunityUserRecruiter).save({ | ||
| opportunityId: '550e8400-e29b-41d4-a716-446655440001', | ||
| userId: '1', | ||
| type: OpportunityUserType.Recruiter, | ||
| }); | ||
|
|
||
| // Mock failed channel creation (no channel in response) | ||
| mockConversationsCreate.mockResolvedValue({ | ||
| ok: false, | ||
| error: 'name_taken', | ||
| channel: undefined, | ||
| }); | ||
|
|
||
| const res = await client.mutate(MUTATION, { | ||
| variables: { | ||
| email: '[email protected]', | ||
| channelName: 'existing-channel', | ||
| }, | ||
| }); | ||
|
|
||
| expect(res.errors).toBeFalsy(); | ||
| expect(res.data.createSharedSlackChannel).toEqual({ _: false }); | ||
|
|
||
| // Should not proceed to invite if channel creation fails | ||
| expect(mockConversationsInviteShared).not.toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| it('should handle invitation failure', async () => { | ||
| loggedUser = '1'; | ||
|
|
||
| // Create a recruiter record for the logged-in user | ||
| await con.getRepository(OpportunityUserRecruiter).save({ | ||
| opportunityId: '550e8400-e29b-41d4-a716-446655440001', | ||
| userId: '1', | ||
| type: OpportunityUserType.Recruiter, | ||
| }); | ||
|
|
||
| mockConversationsCreate.mockResolvedValue({ | ||
| ok: true, | ||
| channel: { | ||
| id: 'C1234567890', | ||
| name: 'test-channel', | ||
| }, | ||
| }); | ||
|
|
||
| mockConversationsInviteShared.mockRejectedValue( | ||
| new Error('Failed to invite user'), | ||
| ); | ||
|
|
||
| const res = await client.mutate(MUTATION, { | ||
| variables: { | ||
| email: '[email protected]', | ||
| channelName: 'test-channel', | ||
| }, | ||
| }); | ||
|
|
||
| expect(res.errors).toBeTruthy(); | ||
| }); | ||
| }); | ||
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
Oops, something went wrong.
Oops, something went wrong.
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.