Skip to content

Commit 0824549

Browse files
committed
fix: typescript errors
1 parent 0d2a24a commit 0824549

6 files changed

Lines changed: 81 additions & 38 deletions

File tree

package/src/__tests__/nativeMultipartUpload.test.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ import {
33
createNativeMultipartUploader,
44
NativeMultipartAbortSignal,
55
NativeMultipartUploadEventEmitter,
6+
NativeMultipartUploadNativeResponse,
67
NativeMultipartUploadProgressEvent,
8+
NativeMultipartUploaderModule,
79
} from '../nativeMultipartUpload';
810

911
const progressEventName = 'streamMultipartUploadProgress';
@@ -20,7 +22,10 @@ const createNativeModule = () => ({
2022
addListener: jest.fn(),
2123
cancelUpload: jest.fn(() => Promise.resolve()),
2224
removeListeners: jest.fn(),
23-
uploadMultipart: jest.fn(() =>
25+
uploadMultipart: jest.fn<
26+
ReturnType<NativeMultipartUploaderModule['uploadMultipart']>,
27+
Parameters<NativeMultipartUploaderModule['uploadMultipart']>
28+
>(() =>
2429
Promise.resolve({
2530
body: 'ok',
2631
headers: [{ name: 'x-test', value: 'yes' }],
@@ -68,11 +73,11 @@ describe('nativeMultipartUpload', () => {
6873
it('passes requests to the native module and forwards matching progress events', async () => {
6974
const nativeModule = createNativeModule();
7075
const eventEmitter = createEventEmitter();
71-
let resolveUpload: (response: Awaited<ReturnType<typeof nativeModule.uploadMultipart>>) => void;
76+
let resolveUpload: (response: NativeMultipartUploadNativeResponse) => void;
7277
nativeModule.uploadMultipart.mockImplementation(
7378
() =>
74-
new Promise((resolve) => {
75-
resolveUpload = resolve;
79+
new Promise<NativeMultipartUploadNativeResponse>((resolve) => {
80+
resolveUpload = (response) => resolve(response);
7681
}),
7782
);
7883
const uploadMultipart = createNativeMultipartUploader(nativeModule, { eventEmitter });

package/src/components/Attachment/__tests__/Attachment.test.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import React, { ComponentProps } from 'react';
22
import { StyleSheet, View } from 'react-native';
33

4+
import type { ReactTestInstance } from 'react-test-renderer';
5+
46
import { render, waitFor } from '@testing-library/react-native';
57
import { v4 as uuidv4 } from 'uuid';
68

@@ -70,8 +72,8 @@ const getAttachmentComponent = (props: ComponentProps<typeof Attachment>) => {
7072
);
7173
};
7274

73-
const getWaveformBarCount = (root) =>
74-
root.findAllByType(View).filter((node) => {
75+
const getWaveformBarCount = (root: ReactTestInstance) =>
76+
root.findAllByType(View).filter((node: ReactTestInstance) => {
7577
const flattenedStyle = StyleSheet.flatten(node.props.style);
7678
return flattenedStyle?.width === 2 && typeof flattenedStyle?.height === 'number';
7779
}).length;

package/src/components/Attachment/__tests__/Giphy.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ describe('Giphy', () => {
5858
}
5959
>
6060
<MessageProvider
61-
value={{ message, ...messageContextValue } as unknown as MessagesContextValue}
61+
value={{ message, ...messageContextValue } as unknown as MessageContextValue}
6262
>
6363
<Giphy {...props} />
6464
</MessageProvider>

package/src/components/MessageInput/__tests__/AttachmentUploadPreviewList.test.tsx

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import React, { ComponentProps } from 'react';
22

33
import { ActivityIndicator } from 'react-native';
44

5+
import type { ReactTestInstance } from 'react-test-renderer';
6+
57
import { act, cleanup, fireEvent, render, screen, waitFor } from '@testing-library/react-native';
68

79
import type { Attachment, Channel as ChannelType, LocalAttachment, StreamChat } from 'stream-chat';
@@ -67,7 +69,12 @@ const renderComponent = ({
6769
);
6870
};
6971

70-
const setPendingUploads = (client, uploads) => {
72+
type PendingUploadRecord = {
73+
id: string;
74+
uploadProgress?: number;
75+
};
76+
77+
const setPendingUploads = (client: StreamChat, uploads: PendingUploadRecord[]) => {
7178
act(() => {
7279
client.uploadManager.state.partialNext({
7380
uploads: Object.fromEntries(
@@ -77,8 +84,12 @@ const setPendingUploads = (client, uploads) => {
7784
});
7885
};
7986

80-
const countActivityIndicators = (nodes) =>
81-
nodes.reduce((count, node) => count + node.findAllByType(ActivityIndicator).length, 0);
87+
const countActivityIndicators = (nodes: ReactTestInstance[]) =>
88+
nodes.reduce(
89+
(count: number, node: ReactTestInstance) =>
90+
count + node.findAllByType(ActivityIndicator).length,
91+
0,
92+
);
8293

8394
describe('AttachmentUploadPreviewList', () => {
8495
let client: StreamChat;

package/src/components/MessageInput/__tests__/AudioAttachmentUploadPreview.test.tsx

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import React, { ComponentProps } from 'react';
22

33
import { ActivityIndicator } from 'react-native';
44

5+
import type { ReactTestInstance } from 'react-test-renderer';
6+
57
import { act, cleanup, fireEvent, render, screen, waitFor } from '@testing-library/react-native';
68

79
import type { Attachment, Channel as ChannelType, LocalAttachment, StreamChat } from 'stream-chat';
@@ -56,7 +58,12 @@ const renderComponent = ({
5658
);
5759
};
5860

59-
const setPendingUploads = (client, uploads) => {
61+
type PendingUploadRecord = {
62+
id: string;
63+
uploadProgress?: number;
64+
};
65+
66+
const setPendingUploads = (client: StreamChat, uploads: PendingUploadRecord[]) => {
6067
act(() => {
6168
client.uploadManager.state.partialNext({
6269
uploads: Object.fromEntries(
@@ -66,8 +73,12 @@ const setPendingUploads = (client, uploads) => {
6673
});
6774
};
6875

69-
const countActivityIndicators = (nodes) =>
70-
nodes.reduce((count, node) => count + node.findAllByType(ActivityIndicator).length, 0);
76+
const countActivityIndicators = (nodes: ReactTestInstance[]) =>
77+
nodes.reduce(
78+
(count: number, node: ReactTestInstance) =>
79+
count + node.findAllByType(ActivityIndicator).length,
80+
0,
81+
);
7182

7283
describe('AudioAttachmentUploadPreview render', () => {
7384
let client: StreamChat;

package/src/utils/__tests__/installNativeMultipartAdapter.test.ts

Lines changed: 39 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,19 @@
1+
import type { AxiosProgressEvent, AxiosRequestConfig } from 'axios';
2+
13
import { getTestClient } from '../../mock-builders/mock';
2-
import { NativeHandlers } from '../../native';
4+
import { NativeHandlers, NativeMultipartUploadProgressConfig } from '../../native';
35
import {
46
installNativeMultipartAdapter,
57
wrapAxiosAdapterWithNativeMultipart,
68
} from '../installNativeMultipartAdapter';
79

10+
type NativeMultipartTestAxiosConfig = AxiosRequestConfig & {
11+
uploadProgress?: (event: AxiosProgressEvent) => void;
12+
uploadProgressOptions?: NativeMultipartUploadProgressConfig;
13+
};
14+
15+
const nativeMultipartConfig = (config: NativeMultipartTestAxiosConfig) => config;
16+
817
describe('installNativeMultipartAdapter', () => {
918
const originalMultipartUpload = NativeHandlers.multipartUpload;
1019

@@ -148,14 +157,18 @@ describe('installNativeMultipartAdapter', () => {
148157
],
149158
};
150159

151-
await client.axiosInstance.post('/uploads/image', formData, {
152-
onUploadProgress,
153-
uploadProgressOptions: {
154-
count: 10,
155-
intervalMs: 25,
156-
},
157-
uploadProgress,
158-
});
160+
await client.axiosInstance.post(
161+
'/uploads/image',
162+
formData,
163+
nativeMultipartConfig({
164+
onUploadProgress,
165+
uploadProgressOptions: {
166+
count: 10,
167+
intervalMs: 25,
168+
},
169+
uploadProgress,
170+
}),
171+
);
159172

160173
expect(onUploadProgress).toHaveBeenCalledWith(
161174
expect.objectContaining({
@@ -261,14 +274,18 @@ describe('installNativeMultipartAdapter', () => {
261274
],
262275
};
263276

264-
await client.axiosInstance.post('/uploads/image', formData, {
265-
onUploadProgress,
266-
uploadProgressOptions: {
267-
completionProgressCap: 75,
268-
count: 10,
269-
intervalMs: 25,
270-
},
271-
});
277+
await client.axiosInstance.post(
278+
'/uploads/image',
279+
formData,
280+
nativeMultipartConfig({
281+
onUploadProgress,
282+
uploadProgressOptions: {
283+
completionProgressCap: 75,
284+
count: 10,
285+
intervalMs: 25,
286+
},
287+
}),
288+
);
272289

273290
expect(onUploadProgress).toHaveBeenCalledTimes(1);
274291
expect(onUploadProgress).toHaveBeenCalledWith(
@@ -302,14 +319,11 @@ describe('installNativeMultipartAdapter', () => {
302319

303320
client.axiosInstance.defaults.adapter = defaultAdapter;
304321

305-
const interceptorId = client.axiosInstance.interceptors.request.use((config) => ({
306-
...config,
307-
headers: {
308-
...config.headers,
309-
'X-CDN-Route': 'custom-cdn',
310-
},
311-
url: '/uploads/file',
312-
}));
322+
const interceptorId = client.axiosInstance.interceptors.request.use((config) => {
323+
config.headers.set('X-CDN-Route', 'custom-cdn');
324+
config.url = '/uploads/file';
325+
return config;
326+
});
313327

314328
installNativeMultipartAdapter(client);
315329
const formData = {

0 commit comments

Comments
 (0)