mattermost-mobile-upstream/app/actions/remote/session_attributes.test.ts
Mattermost Build 3cf16e70c1
[MM-68986][MM-69203] Add module to collect Session Attributes from Mobile App (#9830) (#10073)
* [MM-68986] Add module to collect Session Attributes from Mobile App

* PR feedback

* Add license downgrade check

* Fix android build

---------


(cherry picked from commit 88a23376bb)

Co-authored-by: Devin Binnie <52460000+devinbinnie@users.noreply.github.com>
2026-08-18 14:05:37 -04:00

52 lines
1.7 KiB
TypeScript

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import NetworkManager from '@managers/network_manager';
import {fetchSessionAttributesManifest} from './session_attributes';
jest.mock('@managers/network_manager');
jest.mock('@utils/log');
const serverUrl = 'https://chat.example.com';
const manifest: SAField[] = [
{name: 'os_platform', type: 'string', ttl_seconds: 0, grace_period_seconds: 0},
];
describe('fetchSessionAttributesManifest', () => {
const mockClient = {getSessionAttributesManifest: jest.fn()};
beforeEach(() => {
jest.clearAllMocks();
(NetworkManager.getClient as jest.Mock).mockReturnValue(mockClient);
});
it('should return the manifest from the client', async () => {
mockClient.getSessionAttributesManifest.mockResolvedValue(manifest);
const result = await fetchSessionAttributesManifest(serverUrl);
expect(result).toEqual({manifest});
});
it('should return the error when the client request fails', async () => {
const error = new Error('request failed');
mockClient.getSessionAttributesManifest.mockRejectedValue(error);
const result = await fetchSessionAttributesManifest(serverUrl);
expect(result).toEqual({error});
});
it('should return the error when the client cannot be resolved', async () => {
const error = new Error('no client');
(NetworkManager.getClient as jest.Mock).mockImplementation(() => {
throw error;
});
const result = await fetchSessionAttributesManifest(serverUrl);
expect(result).toEqual({error});
});
});