Skip to content

The open alternative to Salesforce, designed for AI.

Fix test (#15895)

Etiennedb48059beaa2
diff --git a/packages/twenty-server/src/modules/contact-creation-manager/services/__tests__/create-company.service.spec.ts b/packages/twenty-server/src/modules/contact-creation-manager/services/__tests__/create-company.service.spec.ts
index 62492cb3371..fdcab7f1067 100644
--- a/packages/twenty-server/src/modules/contact-creation-manager/services/__tests__/create-company.service.spec.ts
+++ b/packages/twenty-server/src/modules/contact-creation-manager/services/__tests__/create-company.service.spec.ts
@@ -1,6 +1,7 @@
import { Test, type TestingModule } from '@nestjs/testing';
import { getRepositoryToken } from '@nestjs/typeorm';
+import axios from 'axios';
import {
ConnectedAccountProvider,
FieldActorSource,
@@ -14,9 +15,12 @@ import {
CreateCompanyService,
} from 'src/modules/contact-creation-manager/services/create-company.service';
+jest.mock('axios');
+
describe('CreateCompanyService', () => {
let service: CreateCompanyService;
let mockCompanyRepository: any;
+ let mockHttpService: any;
const workspaceId = 'workspace-1';
@@ -101,6 +105,12 @@ describe('CreateCompanyService', () => {
updateMany: jest.fn(),
};
+ mockHttpService = {
+ get: jest.fn(),
+ };
+
+ (axios.create as jest.Mock).mockReturnValue(mockHttpService);
+
const module: TestingModule = await Test.createTestingModule({
providers: [
CreateCompanyService,
@@ -152,6 +162,13 @@ describe('CreateCompanyService', () => {
});
it('should successfully create a company', async () => {
+ mockHttpService.get.mockResolvedValue({
+ data: {
+ name: 'Example1',
+ city: undefined,
+ },
+ });
+
await service.createOrRestoreCompanies([companyToCreate1], workspaceId);
expect(mockCompanyRepository.find).toHaveBeenCalled();
@@ -161,6 +178,20 @@ describe('CreateCompanyService', () => {
});
it('should successfully two companies', async () => {
+ mockHttpService.get
+ .mockResolvedValueOnce({
+ data: {
+ name: 'Example1',
+ city: undefined,
+ },
+ })
+ .mockResolvedValueOnce({
+ data: {
+ name: 'BNQ',
+ city: '',
+ },
+ });
+
await service.createOrRestoreCompanies(
[companyToCreate1, companyToCreate2],
workspaceId,