mattermost-mobile-upstream/app/actions/remote/entry/app.test.ts
yasser khan ef1ecc1d9e
fix: stabilize server switch, saved posts, favorites, and related runtime races (#10122)
test(e2e): stabilize Detox and Maestro suites and harden CI

- Re-enable stabilized cases and document remaining iOS skips.
- Improve selectors, navigation recovery, state assertions, and retry limits.
- Harden API retries, fixture setup, and server configuration cleanup.
- Increase Detox shards to 24 and improve reporting, artifact uploads, and timeout handling.
- Add testIDs and unit-test fixes; revert unproven app behavior changes.
2026-09-09 00:35:15 +05:30

67 lines
2.4 KiB
TypeScript

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import {refetchCurrentUser} from '@actions/remote/user';
import DatabaseManager from '@database/manager';
import {getCurrentUserId, prepareCommonSystemValues} from '@queries/servers/system';
import {appEntry} from './app';
jest.mock('@actions/local/systems');
jest.mock('@actions/remote/user');
jest.mock('@agents/actions/remote/agents');
// The shared mock in test/setup.ts is a singleton, so reassigning its methods in
// beforeEach is order-sensitive; keep this file-local factory.
jest.mock('@database/manager', () => ({
__esModule: true,
default: {
getServerDatabaseAndOperator: jest.fn(),
serverDatabases: {},
},
}));
jest.mock('@managers/websocket_manager');
jest.mock('@queries/servers/system');
jest.mock('./common');
describe('actions/remote/entry/app', () => {
const serverUrl = 'https://server.example.com';
const mockOperator = {
batchRecords: jest.fn(),
};
const mockDatabase = {};
beforeEach(() => {
jest.clearAllMocks();
jest.mocked(DatabaseManager.getServerDatabaseAndOperator).mockReturnValue({
database: mockDatabase,
operator: mockOperator,
} as unknown as ReturnType<typeof DatabaseManager.getServerDatabaseAndOperator>);
jest.mocked(prepareCommonSystemValues).mockResolvedValue([]);
jest.mocked(getCurrentUserId).mockResolvedValue('user1');
jest.mocked(refetchCurrentUser).mockResolvedValue({currentUserId: 'user1'});
});
it('should seed the current user by calling refetchCurrentUser when getCurrentUserId returns no value', async () => {
jest.mocked(getCurrentUserId).mockResolvedValueOnce('');
jest.mocked(refetchCurrentUser).mockResolvedValueOnce({currentUserId: 'seededUser'});
const result = await appEntry(serverUrl);
expect(refetchCurrentUser).toHaveBeenCalledWith(serverUrl, undefined);
expect(result).toEqual({});
});
it('should return an error when refetchCurrentUser fails to seed the current user', async () => {
jest.mocked(getCurrentUserId).mockResolvedValueOnce('');
jest.mocked(refetchCurrentUser).mockResolvedValueOnce({error: 'No user fetched'});
const result = await appEntry(serverUrl);
expect(result).toEqual({error: new Error('appEntry: failed to seed current user')});
});
});