mirror of
https://github.com/hexastack/hexabot
synced 2025-05-05 13:24:37 +00:00
fix(api): update unit tests
This commit is contained in:
parent
69a994f9e3
commit
126a406d16
@ -54,6 +54,7 @@ describe('BlockRepository', () => {
|
||||
validCategory = '64def5678abc123490fedcba';
|
||||
|
||||
category = (await categoryRepository.findOne({ label: 'default' }))!;
|
||||
|
||||
hasPreviousBlocks = (await blockRepository.findOne({
|
||||
name: 'hasPreviousBlocks',
|
||||
}))!;
|
||||
@ -171,42 +172,38 @@ describe('BlockRepository', () => {
|
||||
|
||||
describe('prepareBlocksInCategoryUpdateScope', () => {
|
||||
it('should update blocks within the scope based on category and ids', async () => {
|
||||
jest.spyOn(blockRepository, 'findOne').mockResolvedValue({
|
||||
jest.spyOn(blockRepository, 'find').mockResolvedValue([
|
||||
{
|
||||
id: blockValidIds[0],
|
||||
category: 'oldCategory',
|
||||
category: category.id,
|
||||
nextBlocks: [blockValidIds[1]],
|
||||
attachedBlock: blockValidIds[1],
|
||||
} as Block);
|
||||
|
||||
const mockUpdateOne = jest.spyOn(blockRepository, 'updateOne');
|
||||
attachedBlock: blockValidIds[2],
|
||||
},
|
||||
] as Block[]);
|
||||
jest.spyOn(blockRepository, 'updateOne');
|
||||
|
||||
await blockRepository.prepareBlocksInCategoryUpdateScope(
|
||||
validCategory,
|
||||
blockValidIds,
|
||||
);
|
||||
|
||||
expect(mockUpdateOne).toHaveBeenCalledWith(blockValidIds[0], {
|
||||
expect(blockRepository.updateOne).toHaveBeenCalledWith(blockValidIds[0], {
|
||||
nextBlocks: [blockValidIds[1]],
|
||||
attachedBlock: blockValidIds[1],
|
||||
attachedBlock: blockValidIds[2],
|
||||
});
|
||||
});
|
||||
|
||||
it('should not update blocks if the category already matches', async () => {
|
||||
jest.spyOn(blockRepository, 'findOne').mockResolvedValue({
|
||||
id: validIds[0],
|
||||
category: validCategory,
|
||||
nextBlocks: [],
|
||||
attachedBlock: null,
|
||||
} as unknown as Block);
|
||||
|
||||
const mockUpdateOne = jest.spyOn(blockRepository, 'updateOne');
|
||||
jest.spyOn(blockRepository, 'find').mockResolvedValue([]);
|
||||
jest.spyOn(blockRepository, 'updateOne');
|
||||
|
||||
await blockRepository.prepareBlocksInCategoryUpdateScope(
|
||||
validCategory,
|
||||
validIds,
|
||||
category.id,
|
||||
blockValidIds,
|
||||
);
|
||||
|
||||
expect(mockUpdateOne).not.toHaveBeenCalled();
|
||||
expect(blockRepository.find).toHaveBeenCalled();
|
||||
expect(blockRepository.updateOne).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user