diff --git a/ee/packages/omni-core-ee/jest.config.ts b/ee/packages/omni-core-ee/jest.config.ts new file mode 100644 index 0000000000000..c18c8ae02465c --- /dev/null +++ b/ee/packages/omni-core-ee/jest.config.ts @@ -0,0 +1,6 @@ +import server from '@rocket.chat/jest-presets/server'; +import type { Config } from 'jest'; + +export default { + preset: server.preset, +} satisfies Config; diff --git a/ee/packages/omni-core-ee/src/isDepartmentCreationAvailable.spec.ts b/ee/packages/omni-core-ee/src/isDepartmentCreationAvailable.spec.ts new file mode 100644 index 0000000000000..a70c804b1096f --- /dev/null +++ b/ee/packages/omni-core-ee/src/isDepartmentCreationAvailable.spec.ts @@ -0,0 +1,45 @@ +import { License, MockedLicenseBuilder } from '@rocket.chat/license'; +import type { ILivechatDepartmentModel } from '@rocket.chat/model-typings'; +import { registerModel } from '@rocket.chat/models'; +import { isDepartmentCreationAvailable } from '@rocket.chat/omni-core'; + +import { isDepartmentCreationAvailablePatch } from './isDepartmentCreationAvailable'; + +beforeEach(async () => { + await License.setWorkspaceUrl('http://localhost:3000'); + + License.setLicenseLimitCounter('activeUsers', () => 0); + License.setLicenseLimitCounter('guestUsers', () => 0); + License.setLicenseLimitCounter('roomsPerGuest', async () => 0); + License.setLicenseLimitCounter('privateApps', () => 0); + License.setLicenseLimitCounter('marketplaceApps', () => 0); + License.setLicenseLimitCounter('monthlyActiveContacts', async () => 0); + + License.setLicenseLimitCounter('activeUsers', () => 1); +}); + +beforeAll(async () => { + isDepartmentCreationAvailablePatch(); + + registerModel('ILivechatDepartmentModel', { countTotal: () => 1 } as unknown as ILivechatDepartmentModel); +}); + +it('should skip the check if Livechat Enterprise is enabled', async () => { + const license = new MockedLicenseBuilder(); + license.withGrantedModules(['livechat-enterprise']); + await License.setLicense(await license.sign()); + + const isAvailable = await isDepartmentCreationAvailable(); + + expect(isAvailable).toBe(true); +}); + +it('should not skip the check if Livechat Enterprise is not enabled', async () => { + const license = new MockedLicenseBuilder(); + license.withGrantedModules([]); + await License.setLicense(await license.sign()); + + const isAvailable = await isDepartmentCreationAvailable(); + + expect(isAvailable).toBe(false); +}); diff --git a/packages/omni-core/jest.config.ts b/packages/omni-core/jest.config.ts new file mode 100644 index 0000000000000..c18c8ae02465c --- /dev/null +++ b/packages/omni-core/jest.config.ts @@ -0,0 +1,6 @@ +import server from '@rocket.chat/jest-presets/server'; +import type { Config } from 'jest'; + +export default { + preset: server.preset, +} satisfies Config; diff --git a/packages/omni-core/src/isDepartmentCreationAvailable.spec.ts b/packages/omni-core/src/isDepartmentCreationAvailable.spec.ts new file mode 100644 index 0000000000000..94a275bf7b91c --- /dev/null +++ b/packages/omni-core/src/isDepartmentCreationAvailable.spec.ts @@ -0,0 +1,20 @@ +import type { ILivechatDepartmentModel } from '@rocket.chat/model-typings'; +import { registerModel } from '@rocket.chat/models'; + +import { isDepartmentCreationAvailable } from './isDepartmentCreationAvailable'; + +it('should be available if there are no existing departments', async () => { + registerModel('ILivechatDepartmentModel', { countTotal: () => 0 } as unknown as ILivechatDepartmentModel); + + const isAvailable = await isDepartmentCreationAvailable(); + + expect(isAvailable).toBe(true); +}); + +it('should not be available if there are existing departments', async () => { + registerModel('ILivechatDepartmentModel', { countTotal: () => 1 } as unknown as ILivechatDepartmentModel); + + const isAvailable = await isDepartmentCreationAvailable(); + + expect(isAvailable).toBe(false); +});