mattermost-mobile-upstream/app/actions/remote/systems.test.ts
Carlos Garcia a5ff8a0d95
Mm 68767 zero persistence (#9803)
* implements auto cache cleanup when zero persistence mode is enabled (0 value)

* uses memory flag with sqlite instead of loki when running in zero persistence mode

* renames ephemeral mode manager and improves readability

* zero persistence refactors and restore values during transitions

* fixes ephemeral mode tests

* use initializeClient instead of just initialize to wait for doReconnect to finish

that way teams loading is awaited while WS reconnects during ZPM transitions

* adds inital sync as a mount hook to prevent undesired load error states

during app cold start in ZPM mode, we need a way to load team and channels
without showing loading error during the transition. The nre is initial sync
hook allows for it

* reset started sync subject on wipe

* removes extra log lines

* resets tracked server during ephemeral mode transitions

* improvements to apply persistence mode changes when something fails

* address coderabbit PR suggestions

* add batching time logging

* throws ephemeral mode change error as is

* make deleteServerDatabaseFiles private

* inline derive persistence flag function

* return current user id when refetching current user

* support zero persistence mode server for push notifications

* adds support for zero persistence mode when sharing to mattermost

* adds clarifying comment

* catch and log error deleting files

* reorder translations to correct position

* adds some new tests to improve coverage

* ios push notification native fix

* logout when fetchMe fails with 401 status code during reconnection

* properly surface errors

* return proper false value when checking for zero persistence flag

* change comments and properly await on some operations

* prevent not set persistence mode to report as an error

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

* include servers with no persistence flag set in share list

* disable button for accessibility

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

* improves when to store and remove signing key from global area

* review push notification reception running in zero persistence mode

* add server to ephemeral mode manager right after login

---------

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
2026-07-16 13:55:45 +02:00

130 lines
4.2 KiB
TypeScript

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import DatabaseManager from '@database/manager';
import NetworkManager from '@managers/network_manager';
import {fetchDataRetentionPolicy, fetchConfigAndLicense} from './systems';
const serverUrl = 'baseHandler.test.com';
const globalPolicy = {
message_deletion_enabled: true,
file_deletion_enabled: true,
message_retention_cutoff: 30,
file_retention_cutoff: 30,
};
const teamPolicy = {
team_id: 'team1',
post_duration: 30,
};
const channelPolicy = {
channel_id: 'channel1',
post_duration: 30,
};
const config = {
DiagnosticsEnabled: 'true',
EnableDeveloper: 'true',
} as ClientConfig;
const license = {
IsLicensed: 'true',
DataRetention: 'true',
} as ClientLicense;
const mockClient = {
getGlobalDataRetentionPolicy: jest.fn(() => globalPolicy),
getTeamDataRetentionPolicies: jest.fn(() => ({policies: [teamPolicy], total_count: 1})),
getChannelDataRetentionPolicies: jest.fn(() => ({policies: [channelPolicy], total_count: 1})),
getClientConfigOld: jest.fn(() => config),
getClientLicenseOld: jest.fn(() => license),
};
jest.mock('@managers/network_manager', () => ({
getClient: () => mockClient,
}));
beforeAll(() => {
// eslint-disable-next-line
// @ts-ignore
NetworkManager.getClient = () => mockClient;
});
describe('systems', () => {
beforeEach(async () => {
await DatabaseManager.init([serverUrl]);
});
afterEach(async () => {
await DatabaseManager.destroyServerDatabase(serverUrl);
});
it('fetchDataRetentionPolicy - handle not found database', async () => {
const result = await fetchDataRetentionPolicy('foo') as {error: unknown};
expect(result).toBeDefined();
expect(result.error).toBeDefined();
});
it('fetchDataRetentionPolicy - base case', async () => {
const result = await fetchDataRetentionPolicy(serverUrl);
expect(result).toBeDefined();
expect(result.globalPolicy).toBeDefined();
expect(result.teamPolicies).toBeDefined();
expect(result.channelPolicies).toBeDefined();
expect(result.globalPolicy).toEqual(globalPolicy);
expect(result.teamPolicies).toEqual([teamPolicy]);
expect(result.channelPolicies).toEqual([channelPolicy]);
});
it('fetchDataRetentionPolicy - fetch only', async () => {
const result = await fetchDataRetentionPolicy(serverUrl, true);
expect(result).toBeDefined();
expect(result.globalPolicy).toBeDefined();
expect(result.teamPolicies).toBeDefined();
expect(result.channelPolicies).toBeDefined();
expect(result.globalPolicy).toEqual(globalPolicy);
expect(result.teamPolicies).toEqual([teamPolicy]);
expect(result.channelPolicies).toEqual([channelPolicy]);
});
it('fetchDataRetentionPolicy - error case', async () => {
mockClient.getGlobalDataRetentionPolicy.mockImplementationOnce(() => {
throw new Error('error');
});
const result = await fetchDataRetentionPolicy(serverUrl);
expect(result).toBeDefined();
expect(result.error).toBeDefined();
});
it('fetchConfigAndLicense - base case', async () => {
const result = await fetchConfigAndLicense(serverUrl);
expect(result).toBeDefined();
expect(result.config).toBeDefined();
expect(result.license).toBeDefined();
expect(result.config).toEqual(config);
expect(result.license).toEqual(license);
});
it('fetchConfigAndLicense - fetch only', async () => {
const result = await fetchConfigAndLicense(serverUrl, true);
expect(result).toBeDefined();
expect(result.config).toBeDefined();
expect(result.license).toBeDefined();
expect(result.config).toEqual(config);
expect(result.license).toEqual(license);
});
it('fetchConfigAndLicense - error case', async () => {
mockClient.getClientConfigOld.mockImplementationOnce(() => {
throw new Error('error');
});
const result = await fetchConfigAndLicense(serverUrl);
expect(result).toBeDefined();
expect(result.error).toBeDefined();
});
});