mattermost-mobile/app/client/rest/channel_bookmark.test.ts
Elias Nahum d1d3fda83a
Request metrics improvements (#8420)
* Network metrics

* update network-client ref

* fix unit tests

* missing catch error parsing

* Replace API's to fetch all teams and channels for a user
Update groupLabel to use a type definition
Include effective Latency and Average Speed in the metrics
Include parallel and sequential request counts

* update network library and fix tests

* feat(MM-61865): send network request telemetry data to the server (#8436)

* feat(MM-61865): send network info telemetry data

* unit testing

* fix latency vs effectiveLatency

* cleanup test

* fix failing tests

* fix spelling error

* fix failing test

* more cleanup

* fix: improve parallel requests calculation (#8439)

* fix: improve parallel requests calculation

* fix test issue

* multiple parallelGroups testing

* calculateAverageSpeedWithCategories test

* categorizedRequests in it's own describe

* clean up duplicate tests

* check for when groupLabel is non-existent

* a case when groupLabel is non-existent

* more testing with effective latency.

* resolveAndFlattenModels with a capital F

* add try..catch within resolveAndFlattenModels

* update groupLabel to fix failing lint

* fix linting issue due to unknown group label

* forgot to push changes

* fix the indentation problem again

* add env var option for COLLECT_NETWORK_METRICS

---------

Co-authored-by: Rahim Rahman <rahim.rahman@mattermost.com>
Co-authored-by: Mattermost Build <build@mattermost.com>
2025-01-16 13:55:29 -07: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 = 'Login';
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);
});
});