mattermost-mobile-upstream/app/client/rest/ephemeral_mode.test.ts
Carlos Garcia ad6b834d34
Mm 68296 audit ephemeral mode events (#10139)
* consider all error paths when wiping server artifacts

* log events related to ephemeral mode to keep an audit log server side

* adds playbook run delete count to cleanup audit events

* sends signature as proof for auditing wipe events

* fixes some missed data in audit events

* throw and log errors while enqueuing audit events

* report exact deleted count on audit event

* test terminate session prunes audit event queue in all cases

* assert on queue lenght in tests

* fetch count inside write transaction to return accurate value

* remove delete count expectations from tests since unsafe where clauses are not supported by loki
2026-09-23 13:48:14 +02:00

89 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 type ClientBase from './base';
import type {ClientEphemeralModeMix} from './ephemeral_mode';
describe('ClientEphemeralMode', () => {
let client: ClientEphemeralModeMix & ClientBase;
beforeAll(() => {
client = TestHelper.createClient();
client.doFetch = jest.fn();
});
it('should POST offline_time_minutes and purge_at to the purge route', async () => {
const expectedUrl = `${client.urlVersion}/ephemeral_mode/purge`;
const expectedOptions = {
method: 'post',
body: {offline_time_minutes: 42, purge_at: 1000},
};
await client.logOfflinePurge(42, 1000);
expect(client.doFetch).toHaveBeenCalledWith(expectedUrl, expectedOptions);
});
it('should include error_reason in the purge body when a reason is passed', async () => {
const expectedUrl = `${client.urlVersion}/ephemeral_mode/purge`;
const expectedOptions = {
method: 'post',
body: {offline_time_minutes: 42, purge_at: 1000, error_reason: 'database wipe failed after retries'},
};
await client.logOfflinePurge(42, 1000, 'database wipe failed after retries');
expect(client.doFetch).toHaveBeenCalledWith(expectedUrl, expectedOptions);
});
it('should POST posts_deleted, playbook_runs_deleted, and cleanup_at to the cleanup route', async () => {
const expectedUrl = `${client.urlVersion}/ephemeral_mode/cleanup`;
const expectedOptions = {
method: 'post',
body: {posts_deleted: 3, playbook_runs_deleted: 1, cleanup_at: 2000},
};
await client.logCleanup(3, 1, 2000);
expect(client.doFetch).toHaveBeenCalledWith(expectedUrl, expectedOptions);
});
it('should include error_reason in the cleanup body when a reason is passed', async () => {
const expectedUrl = `${client.urlVersion}/ephemeral_mode/cleanup`;
const expectedOptions = {
method: 'post',
body: {posts_deleted: 3, playbook_runs_deleted: 1, cleanup_at: 2000, error_reason: 'cleanup failed before completion'},
};
await client.logCleanup(3, 1, 2000, 'cleanup failed before completion');
expect(client.doFetch).toHaveBeenCalledWith(expectedUrl, expectedOptions);
});
it('should POST signature and wipe_at to the wipe route', async () => {
const expectedUrl = `${client.urlVersion}/ephemeral_mode/wipe`;
const expectedOptions = {
method: 'post',
body: {signature: 'signature123', wipe_at: 3000},
};
await client.logSessionWipe('signature123', 3000);
expect(client.doFetch).toHaveBeenCalledWith(expectedUrl, expectedOptions);
});
it('should include error_reason in the wipe body when a reason is passed', async () => {
const expectedUrl = `${client.urlVersion}/ephemeral_mode/wipe`;
const expectedOptions = {
method: 'post',
body: {signature: 'signature123', wipe_at: 3000, error_reason: 'terminateSession failed: databaseOperation'},
};
await client.logSessionWipe('signature123', 3000, 'terminateSession failed: databaseOperation');
expect(client.doFetch).toHaveBeenCalledWith(expectedUrl, expectedOptions);
});
});