The open alternative to Salesforce, designed for AI.
TypeScript crmcrm-systemcustomergood-first-issuegraphqlhacktoberfestjavascriptmarketingmonoreponestjsopen-sourcepostgresqlreactreactjssalestypescriptweb
import { Test, type TestingModule } from '@nestjs/testing';
import { SupportDriver } from 'src/engine/core-modules/twenty-config/interfaces/support.interface';
import { ClientConfigService } from 'src/engine/core-modules/client-config/services/client-config.service';
import { ModelFamily } from 'src/engine/metadata-modules/ai/ai-models/types/model-family.enum';
import { type ModelId } from 'src/engine/metadata-modules/ai/ai-models/types/model-id.type';
import { ENTERPRISE_INSTANCE_TYPE } from 'twenty-shared/constants';
import { ClientConfigController } from './client-config.controller';
describe('ClientConfigController', () => {
let controller: ClientConfigController;
let clientConfigService: ClientConfigService;
beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
controllers: [ClientConfigController],
providers: [
{
provide: ClientConfigService,
useValue: {
getClientConfig: jest.fn(),
},
},
],
}).compile();
controller = module.get<ClientConfigController>(ClientConfigController);
clientConfigService = module.get<ClientConfigService>(ClientConfigService);
});
it('should be defined', () => {
expect(controller).toBeDefined();
});
describe('getClientConfig', () => {
it('should return client config from service', async () => {
const mockClientConfig = {
billing: {
isBillingEnabled: true,
billingUrl: 'https://billing.example.com',
trialPeriods: [
{
duration: 7,
isCreditCardRequired: false,
},
],
},
aiEvaluationModels: [],
aiModelTiers: [],
aiModels: [
{
modelId: 'openai/gpt-4o' as ModelId,
label: 'GPT-4o',
modelFamily: ModelFamily.GPT,
sdkPackage: '@ai-sdk/openai' as const,
inputCostPerMillionTokensInCredits: 2500000,
outputCostPerMillionTokensInCredits: 10000000,
},
],
authProviders: {
google: true,
magicLink: false,
password: true,
microsoft: false,
sso: [],
},
signInPrefilled: false,
isMultiWorkspaceEnabled: true,
isEmailVerificationRequired: false,
defaultSubdomain: 'app',
frontDomain: 'localhost',
serverUrl: 'http://localhost:3000',
publicFunctionDomain: null,
support: {
supportDriver: SupportDriver.NONE,
supportFrontChatId: undefined,
},
sentry: {
environment: 'development',
release: '1.0.0',
dsn: undefined,
tracesSampleRate: 0.1,
},
captcha: {
provider: undefined,
siteKey: undefined,
},
api: {
mutationMaximumAffectedRecords: 100,
},
onboarding: {
importContactsCreditsReward: 2,
inviteTeamCreditsRewardPerUser: 3,
createProfileCreditsReward: 0.5,
upgradeCreditsReward: 0.5,
inviteTeamMaxInvites: 10,
},
isAttachmentPreviewEnabled: true,
analyticsEnabled: false,
canManageFeatureFlags: true,
publicFeatureFlags: [],
isCookieSessionEnabled: true,
isMicrosoftMessagingEnabled: false,
isMicrosoftCalendarEnabled: false,
isGoogleMessagingEnabled: false,
isGoogleCalendarEnabled: false,
isConfigVariablesInDbEnabled: false,
isImapSmtpCaldavEnabled: false,
isEmailingDomainInDemoMode: false,
calendarBookingPageId: undefined,
isBookCallOnboardingStepEnabled: false,
isCompanyEnrichmentEnabled: false,
isTwoFactorAuthenticationEnabled: false,
allowRequestsToTwentyIcons: true,
isCloudflareIntegrationEnabled: false,
isClickHouseConfigured: false,
isWorkspaceSchemaDDLLocked: false,
isOnboardingAiChatEnabled: false,
enterpriseInstanceType: ENTERPRISE_INSTANCE_TYPE.PRODUCTION,
};
jest
.spyOn(clientConfigService, 'getClientConfig')
.mockResolvedValue(mockClientConfig);
const result = await controller.getClientConfig();
expect(result).toEqual(mockClientConfig);
expect(clientConfigService.getClientConfig).toHaveBeenCalled();
});
});
});