Files
upstream-rocketchat/packages/apps/tests/server/managers/AppExternalComponentManager.test.ts
upstream-mirror 30810eecd7
Some checks failed
Create issues from TODOs / todos (push) Failing after 3s
Close inactive issues / close-issues (push) Has been cancelled
Deploy GitHub Pages / deploy-preview (push) Has been cancelled
CI / ⚙️ Variables Setup (push) Has been cancelled
CI / ⚙️ Test Guard (push) Has been cancelled
CI / 🚀 Notify external services - draft (push) Has been cancelled
CI / 📦 Build Packages (push) Has been cancelled
CI / 📦 Meteor Build (coverage) (push) Has been cancelled
CI / 📦 Meteor Build (production) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [account-service presence-service omnichannel-transcript-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [account-service presence-service omnichannel-transcript-service], fips) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [authorization-service queue-worker-service ddp-streamer-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [authorization-service queue-worker-service ddp-streamer-service], fips) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], coverage) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], fips) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [account-service presence-service omnichannel-transcript-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [authorization-service queue-worker-service ddp-streamer-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [rocketchat], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [rocketchat], coverage) (push) Has been cancelled
CI / 🚢 Publish Docker Images (ghcr.io) (push) Has been cancelled
CI / 📦 Track Image Sizes (push) Has been cancelled
CI / 🔎 Code Check - Action Lint (push) Has been cancelled
CI / 🔎 Code Check (push) Has been cancelled
CI / 🔨 Test Storybook (push) Has been cancelled
CI / 🔨 Test Unit (push) Has been cancelled
CI / 🔨 Test API (CE) (push) Has been cancelled
CI / 🔨 Test API Livechat (CE) (push) Has been cancelled
CI / 🔨 Test UI (CE) (push) Has been cancelled
CI / 🔨 Test API (EE) (push) Has been cancelled
CI / 🔨 Test API Livechat (EE) (push) Has been cancelled
CI / 🔨 Test API Apps (deno-runtime - EE) (push) Has been cancelled
CI / 🔨 Test UI (EE) (push) Has been cancelled
CI / 🔨 Test API (FIPS) (push) Has been cancelled
CI / 🔨 Test API Livechat (FIPS) (push) Has been cancelled
CI / 🔨 Test UI (FIPS) (push) Has been cancelled
CI / 🔨 Test Federation Matrix (push) Has been cancelled
CI / 📊 Report Coverage (push) Has been cancelled
CI / ✅ Tests Done (push) Has been cancelled
CI / 🚀 Publish build assets (push) Has been cancelled
CI / 🚀 Publish Docker Images (DockerHub) (push) Has been cancelled
CI / 🚀 Notify external services (push) Has been cancelled
CI / Update Version Durability (push) Has been cancelled
Release / Release (push) Has been cancelled
Auto-close duplicate issues / auto-close-duplicates (push) Failing after 1s
Code scanning - action / CodeQL-Build (push) Failing after 2s
snapshot of https://github.com/RocketChat/Rocket.Chat.git (develop, 2026-09-16; blobs > 131072B omitted)
2026-09-16 01:21:02 +05:00

138 lines
4.9 KiB
TypeScript

import * as assert from 'node:assert';
import { describe, it } from 'node:test';
import type { IExternalComponent } from '@rocket.chat/apps-engine/definition/externalComponent/IExternalComponent';
import { ExternalComponentLocation } from '@rocket.chat/apps-engine/definition/externalComponent/IExternalComponent';
import { AppExternalComponentManager } from '../../../src/server/managers';
describe('AppExternalComponentManager', () => {
const mockExternalComponent1: IExternalComponent = {
appId: '1eb382c0-3679-44a6-8af0-18802e342fb1',
name: 'TestExternalComponent1',
description: 'TestExternalComponent1',
url: '',
icon: '',
location: ExternalComponentLocation.CONTEXTUAL_BAR,
};
const mockExternalComponent2: IExternalComponent = {
appId: '125a944b-9747-4e6e-b029-6e9b26bb3481',
name: 'TestExternalComponent2',
description: 'TestExternalComponent2',
url: '',
icon: '',
location: ExternalComponentLocation.CONTEXTUAL_BAR,
};
const mockExternalComponent3: IExternalComponent = {
...mockExternalComponent2,
appId: mockExternalComponent1.appId,
name: mockExternalComponent2.name,
description: 'TestExternalComponent3',
};
function register(aecm: AppExternalComponentManager, externalComponent: IExternalComponent): void {
const { appId } = externalComponent;
aecm.addExternalComponent(appId, externalComponent);
aecm.registerExternalComponents(appId);
}
it('basicAppExternalComponentManager', () => {
const aecm = new AppExternalComponentManager();
assert.strictEqual((aecm as any).registeredExternalComponents.size, 0);
assert.strictEqual((aecm as any).appTouchedExternalComponents.size, 0);
});
it('verifyGetRegisteredExternalComponents', () => {
const aecm = new AppExternalComponentManager();
const component = mockExternalComponent1;
assert.strictEqual(aecm.getRegisteredExternalComponents().size, 0);
register(aecm, component);
assert.strictEqual(aecm.getRegisteredExternalComponents().size, 1);
});
it('verifyGetAppTouchedExternalComponents', () => {
const aecm = new AppExternalComponentManager();
const component = mockExternalComponent1;
assert.strictEqual(aecm.getAppTouchedExternalComponents().size, 0);
aecm.addExternalComponent(component.appId, component);
assert.strictEqual(aecm.getAppTouchedExternalComponents().size, 1);
});
it('verifyGetExternalComponents', () => {
const aecm = new AppExternalComponentManager();
const component = mockExternalComponent1;
assert.strictEqual(aecm.getExternalComponents(component.appId), null);
aecm.addExternalComponent(component.appId, component);
const components = aecm.getExternalComponents(component.appId);
assert.notStrictEqual(components, null);
assert.strictEqual(components!.size, 1);
});
it('verifyGetProvidedComponents', () => {
const aecm = new AppExternalComponentManager();
const component1 = mockExternalComponent1;
const component2 = mockExternalComponent2;
assert.strictEqual(Array.isArray(aecm.getProvidedComponents()), true);
register(aecm, component1);
register(aecm, component2);
assert.strictEqual(aecm.getProvidedComponents().length, 2);
});
it('verifyAddExternalComponent', () => {
const aecm1 = new AppExternalComponentManager();
const component1 = mockExternalComponent1;
const component3 = mockExternalComponent3;
aecm1.addExternalComponent(component1.appId, component1);
assert.strictEqual(aecm1.getAppTouchedExternalComponents().size, 1);
assert.strictEqual(aecm1.getExternalComponents(component1.appId).size, 1);
aecm1.addExternalComponent(component1.appId, component3);
assert.strictEqual(aecm1.getExternalComponents(component1.appId).size, 2);
});
it('verifyRegisterExternalComponents', () => {
const aecm = new AppExternalComponentManager();
const component = mockExternalComponent1;
assert.strictEqual(aecm.getRegisteredExternalComponents().size, 0);
register(aecm, component);
assert.strictEqual(aecm.getRegisteredExternalComponents().size, 1);
});
it('verifyUnregisterExternalComponents', () => {
const aecm = new AppExternalComponentManager();
const component = mockExternalComponent1;
register(aecm, component);
assert.strictEqual(aecm.getAppTouchedExternalComponents().size, 1);
assert.strictEqual(aecm.getRegisteredExternalComponents().size, 1);
aecm.unregisterExternalComponents(component.appId);
assert.strictEqual(aecm.getAppTouchedExternalComponents().size, 1);
assert.strictEqual(aecm.getRegisteredExternalComponents().size, 0);
});
it('verifyPurgeExternalComponents', () => {
const aecm = new AppExternalComponentManager();
const component = mockExternalComponent1;
register(aecm, component);
assert.strictEqual(aecm.getAppTouchedExternalComponents().size, 1);
assert.strictEqual(aecm.getRegisteredExternalComponents().size, 1);
aecm.purgeExternalComponents(component.appId);
assert.strictEqual(aecm.getAppTouchedExternalComponents().size, 0);
assert.strictEqual(aecm.getRegisteredExternalComponents().size, 0);
});
});