* Add license load metric to About screen - Add REST endpoint to fetch license load percentage - Display load metric in About screen next to server version Fixes: https://mattermost.atlassian.net/browse/MM-63728 * MM-63728: Address PR feedback from enahum - Move license load metric fetch to a remote action - Use isMinimumServerVersion to check for server 10.8.0 or higher 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * MM-63728: Simplify getLicenseLoadMetric to directly return number 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * MM-63728: Move getLicenseLoadMetric to dedicated license.ts file - Create new remote action file specifically for license-related functions - Add test file for the license actions - Update imports in about.tsx 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * MM-63728: Remove redundant license check in about.tsx - Rely on getLicenseLoadMetric to handle the license check 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * MM-63728: Update E2E tests for license load metric - Add license load metric test IDs to about screen - Update E2E test to check for load metric when license is enabled - Handle cases where server might not support the feature 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * recover app/actions/remote/general.ts * MM-63728: Return error from getLicenseLoadMetric instead of silent failure - Remove silent failure and debug logging - Return the error object when API call fails - Update the About component to handle possible error responses - Update tests to verify error handling 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * MM-63728: Remove groupLabel parameter from getLicenseLoadMetric - Remove groupLabel parameter from client getLicenseLoadMetric method in interface and implementation - Update client tests to reflect the parameter removal - Update license action test to verify no parameter is passed 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * simplify about screen checks * MM-63728: Use jest.mocked and real version checks in license tests - Removed isMinimumServerVersion mock, letting tests use real version checking - Used proper type casting for mock Client - Added comprehensive version compatibility test cases - Simplified test setup 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * MM-63728: Remove redundant server version test - Removed redundant test for different server versions - Existing tests already cover the necessary version compatibility cases 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * MM-63728: Refactor license test to use better mocking pattern - Refactored the test file to use a better mocking pattern similar to custom_emoji.test.ts - Simplified mock declarations using jest.mock() - Added type import for Client for better readability - Improved type casting for mock objects 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * npm run fix --------- Co-authored-by: Claude <noreply@anthropic.com>
74 lines
2.9 KiB
TypeScript
74 lines
2.9 KiB
TypeScript
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
// See LICENSE.txt for license information.
|
|
|
|
import NetworkManager from '@managers/network_manager';
|
|
|
|
import {getLicenseLoadMetric} from './license';
|
|
import {forceLogoutIfNecessary} from './session';
|
|
|
|
import type {Client} from '@client/rest';
|
|
|
|
jest.mock('@constants/device', () => ({}), {virtual: true});
|
|
jest.mock('@database/manager', () => ({}), {virtual: true});
|
|
|
|
jest.mock('@managers/network_manager');
|
|
jest.mock('./session');
|
|
|
|
describe('Actions.Remote.License', () => {
|
|
const serverUrl = 'https://server.com';
|
|
|
|
beforeEach(() => {
|
|
jest.clearAllMocks();
|
|
});
|
|
|
|
describe('getLicenseLoadMetric', () => {
|
|
it('should return null if not licensed', async () => {
|
|
const result = await getLicenseLoadMetric(serverUrl, '10.8.0', false);
|
|
expect(result).toBeNull();
|
|
expect(NetworkManager.getClient).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it('should return null if server version is less than minimum', async () => {
|
|
const result = await getLicenseLoadMetric(serverUrl, '10.7.0', true);
|
|
expect(result).toBeNull();
|
|
expect(NetworkManager.getClient).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it('should fetch and return load metric if licensed and minimum version is met', async () => {
|
|
const mockClient = {
|
|
getLicenseLoadMetric: jest.fn().mockResolvedValue({load: 100}),
|
|
};
|
|
jest.mocked(NetworkManager.getClient).mockReturnValue(mockClient as unknown as Client);
|
|
|
|
const result = await getLicenseLoadMetric(serverUrl, '10.8.0', true);
|
|
|
|
expect(NetworkManager.getClient).toHaveBeenCalledWith(serverUrl);
|
|
expect(mockClient.getLicenseLoadMetric).toHaveBeenCalledWith();
|
|
expect(result).toBe(100);
|
|
});
|
|
|
|
it('should return null if response does not contain load or load is 0', async () => {
|
|
const mockClient = {
|
|
getLicenseLoadMetric: jest.fn().mockResolvedValue({load: 0}),
|
|
};
|
|
jest.mocked(NetworkManager.getClient).mockReturnValue(mockClient as unknown as Client);
|
|
|
|
const result = await getLicenseLoadMetric(serverUrl, '10.8.0', true);
|
|
|
|
expect(result).toBeNull();
|
|
});
|
|
|
|
it('should return error and call forceLogoutIfNecessary if API call fails', async () => {
|
|
const mockError = new Error('API error');
|
|
const mockClient = {
|
|
getLicenseLoadMetric: jest.fn().mockRejectedValue(mockError),
|
|
};
|
|
jest.mocked(NetworkManager.getClient).mockReturnValue(mockClient as unknown as Client);
|
|
|
|
const result = await getLicenseLoadMetric(serverUrl, '10.8.0', true);
|
|
|
|
expect(result).toEqual({error: mockError});
|
|
expect(forceLogoutIfNecessary).toHaveBeenCalledWith(serverUrl, mockError);
|
|
});
|
|
});
|
|
});
|