Skip to content

Commit c15c10e

Browse files
committed
#1524 Changed the delete request to an update request and added tests
1 parent 60f543a commit c15c10e

3 files changed

Lines changed: 17 additions & 5 deletions

File tree

src/backend/src/services/projects.services.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -859,13 +859,17 @@ export default class ProjectsService {
859859
});
860860

861861
if (!materialType) throw new NotFoundException('Material Type', materialTypeId);
862+
if (materialType.dateDeleted) throw new DeletedException('Material Type', materialTypeId);
862863

863-
await prisma.material_Type.delete({
864+
const deletedMaterialType = await prisma.material_Type.update({
864865
where: {
865866
name: materialTypeId
867+
},
868+
data: {
869+
dateDeleted: new Date()
866870
}
867871
});
868872

869-
return materialType;
873+
return deletedMaterialType;
870874
}
871875
}

src/backend/tests/projects.test.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -697,12 +697,19 @@ describe('Projects', () => {
697697
);
698698
});
699699

700+
test('Deleted Material Tye does not work if the material type is already deleted', async () => {
701+
vi.spyOn(prisma.material_Type, 'findUnique').mockResolvedValue({ ...toolMaterial, dateDeleted: new Date() });
702+
await expect(ProjectsService.deleteMaterialType('NERSoftwareTools', batman)).rejects.toThrow(
703+
new DeletedException('Material Type', 'NERSoftwareTools')
704+
);
705+
});
706+
700707
test('Delete Material Type works', async () => {
701708
vi.spyOn(prisma.material_Type, 'findUnique').mockResolvedValue(toolMaterial);
702-
vi.spyOn(prisma.material_Type, 'delete').mockResolvedValue(toolMaterial);
709+
vi.spyOn(prisma.material_Type, 'update').mockResolvedValue({ ...toolMaterial, dateDeleted: new Date() });
703710
const deletedMaterialType = await ProjectsService.deleteMaterialType('NERSoftwareTools', superman);
704711
expect(deletedMaterialType.name).toBe('NERSoftwareTools');
705-
expect(prisma.material_Type.delete).toBeCalledTimes(1);
712+
expect(prisma.material_Type.update).toBeCalledTimes(1);
706713
});
707714
});
708715
});

src/backend/tests/test-data/projects.test-data.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,5 +164,6 @@ export const prismaManufacturer2: Manufacturer = {
164164
export const toolMaterial: PrismaMaterialType = {
165165
name: 'NERSoftwareTools',
166166
dateCreated: new Date(),
167-
creatorId: batman.userId
167+
creatorId: batman.userId,
168+
dateDeleted: null
168169
};

0 commit comments

Comments
 (0)