@@ -5,6 +5,8 @@ import { aquaman, batman, wonderwoman, superman, theVisitor } from './test-data/
55import {
66 prismaProject1 ,
77 sharedProject1 ,
8+ prismaLinkType1 ,
9+ prismaLinkType2 ,
810 prismaAssembly1 ,
911 toolMaterial ,
1012 prismaManufacturer1 ,
@@ -301,6 +303,35 @@ describe('Projects', () => {
301303 } ) ;
302304 } ) ;
303305
306+ describe ( 'Create LinkType' , ( ) => {
307+ test ( 'Create LinkType Type fails for non heads or admins' , async ( ) => {
308+ await expect (
309+ ProjectsService . createLinkType ( wonderwoman , prismaLinkType1 . name , prismaLinkType1 . iconName , prismaLinkType1 . required )
310+ ) . rejects . toThrow ( new AccessDeniedException ( 'Only admins can create link types' ) ) ;
311+ } ) ;
312+
313+ test ( 'Create LinkType Type fails if LinkType with name already exists' , async ( ) => {
314+ vi . spyOn ( prisma . linkType , 'findUnique' ) . mockResolvedValue ( { ...prismaLinkType2 , creatorId : batman . userId } ) ;
315+ await expect (
316+ ProjectsService . createLinkType ( batman , prismaLinkType1 . name , prismaLinkType1 . iconName , prismaLinkType1 . required )
317+ ) . rejects . toThrow ( new HttpException ( 400 , 'LinkType with that name already exists' ) ) ;
318+ } ) ;
319+
320+ test ( 'Create LinkType successfully returns new LinkType' , async ( ) => {
321+ vi . spyOn ( prisma . linkType , 'findUnique' ) . mockResolvedValue ( null ) ;
322+ vi . spyOn ( prisma . linkType , 'create' ) . mockResolvedValue ( { ...prismaLinkType2 , creatorId : batman . userId } ) ;
323+
324+ const linkType = await ProjectsService . createLinkType (
325+ batman ,
326+ prismaLinkType2 . name ,
327+ prismaLinkType2 . iconName ,
328+ prismaLinkType2 . required
329+ ) ;
330+
331+ expect ( linkType ) . toStrictEqual ( prismaLinkType2 ) ;
332+ } ) ;
333+ } ) ;
334+
304335 describe ( 'createAssembly' , ( ) => {
305336 test ( 'createAssembly fails given invalid project wbs number' , async ( ) => {
306337 await expect (
0 commit comments