Skip to content

Commit 719babc

Browse files
committed
#1528 Ensure material and assembly have same wbs element
1 parent 99e47fd commit 719babc

3 files changed

Lines changed: 16 additions & 1 deletion

File tree

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -838,6 +838,13 @@ export default class ProjectsService {
838838
});
839839
if (!project) throw new NotFoundException('Project', assembly.wbsElementId);
840840

841+
// Confirm that the assembly's wbsElement is the same as the material's wbsElement
842+
if (material.wbsElementId !== assembly.wbsElementId)
843+
throw new HttpException(
844+
400,
845+
`The WBS element of the material (${material.wbsElementId}) and assembly (${assembly.wbsElementId}) do not match`
846+
);
847+
841848
// Permission: leadership and up, anyone on project team
842849
if (!(isLeadership(submitter.role) || isUserPartOfTeams(project.teams, submitter)))
843850
throw new AccessDeniedException('Only leadership or above can create a material type');

src/backend/tests/projects.test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -695,6 +695,14 @@ describe('Projects', () => {
695695
);
696696
});
697697

698+
test('assignment fails because the wbsElements do not match', async () => {
699+
vi.spyOn(prisma.material, 'findUnique').mockResolvedValue({ ...prismaMaterial1, wbsElementId: 1 });
700+
vi.spyOn(prisma.assembly, 'findUnique').mockResolvedValue({ ...prismaAssembly1, wbsElementId: 2 });
701+
await expect(ProjectsService.assignMaterialAssembly(superman, 'mid', 'aid')).rejects.toThrow(
702+
new HttpException('400', `The WBS element of the material (1) and assembly (2) do not match`)
703+
);
704+
});
705+
698706
test('assignment successful', async () => {
699707
vi.spyOn(prisma.material, 'findUnique').mockResolvedValue(prismaMaterial1);
700708
vi.spyOn(prisma.assembly, 'findUnique').mockResolvedValue(prismaAssembly1);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ export const prismaAssembly1: Assembly = {
112112
pdmFileName: 'file.txt',
113113
dateCreated: new Date('10-19-2023'),
114114
userCreatedId: batman.userId,
115-
wbsElementId: 66,
115+
wbsElementId: sharedProject1.id,
116116
dateDeleted: null,
117117
userDeletedId: null,
118118
assemblyId: '1'

0 commit comments

Comments
 (0)