Skip to content

Commit

Permalink
[#140] feat: block 서비스 내 deleteOnly 함수 및 테스트 코드 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
skid901 committed Dec 19, 2020
1 parent 5e13658 commit b1f8251
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
4 changes: 4 additions & 0 deletions backend/src/services/block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,7 @@ export const deleteCascade = async (blockId: string): Promise<BlockDoc> => {
await parent.deleteChild(blockId);
return parent;
};

export const deleteOnly = async (blockId: string): Promise<BlockDoc> => {
return null;
};
40 changes: 40 additions & 0 deletions backend/test/services/block.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,4 +184,44 @@ describe('@services/block', () => {
blockService.deleteCascade(received.id),
).rejects.toThrow();
});

it('deleteOnly: Success', async () => {
const { block } = await blockService.create({
parentId: page.rootId.toHexString(),
});
const { block: sibling } = await blockService.create({
parentId: page.rootId.toHexString(),
});
let { block: child } = await blockService.create({
parentId: block.id,
});
let { block: anotherChild } = await blockService.create({
parentId: block.id,
});

const receivedParentId = block.parentId.toHexString();
const parent = await blockService.deleteOnly(block.id);
child = await Block.readOne(child.id);
anotherChild = await Block.readOne(anotherChild.id);
const receivedChildIdList = parent.childIdList.map((childId) =>
childId.toHexString(),
);

expect(parent.id).toEqual(receivedParentId);
expect(child.parentId).toEqual(receivedParentId);
expect(anotherChild.parentId).toEqual(receivedParentId);
expect(receivedChildIdList).toEqual([
child.id,
anotherChild.id,
sibling.id,
]);
});

it('deleteOnly: Not found', async () => {
const received: BlockDTO = { id: 'invalid id' };

await expect(async () =>
blockService.deleteOnly(received.id),
).rejects.toThrow();
});
});

0 comments on commit b1f8251

Please sign in to comment.