Fix test (#15895)
This commit is contained in:
+31
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user