diff --git a/api/src/chat/repositories/block.repository.spec.ts b/api/src/chat/repositories/block.repository.spec.ts index 534c6c7..0904e8a 100644 --- a/api/src/chat/repositories/block.repository.spec.ts +++ b/api/src/chat/repositories/block.repository.spec.ts @@ -9,7 +9,7 @@ import { EventEmitter2 } from '@nestjs/event-emitter'; import { MongooseModule, getModelToken } from '@nestjs/mongoose'; import { Test } from '@nestjs/testing'; -import { Model, Types } from 'mongoose'; +import { Model } from 'mongoose'; import { blockFixtures, @@ -144,11 +144,18 @@ describe('BlockRepository', () => { }); it('should do nothing if no block is found for the criteria', async () => { - jest.spyOn(blockRepository, 'findOne').mockResolvedValue(null); + const mockFindOne = jest + .spyOn(blockRepository, 'findOne') + .mockResolvedValue(null); const mockUpdateMany = jest.spyOn(blockRepository, 'updateMany'); - await blockRepository.preUpdate({} as any, { _id: 'nonexistent' }, {}); + await blockRepository.preUpdate( + {} as any, + { _id: 'nonexistent' }, + { $set: { category: 'newCategory' } }, + ); + expect(mockFindOne).toHaveBeenCalledWith({ _id: 'nonexistent' }); expect(mockUpdateMany).not.toHaveBeenCalled(); }); }); @@ -232,7 +239,7 @@ describe('BlockRepository', () => { ]); expect(mockUpdateOne).toHaveBeenCalledWith('64abc1234def567890fedcab', { - nextBlocks: [new Types.ObjectId(validIds[1])], + nextBlocks: [validIds[1]], }); }); }); diff --git a/api/src/chat/repositories/block.repository.ts b/api/src/chat/repositories/block.repository.ts index f3efda6..1198794 100644 --- a/api/src/chat/repositories/block.repository.ts +++ b/api/src/chat/repositories/block.repository.ts @@ -113,8 +113,8 @@ export class BlockRepository extends BaseRepository< { attachedBlock: movedBlock.id }, { $set: { attachedBlock: null } }, ); - this.checkDeprecatedAttachmentUrl(update); } + this.checkDeprecatedAttachmentUrl(update); } /** @@ -213,9 +213,9 @@ export class BlockRepository extends BaseRepository< await this.updateOne(block.id, { attachedBlock: null }); } - const nextBlocks = block.nextBlocks - .filter((nextBlock) => !ids.includes(nextBlock)) - .map((id) => new Types.ObjectId(id)); + const nextBlocks = block.nextBlocks.filter( + (nextBlock) => !ids.includes(nextBlock), + ); if (nextBlocks.length > 0) { await this.updateOne(block.id, { nextBlocks });