@@ -3,7 +3,7 @@ import ProspectiveSponsorServices from '../../src/services/prospective-sponsor.s
33import FinanceServices from '../../src/services/finance.services.js' ;
44import { AccessDeniedException , DeletedException , HttpException , NotFoundException } from '../../src/utils/errors.utils.js' ;
55import { batmanAppAdmin , wonderwomanGuest , supermanAdmin } from '../test-data/users.test-data.js' ;
6- import { createTestOrganization , createTestUser , resetUsers } from '../test-utils.js' ;
6+ import { createFinanceTeamAndLead , createTestOrganization , createTestUser , resetUsers } from '../test-utils.js' ;
77import prisma from '../../src/prisma/prisma.js' ;
88import { FirstContactMethod , ProspectiveSponsorStatus } from 'shared' ;
99
@@ -627,7 +627,7 @@ describe('Prospective Sponsor Tests', () => {
627627 } ) ;
628628
629629 describe ( 'Delete Prospective Sponsor' , ( ) => {
630- it ( 'Fails if user is not a head' , async ( ) => {
630+ it ( 'Fails if user is not a finance lead or head' , async ( ) => {
631631 const head = await createTestUser ( batmanAppAdmin , orgId ) ;
632632 const guest = await createTestUser ( wonderwomanGuest , orgId ) ;
633633
@@ -646,7 +646,49 @@ describe('Prospective Sponsor Tests', () => {
646646
647647 await expect (
648648 ProspectiveSponsorServices . deleteProspectiveSponsor ( ps . prospectiveSponsorId , guest , organization )
649- ) . rejects . toThrow ( new AccessDeniedException ( 'Only heads can delete prospective sponsors' ) ) ;
649+ ) . rejects . toThrow ( new AccessDeniedException ( 'Only finance leads or heads can delete prospective sponsors' ) ) ;
650+ } ) ;
651+
652+ it ( 'Fails if user is a finance team member (not lead)' , async ( ) => {
653+ await createFinanceTeamAndLead ( organization ) ;
654+ const financeHead = await prisma . user . findUniqueOrThrow ( { where : { googleAuthId : 'financeHead' } } ) ;
655+ const financeMember = await prisma . user . findUniqueOrThrow ( { where : { googleAuthId : 'financeMember' } } ) ;
656+
657+ const ps = await ProspectiveSponsorServices . createProspectiveSponsor (
658+ financeHead ,
659+ organization ,
660+ 'Acme Corp' ,
661+ ProspectiveSponsorStatus . NOT_IN_CONTACT
662+ ) ;
663+
664+ await expect (
665+ ProspectiveSponsorServices . deleteProspectiveSponsor ( ps . prospectiveSponsorId , financeMember , organization )
666+ ) . rejects . toThrow ( new AccessDeniedException ( 'Only finance leads or heads can delete prospective sponsors' ) ) ;
667+ } ) ;
668+
669+ it ( 'Succeeds if user is a finance team lead' , async ( ) => {
670+ await createFinanceTeamAndLead ( organization ) ;
671+ const financeHead = await prisma . user . findUniqueOrThrow ( { where : { googleAuthId : 'financeHead' } } ) ;
672+ const financeLead = await prisma . user . findUniqueOrThrow ( { where : { googleAuthId : 'financeLead' } } ) ;
673+
674+ const ps = await ProspectiveSponsorServices . createProspectiveSponsor (
675+ financeHead ,
676+ organization ,
677+ 'Acme Corp' ,
678+ ProspectiveSponsorStatus . NOT_IN_CONTACT
679+ ) ;
680+
681+ const result = await ProspectiveSponsorServices . deleteProspectiveSponsor (
682+ ps . prospectiveSponsorId ,
683+ financeLead ,
684+ organization
685+ ) ;
686+
687+ expect ( result . prospectiveSponsorId ) . toBe ( ps . prospectiveSponsorId ) ;
688+ const deletedPs = await prisma . prospective_Sponsor . findUnique ( {
689+ where : { prospectiveSponsorId : ps . prospectiveSponsorId }
690+ } ) ;
691+ expect ( deletedPs ?. dateDeleted ) . not . toBeNull ( ) ;
650692 } ) ;
651693
652694 it ( 'Fails if prospective sponsor does not exist' , async ( ) => {
@@ -891,7 +933,7 @@ describe('Prospective Sponsor Tests', () => {
891933 } ) ;
892934
893935 describe ( 'Accept Prospective Sponsor' , ( ) => {
894- it ( 'Fails if user is not a head or contactor' , async ( ) => {
936+ it ( 'Fails if user is not a finance lead, head, or contactor' , async ( ) => {
895937 const head = await createTestUser ( batmanAppAdmin , orgId ) ;
896938 const guest = await createTestUser ( wonderwomanGuest , orgId ) ;
897939
@@ -920,7 +962,69 @@ describe('Prospective Sponsor Tests', () => {
920962 false ,
921963 5000
922964 )
923- ) . rejects . toThrow ( new AccessDeniedException ( 'Only heads or the assigned contactor can accept prospective sponsors' ) ) ;
965+ ) . rejects . toThrow (
966+ new AccessDeniedException ( 'Only finance leads, heads, or the assigned contactor can accept prospective sponsors' )
967+ ) ;
968+ } ) ;
969+
970+ it ( 'Fails if user is a finance team member (not lead or contactor)' , async ( ) => {
971+ await createFinanceTeamAndLead ( organization ) ;
972+ const financeHead = await prisma . user . findUniqueOrThrow ( { where : { googleAuthId : 'financeHead' } } ) ;
973+ const financeMember = await prisma . user . findUniqueOrThrow ( { where : { googleAuthId : 'financeMember' } } ) ;
974+
975+ const ps = await ProspectiveSponsorServices . createProspectiveSponsor (
976+ financeHead ,
977+ organization ,
978+ 'Acme Corp' ,
979+ ProspectiveSponsorStatus . NOT_IN_CONTACT
980+ ) ;
981+
982+ await expect (
983+ ProspectiveSponsorServices . acceptProspectiveSponsor (
984+ financeMember ,
985+ organization ,
986+ ps . prospectiveSponsorId ,
987+ undefined ,
988+ [ 'MONETARY' ] ,
989+ new Date ( ) ,
990+ [ 2024 ] ,
991+ false
992+ )
993+ ) . rejects . toThrow (
994+ new AccessDeniedException ( 'Only finance leads, heads, or the assigned contactor can accept prospective sponsors' )
995+ ) ;
996+ } ) ;
997+
998+ it ( 'Succeeds if user is a finance team lead' , async ( ) => {
999+ await createFinanceTeamAndLead ( organization ) ;
1000+ const financeHead = await prisma . user . findUniqueOrThrow ( { where : { googleAuthId : 'financeHead' } } ) ;
1001+ const financeLead = await prisma . user . findUniqueOrThrow ( { where : { googleAuthId : 'financeLead' } } ) ;
1002+ const joinDate = new Date ( 2024 , 6 , 1 ) ;
1003+
1004+ const ps = await ProspectiveSponsorServices . createProspectiveSponsor (
1005+ financeHead ,
1006+ organization ,
1007+ 'Finance Lead Accept Corp' ,
1008+ ProspectiveSponsorStatus . NOT_IN_CONTACT
1009+ ) ;
1010+
1011+ const result = await ProspectiveSponsorServices . acceptProspectiveSponsor (
1012+ financeLead ,
1013+ organization ,
1014+ ps . prospectiveSponsorId ,
1015+ undefined ,
1016+ [ 'MONETARY' ] ,
1017+ joinDate ,
1018+ [ 2024 ] ,
1019+ false ,
1020+ 2500
1021+ ) ;
1022+
1023+ expect ( result . status ) . toBe ( ProspectiveSponsorStatus . ACCEPTED ) ;
1024+ const sponsors = await FinanceServices . getAllSponsors ( organization ) ;
1025+ const createdSponsor = sponsors . find ( ( s ) => s . name === 'Finance Lead Accept Corp' ) ;
1026+ expect ( createdSponsor ) . toBeDefined ( ) ;
1027+ expect ( createdSponsor ! . sponsorValue ) . toBe ( 2500 ) ;
9241028 } ) ;
9251029
9261030 it ( 'Succeeds when the contactor accepts' , async ( ) => {
0 commit comments