【发布时间】:2022-01-17 19:42:36
【问题描述】:
我正在为我的 searchService 做测试,我意识到用于向 elasticSearch db 插入数据的批量方法有一些实习操作。
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();
调用的批量方法:
for await (const chunk of arrayOfBulkBodiesInChunks) {
const bulkBody = chunk.flatMap((doc) => [
{ index: { _index: this.index } },
doc,
]);
await this.elasticsearchService.bulk({
refresh: true,
body: bulkBody,
});
}
我正在寻求帮助,为批量操作编写一个模拟。
【问题讨论】:
标签: elasticsearch jestjs nestjs prisma elasticsearch-jest