mattermost-mobile/app/client/rest/groups.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

103 lines
3.2 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 {PER_PAGE_DEFAULT} from './constants';
import type ClientBase from './base';
import type {ClientGroupsMix} from './groups';
describe('ClientGroups', () => {
let client: ClientGroupsMix & ClientBase;
beforeAll(() => {
client = TestHelper.createClient();
client.doFetch = jest.fn();
});
test('getGroups', async () => {
const params = {
query: 'test',
filterAllowReference: true,
page: 1,
perPage: 10,
since: 0,
includeMemberCount: true,
};
await client.getGroups(params);
expect(client.doFetch).toHaveBeenCalledWith(
`${client.urlVersion}/groups${buildQueryString({
q: params.query,
filter_allow_reference: params.filterAllowReference,
page: params.page,
per_page: params.perPage,
since: params.since,
include_member_count: params.includeMemberCount,
})}`,
{method: 'get'},
);
// Test with default values
await client.getGroups({});
expect(client.doFetch).toHaveBeenCalledWith(
`${client.urlVersion}/groups${buildQueryString({
q: '',
filter_allow_reference: true,
page: 0,
per_page: PER_PAGE_DEFAULT,
since: 0,
include_member_count: false,
})}`,
{method: 'get'},
);
});
test('getAllGroupsAssociatedToChannel', async () => {
const channelId = 'channel1';
const groupLabel = 'testGroup';
await client.getAllGroupsAssociatedToChannel(channelId, undefined, groupLabel);
expect(client.doFetch).toHaveBeenCalledWith(
`${client.urlVersion}/channels/${channelId}/groups${buildQueryString({
paginate: false,
filter_allow_reference: false,
include_member_count: true,
})}`,
{method: 'get', groupLabel},
);
});
test('getAllGroupsAssociatedToTeam', async () => {
const teamId = 'team1';
await client.getAllGroupsAssociatedToTeam(teamId);
expect(client.doFetch).toHaveBeenCalledWith(
`${client.urlVersion}/teams/${teamId}/groups${buildQueryString({
paginate: false,
filter_allow_reference: false,
})}`,
{method: 'get'},
);
});
test('getAllGroupsAssociatedToMembership', async () => {
const userId = 'user1';
const groupLabel = 'testGroup';
await client.getAllGroupsAssociatedToMembership(userId, undefined, groupLabel);
expect(client.doFetch).toHaveBeenCalledWith(
`${client.urlVersion}/users/${userId}/groups${buildQueryString({
paginate: false,
filter_allow_reference: false,
})}`,
{method: 'get', groupLabel},
);
});
});