Skip to content

Commit

Permalink
feat: add test coverage for upload file messages (posts)
Browse files Browse the repository at this point in the history
  • Loading branch information
domw30 committed Sep 4, 2024
1 parent 308a1a9 commit 80ff320
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
46 changes: 46 additions & 0 deletions src/store/posts/saga.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,52 @@ describe(createOptimisticPost, () => {
});
});

describe(uploadFileMessages, () => {
it('uploads an uploadable file', async () => {
const imageCreationResponse = { id: 'image-message-id', optimisticId: 'optimistic-id' };
const upload = jest.fn().mockReturnValue(imageCreationResponse);
const uploadable = { upload, optimisticMessage: { id: 'optimistic-id' } } as any;
const channelId = 'channel-id';

const initialState = new StoreBuilder().withConversationList({
id: channelId,
messages: [{ id: 'optimistic-id' } as any],
});

const { storeState } = await expectSaga(uploadFileMessages, channelId, '', [uploadable], true)
.withReducer(rootReducer, initialState.build())
.run();

const channel = denormalizeChannel(channelId, storeState);
expect(channel.messages).toHaveLength(1);
expect(channel.messages[0].id).toEqual('optimistic-id');
});

it('first media file sets its rootMessageId', async () => {
const imageCreationResponse = { id: 'image-message-id' };
const upload1 = jest.fn().mockReturnValue(imageCreationResponse);
const upload2 = jest.fn().mockReturnValue(imageCreationResponse);
const uploadable1 = { upload: upload1, optimisticMessage: { id: 'id-1' } } as any;
const uploadable2 = { upload: upload2, optimisticMessage: { id: 'id-2' } } as any;
const channelId = 'channel-id';
const rootMessageId = 'root-message-id';

await expectSaga(
uploadFileMessages,
channelId,
rootMessageId,
[
uploadable1,
uploadable2,
],
true
).run();

expect(upload1).toHaveBeenCalledWith(channelId, rootMessageId, true);
expect(upload2).toHaveBeenCalledWith(channelId, '', true);
});
});

describe(fetchPosts, () => {
function subject(...args: Parameters<typeof expectSaga>) {
return expectSaga(...args).provide([
Expand Down
2 changes: 1 addition & 1 deletion src/store/posts/saga.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { takeLatest, call, put, select } from 'redux-saga/effects';
import { takeLatest, call, select } from 'redux-saga/effects';
import uniqBy from 'lodash.uniqby';

import { SagaActionTypes } from '.';
Expand Down

0 comments on commit 80ff320

Please sign in to comment.