|
1 | 1 | import prisma from '../src/prisma/prisma'; |
2 | 2 | import { getHighestProjectNumber } from '../src/utils/projects.utils'; |
3 | 3 | import * as changeRequestUtils from '../src/utils/change-requests.utils'; |
4 | | -import { aquaman, batman, superman, theVisitor, wonderwoman } from './test-data/users.test-data'; |
| 4 | +import { aquaman, batman, wonderwoman, superman, theVisitor } from './test-data/users.test-data'; |
5 | 5 | import { |
6 | 6 | prismaProject1, |
7 | 7 | sharedProject1, |
@@ -685,6 +685,35 @@ describe('Projects', () => { |
685 | 685 | }); |
686 | 686 | }); |
687 | 687 |
|
| 688 | + describe('Deleting material type', () => { |
| 689 | + test('Delete Material Type does not work if user is not an admin or head', async () => { |
| 690 | + await expect(ProjectsService.deleteMaterialType('NERSoftwareTools', theVisitor)).rejects.toThrow( |
| 691 | + new AccessDeniedException('Only an admin or head can delete a material type') |
| 692 | + ); |
| 693 | + }); |
| 694 | + |
| 695 | + test('Delete Material Type does not work if material type does not exist', async () => { |
| 696 | + await expect(ProjectsService.deleteMaterialType('NERSoftwareTools', batman)).rejects.toThrow( |
| 697 | + new NotFoundException('Material Type', 'NERSoftwareTools') |
| 698 | + ); |
| 699 | + }); |
| 700 | + |
| 701 | + test('Deleted Material Tye does not work if the material type is already deleted', async () => { |
| 702 | + vi.spyOn(prisma.material_Type, 'findUnique').mockResolvedValue({ ...toolMaterial, dateDeleted: new Date() }); |
| 703 | + await expect(ProjectsService.deleteMaterialType('NERSoftwareTools', batman)).rejects.toThrow( |
| 704 | + new DeletedException('Material Type', 'NERSoftwareTools') |
| 705 | + ); |
| 706 | + }); |
| 707 | + |
| 708 | + test('Delete Material Type works', async () => { |
| 709 | + vi.spyOn(prisma.material_Type, 'findUnique').mockResolvedValue(toolMaterial); |
| 710 | + vi.spyOn(prisma.material_Type, 'update').mockResolvedValue({ ...toolMaterial, dateDeleted: new Date() }); |
| 711 | + const deletedMaterialType = await ProjectsService.deleteMaterialType('NERSoftwareTools', superman); |
| 712 | + expect(deletedMaterialType.name).toBe('NERSoftwareTools'); |
| 713 | + expect(prisma.material_Type.update).toBeCalledTimes(1); |
| 714 | + }); |
| 715 | + }); |
| 716 | + |
688 | 717 | describe('updateMaterial', () => { |
689 | 718 | test('Update material fails if the given material does not exists', async () => { |
690 | 719 | vi.spyOn(prisma.material, 'findUnique').mockResolvedValue(null); |
|
0 commit comments