mattermost-mobile/app/client/rest/channel_bookmark.test.ts
Joram Wilander 4fedb846bc
MM-59683 + more - Add tests to client/rest (#8447)
* Add tests to client/rest/users

* Add tests to client/rest/channels

* Add tests to client/rest/posts

* Add tests to client/rest/teams

* Add tests to client/rest/general

* Minor clean-up

* Add tests to client/rest/file

* Add tests to client/rest/threads

* Add tests to client/rest/emojis

* Add tests to client/rest/integrations

* Add tests to client/rest/categories

* Add tests to client/rest/groups

* Add tests to client/rest/channel_bookmark

* Add tests to client/rest/preferences

* Add tests to client/rest/tos

* Add tests to client/rest/nps and client/rest/plugins

* Minor clean-up

* Fix type error with proper client.searchFiles definition

* add more test to cover 100%

* add teamId test

* improve users test

---------

Co-authored-by: Rahim Rahman <rahim.rahman@mattermost.com>
2025-01-07 08:23:28 -05:00

92 lines
3.4 KiB
TypeScript

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import TestHelper from '@test/test_helper';
import {buildQueryString} from '@utils/helpers';
import type ClientBase from './base';
import type {ClientChannelBookmarksMix} from './channel_bookmark';
describe('ClientChannelBookmarks', () => {
let client: ClientChannelBookmarksMix & ClientBase;
beforeAll(() => {
client = TestHelper.createClient();
client.doFetch = jest.fn();
});
test('createChannelBookmark', async () => {
const channelId = 'channel_id';
const bookmark = {id: 'bookmark_id', display_name: 'bookmark_name'} as ChannelBookmark;
const expectedUrl = client.getChannelBookmarksRoute(channelId);
const expectedOptions = {
method: 'post',
body: bookmark,
headers: {'Connection-Id': ''},
};
await client.createChannelBookmark(channelId, bookmark);
expect(client.doFetch).toHaveBeenCalledWith(expectedUrl, expectedOptions);
});
test('updateChannelBookmark', async () => {
const channelId = 'channel_id';
const bookmark = {id: 'bookmark_id', display_name: 'new_bookmark_name'} as ChannelBookmark;
const connectionId = 'connection_id';
const expectedUrl = client.getChannelBookmarkRoute(channelId, bookmark.id);
const expectedOptions = {
method: 'patch',
body: bookmark,
headers: {'Connection-Id': connectionId},
};
await client.updateChannelBookmark(channelId, bookmark, connectionId);
expect(client.doFetch).toHaveBeenCalledWith(expectedUrl, expectedOptions);
});
test('updateChannelBookmarkSortOrder', async () => {
const channelId = 'channel_id';
const bookmarkId = 'bookmark_id';
const newSortOrder = 1;
const connectionId = 'connection_id';
const expectedUrl = `${client.getChannelBookmarkRoute(channelId, bookmarkId)}/sort_order`;
const expectedOptions = {
method: 'post',
body: newSortOrder,
headers: {'Connection-Id': connectionId},
};
await client.updateChannelBookmarkSortOrder(channelId, bookmarkId, newSortOrder, connectionId);
expect(client.doFetch).toHaveBeenCalledWith(expectedUrl, expectedOptions);
});
test('deleteChannelBookmark', async () => {
const channelId = 'channel_id';
const bookmarkId = 'bookmark_id';
const connectionId = 'connection_id';
const expectedUrl = client.getChannelBookmarkRoute(channelId, bookmarkId);
const expectedOptions = {
method: 'delete',
headers: {'Connection-Id': connectionId},
};
await client.deleteChannelBookmark(channelId, bookmarkId, connectionId);
expect(client.doFetch).toHaveBeenCalledWith(expectedUrl, expectedOptions);
});
test('getChannelBookmarksForChannel', async () => {
const channelId = 'channel_id';
const since = 123456;
const groupLabel = 'group_label';
const expectedUrl = `${client.getChannelBookmarksRoute(channelId)}${buildQueryString({bookmarks_since: since})}`;
const expectedOptions = {method: 'get', groupLabel};
await client.getChannelBookmarksForChannel(channelId, since, groupLabel);
expect(client.doFetch).toHaveBeenCalledWith(expectedUrl, expectedOptions);
});
});