I'm doing test for my searchService and I realize that the bulk method used to insert data to elasticSearch db has some intern operation.
beforeEach(async () => {
const moduleRef: TestingModule = await Test.createTestingModule({
providers: [
SearchService,
{
provide: ElasticsearchService,
useValue: {
bulk: jest.fn(),
count: jest.fn(),
helpers: {
scrollSearch: jest.fn(),
},
search: jest.fn(),
},
},
{
provide: PrismaService,
useValue: {
skus: {
findMany: jest.fn().mockResolvedValueOnce(findManyMock),
findUnique: jest.fn().mockResolvedValue({}),
update: jest.fn().mockResolvedValue({}),
create: jest.fn().mockResolvedValue({}),
delete: jest.fn().mockResolvedValue({}),
},
},
},
],
}).compile();
the bulk method called:
for await (const chunk of arrayOfBulkBodiesInChunks) {
const bulkBody = chunk.flatMap((doc) => [
{ index: { _index: this.index } },
doc,
]);
await this.elasticsearchService.bulk({
refresh: true,
body: bulkBody,
});
}
I'm asking help to write a mock for bulk operations.