Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/vocal-maroon-monkey.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@inkeep/agents-work-apps": patch
---

Fix Slack API retry import
31 changes: 17 additions & 14 deletions packages/agents-work-apps/src/__tests__/slack/client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* - Message posting (channels and threads)
*/

import { retryPolicies, WebClient } from '@slack/web-api';
import type { WebClient } from '@slack/web-api';
import { beforeEach, describe, expect, it, vi } from 'vitest';
import {
checkUserIsChannelMember,
Expand All @@ -22,8 +22,8 @@ import {
postMessageInThread,
} from '../../slack/services/client';

vi.mock('@slack/web-api', () => ({
WebClient: vi.fn().mockImplementation(() => ({
const { mockWebClient } = vi.hoisted(() => {
const mockWebClient = vi.fn().mockImplementation(() => ({
users: {
info: vi.fn(),
},
Expand All @@ -37,11 +37,16 @@ vi.mock('@slack/web-api', () => ({
chat: {
postMessage: vi.fn(),
},
})),
retryPolicies: {
fiveRetriesInFiveMinutes: { retries: 5, factor: 3.86, randomize: true },
},
}));
}));

return { mockWebClient };
});

vi.mock('@slack/web-api', () => {
return {
WebClient: mockWebClient,
};
});

vi.mock('../../logger', () => ({
getLogger: () => ({
Expand All @@ -58,14 +63,12 @@ describe('Slack Client', () => {
});

describe('getSlackClient', () => {
it('should create a WebClient with the provided token and retry config', () => {
it('should create a WebClient with the provided token', () => {
const token = 'xoxb-test-token';

const client = getSlackClient(token);

expect(WebClient).toHaveBeenCalledWith(token, {
retryConfig: retryPolicies.fiveRetriesInFiveMinutes,
});
expect(mockWebClient).toHaveBeenCalledWith(token);
expect(client).toBeDefined();
});

Expand All @@ -76,8 +79,8 @@ describe('Slack Client', () => {
getSlackClient(token1);
getSlackClient(token2);

expect(WebClient).toHaveBeenCalledWith(token1, expect.anything());
expect(WebClient).toHaveBeenCalledWith(token2, expect.anything());
expect(mockWebClient).toHaveBeenCalledWith(token1);
expect(mockWebClient).toHaveBeenCalledWith(token2);
});
});

Expand Down
6 changes: 2 additions & 4 deletions packages/agents-work-apps/src/slack/services/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* Tokens are fetched from Nango at runtime and passed to these functions.
*/

import { retryPolicies, WebClient } from '@slack/web-api';
import { WebClient } from '@slack/web-api';
import { getLogger } from '../../logger';

const logger = getLogger('slack-client');
Expand Down Expand Up @@ -45,9 +45,7 @@ async function paginateSlack<TResponse, TItem>({
* @returns Configured Slack WebClient instance
*/
export function getSlackClient(token: string): WebClient {
return new WebClient(token, {
retryConfig: retryPolicies.fiveRetriesInFiveMinutes,
});
return new WebClient(token);
}

/**
Expand Down