mirror of
https://github.com/mattermost/mattermost-mobile.git
synced 2026-11-05 18:38:54 +00:00
* Expo-Router partial migration * Full migration to ExpoRouter * i18n * add tests * Merge branch 'main' into expo-router * align package-lock.json * i18n * feedback review * feedback review * android 16kb patch * Refactored emoji picker keyboard using a state machine * set android launch_screen in drawables instead of layout * no conditional hooks * remove duplicate call in test * address feedback * fix tests and address more feedback * small corrections * small corrections * small corrections * fix draft test * fix draft test 2 * remove navigateToScreen in draff test * fix nit in draft test * remove doc file * Feedback review * fix snapshots * improve test coverage * fix i18n * Upgrade t o RN 0.83, other dependencies and new architecture (#9737) * library hardware-keyboard android new arch support fix * library rnshare android new arch support fix * library rnutils android new arch support fix * library secure-pdf-viewer add new arch support * Enable new arch on iOS and Android * update emm and network client with new-arch * update intune to use new-arch * performance improvements * fix tests * fixes post input on new-arch * fix android emoji picker * remove doc * run tests in parallel * upgrade to React Native 0.83.9, Expo 55, React 19, and New Architecture Bumps core dependencies to their latest versions: - React Native 0.77.3 → 0.83.9 (New Architecture enabled) - React 18.3.1 → 19.2.5 - Expo SDK 52 → 55 - TypeScript 5.8.3 → 6.0.3 - Node.js 22.16.0 → 24.15.0 - react-native-reanimated 3.17.3 → 4.3.0 - Various other dependency upgrades Migrates iOS AppDelegate from Objective-C to Swift, updates Android build tooling and Gradle wrapper, refreshes all patches and font assets, and adapts app code, tests, and CI workflows throughout for API changes introduced by these upgrades. * remove unecessary dismissKeyboard in notifications * feedback review * update intune to use new-arch * update @mattermost deps * missing i18n string * additional fixes * update fastlane
152 lines
6.6 KiB
TypeScript
152 lines
6.6 KiB
TypeScript
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
// See LICENSE.txt for license information.
|
|
|
|
import {PUSH_PROXY_RESPONSE_VERIFIED, PUSH_PROXY_STATUS_VERIFIED} from '@constants/push_proxy';
|
|
import DatabaseManager from '@database/manager';
|
|
import NetworkManager from '@managers/network_manager';
|
|
import {getDeviceToken} from '@queries/app/global';
|
|
import {getExpandedLinks, getPushVerificationStatus} from '@queries/servers/system';
|
|
import TestHelper from '@test/test_helper';
|
|
|
|
import {doPing, getRedirectLocation} from './general';
|
|
|
|
jest.mock('@managers/network_manager', () => ({
|
|
createClient: jest.fn(),
|
|
getClient: jest.fn(),
|
|
invalidateClient: jest.fn(),
|
|
}));
|
|
jest.mock('@queries/app/global', () => ({getDeviceToken: jest.fn()}));
|
|
jest.mock('@queries/servers/system', () => ({
|
|
...jest.requireActual('@queries/servers/system'),
|
|
getExpandedLinks: jest.fn(),
|
|
getPushVerificationStatus: jest.fn(),
|
|
}));
|
|
jest.mock('./session', () => ({forceLogoutIfNecessary: jest.fn()}));
|
|
jest.mock('@utils/log', () => ({logDebug: jest.fn()}));
|
|
|
|
const serverUrl = 'http://server.com';
|
|
|
|
const makePingClient = (overrides: Partial<{ping: jest.Mock}> = {}) => ({
|
|
ping: jest.fn().mockResolvedValue({ok: true, code: 200, data: {}, headers: {}}),
|
|
...overrides,
|
|
});
|
|
|
|
describe('doPing', () => {
|
|
beforeEach(() => {
|
|
jest.clearAllMocks();
|
|
});
|
|
|
|
it('should return error when createClient fails and no client provided', async () => {
|
|
(NetworkManager.createClient as jest.Mock).mockRejectedValue(new Error('network error'));
|
|
|
|
const result = await doPing(serverUrl, false);
|
|
expect(result).toHaveProperty('error');
|
|
});
|
|
|
|
it('should return empty object on successful ping without push proxy verification', async () => {
|
|
const mockClient = makePingClient();
|
|
(NetworkManager.createClient as jest.Mock).mockResolvedValue(mockClient);
|
|
|
|
const result = await doPing(serverUrl, false);
|
|
expect(result).toEqual({});
|
|
});
|
|
|
|
it('should return certificate error on 401 response', async () => {
|
|
const mockClient = makePingClient({ping: jest.fn().mockResolvedValue({ok: false, code: 401, headers: {}})});
|
|
(NetworkManager.createClient as jest.Mock).mockResolvedValue(mockClient);
|
|
|
|
const result = await doPing(serverUrl, false);
|
|
expect(result).toHaveProperty('error');
|
|
expect((result as any).error.intl.id).toBe('mobile.server_requires_client_certificate');
|
|
});
|
|
|
|
it('should return ping error and invalidate client on non-ok response', async () => {
|
|
const mockClient = makePingClient({ping: jest.fn().mockResolvedValue({ok: false, code: 500, headers: {}})});
|
|
(NetworkManager.createClient as jest.Mock).mockResolvedValue(mockClient);
|
|
|
|
const result = await doPing(serverUrl, false);
|
|
expect(result).toHaveProperty('error');
|
|
expect(NetworkManager.invalidateClient).toHaveBeenCalledWith(serverUrl);
|
|
});
|
|
|
|
it('should not invalidate client when client is provided externally', async () => {
|
|
const mockClient = makePingClient({ping: jest.fn().mockResolvedValue({ok: false, code: 500, headers: {}})});
|
|
|
|
const result = await doPing(serverUrl, false, 5000, undefined, mockClient as any);
|
|
expect(result).toHaveProperty('error');
|
|
expect(NetworkManager.invalidateClient).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it('should return ping error on network exception', async () => {
|
|
const mockClient = makePingClient({ping: jest.fn().mockRejectedValue(new Error('timeout'))});
|
|
(NetworkManager.createClient as jest.Mock).mockResolvedValue(mockClient);
|
|
|
|
const result = await doPing(serverUrl, false);
|
|
expect(result).toHaveProperty('error');
|
|
expect(NetworkManager.invalidateClient).toHaveBeenCalledWith(serverUrl);
|
|
});
|
|
|
|
it('should return canReceiveNotifications when verifyPushProxy is true and device token returned', async () => {
|
|
(getPushVerificationStatus as jest.Mock).mockResolvedValue('unknown');
|
|
(getDeviceToken as jest.Mock).mockResolvedValue('token123');
|
|
const mockClient = makePingClient({
|
|
ping: jest.fn().mockResolvedValue({ok: true, code: 200, data: {CanReceiveNotifications: PUSH_PROXY_RESPONSE_VERIFIED}, headers: {}}),
|
|
});
|
|
(NetworkManager.createClient as jest.Mock).mockResolvedValue(mockClient);
|
|
|
|
const result = await doPing(serverUrl, true) as any;
|
|
expect(result.canReceiveNotifications).toBe(PUSH_PROXY_RESPONSE_VERIFIED);
|
|
});
|
|
|
|
it('should skip device token fetch when push proxy already verified', async () => {
|
|
await TestHelper.setupServerDatabase(serverUrl);
|
|
(getPushVerificationStatus as jest.Mock).mockResolvedValue(PUSH_PROXY_STATUS_VERIFIED);
|
|
const mockClient = makePingClient({
|
|
ping: jest.fn().mockResolvedValue({ok: true, code: 200, data: {CanReceiveNotifications: null}, headers: {}}),
|
|
});
|
|
|
|
const result = await doPing(serverUrl, true, 5000, undefined, mockClient as any) as any;
|
|
expect(getDeviceToken).not.toHaveBeenCalled();
|
|
expect(result.canReceiveNotifications).toBe(PUSH_PROXY_RESPONSE_VERIFIED);
|
|
|
|
await DatabaseManager.destroyServerDatabase(serverUrl);
|
|
});
|
|
});
|
|
|
|
describe('getRedirectLocation', () => {
|
|
beforeEach(async () => {
|
|
jest.clearAllMocks();
|
|
await TestHelper.setupServerDatabase(serverUrl);
|
|
});
|
|
|
|
afterEach(async () => {
|
|
await DatabaseManager.destroyServerDatabase(serverUrl);
|
|
});
|
|
|
|
it('should store the expanded link and return it', async () => {
|
|
const mockClient = {getRedirectLocation: jest.fn().mockResolvedValue({location: 'https://expanded.url/page'})};
|
|
(NetworkManager.getClient as jest.Mock).mockReturnValue(mockClient);
|
|
(getExpandedLinks as jest.Mock).mockResolvedValue({});
|
|
|
|
const result = await getRedirectLocation(serverUrl, 'https://short.url') as any;
|
|
expect(result.expandedLink.location).toBe('https://expanded.url/page');
|
|
});
|
|
|
|
it('should return expandedLink without storing when no location in response', async () => {
|
|
const mockClient = {getRedirectLocation: jest.fn().mockResolvedValue({})};
|
|
(NetworkManager.getClient as jest.Mock).mockReturnValue(mockClient);
|
|
|
|
const result = await getRedirectLocation(serverUrl, 'https://short.url') as any;
|
|
expect(result.expandedLink).toEqual({});
|
|
});
|
|
|
|
it('should return error when client throws', async () => {
|
|
(NetworkManager.getClient as jest.Mock).mockImplementation(() => {
|
|
throw new Error('no client');
|
|
});
|
|
|
|
const result = await getRedirectLocation(serverUrl, 'https://short.url') as any;
|
|
expect(result).toHaveProperty('error');
|
|
});
|
|
});
|