fix: minor fix

This commit is contained in:
hexastack 2024-11-21 09:55:26 +01:00
parent f93d6c20ae
commit 812202d9e1
2 changed files with 15 additions and 8 deletions

View File

@ -9,7 +9,7 @@
import { EventEmitter2 } from '@nestjs/event-emitter'; import { EventEmitter2 } from '@nestjs/event-emitter';
import { MongooseModule, getModelToken } from '@nestjs/mongoose'; import { MongooseModule, getModelToken } from '@nestjs/mongoose';
import { Test } from '@nestjs/testing'; import { Test } from '@nestjs/testing';
import { Model, Types } from 'mongoose'; import { Model } from 'mongoose';
import { import {
blockFixtures, blockFixtures,
@ -144,11 +144,18 @@ describe('BlockRepository', () => {
}); });
it('should do nothing if no block is found for the criteria', async () => { 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'); 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(); expect(mockUpdateMany).not.toHaveBeenCalled();
}); });
}); });
@ -232,7 +239,7 @@ describe('BlockRepository', () => {
]); ]);
expect(mockUpdateOne).toHaveBeenCalledWith('64abc1234def567890fedcab', { expect(mockUpdateOne).toHaveBeenCalledWith('64abc1234def567890fedcab', {
nextBlocks: [new Types.ObjectId(validIds[1])], nextBlocks: [validIds[1]],
}); });
}); });
}); });

View File

@ -113,8 +113,8 @@ export class BlockRepository extends BaseRepository<
{ attachedBlock: movedBlock.id }, { attachedBlock: movedBlock.id },
{ $set: { attachedBlock: null } }, { $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 }); await this.updateOne(block.id, { attachedBlock: null });
} }
const nextBlocks = block.nextBlocks const nextBlocks = block.nextBlocks.filter(
.filter((nextBlock) => !ids.includes(nextBlock)) (nextBlock) => !ids.includes(nextBlock),
.map((id) => new Types.ObjectId(id)); );
if (nextBlocks.length > 0) { if (nextBlocks.length > 0) {
await this.updateOne(block.id, { nextBlocks }); await this.updateOne(block.id, { nextBlocks });