|
1 | 1 | import { alfred, robinMember, cyborgMember, theVisitorGuest } from '../test-data/users.test-data'; |
2 | 2 | import ReimbursementRequestService from '../../src/services/reimbursement-requests.services'; |
3 | | -import { AccessDeniedException, DeletedException, HttpException, NotFoundException } from '../../src/utils/errors.utils'; |
| 3 | +import { |
| 4 | + AccessDeniedException, |
| 5 | + DeletedException, |
| 6 | + HttpException, |
| 7 | + InvalidOrganizationException, |
| 8 | + NotFoundException |
| 9 | +} from '../../src/utils/errors.utils'; |
4 | 10 | import { createTestReimbursementRequest, createTestUser, resetUsers } from '../test-utils'; |
5 | 11 | import prisma from '../../src/prisma/prisma'; |
6 | 12 | import { addDaysToDate, IndexCode, ReimbursementRequest, ReimbursementStatusType, AccountCode } from 'shared'; |
@@ -1041,4 +1047,82 @@ describe('Reimbursement Requests', () => { |
1041 | 1047 | expect(assignedRRs).toEqual([]); |
1042 | 1048 | }); |
1043 | 1049 | }); |
| 1050 | + |
| 1051 | + describe('Set vendor tax exempt status', () => { |
| 1052 | + test('Finance member can set vendor tax exempt status', async () => { |
| 1053 | + const updatedVendor = await ReimbursementRequestService.setVendorTaxExemptStatus( |
| 1054 | + createdVendor.vendorId, |
| 1055 | + true, |
| 1056 | + financeMember, |
| 1057 | + org |
| 1058 | + ); |
| 1059 | + |
| 1060 | + expect(updatedVendor).not.toBeNull(); |
| 1061 | + expect(updatedVendor.taxExempt).toBe(true); |
| 1062 | + }); |
| 1063 | + |
| 1064 | + test('Non-finance member cannot set vendor tax exempt status', async () => { |
| 1065 | + await expect( |
| 1066 | + ReimbursementRequestService.setVendorTaxExemptStatus(createdVendor.vendorId, true, regularMember, org) |
| 1067 | + ).rejects.toThrow(new AccessDeniedException('You are not a member of the finance team!')); |
| 1068 | + }); |
| 1069 | + |
| 1070 | + test('Cannot set tax exempt status for non-existent vendor', async () => { |
| 1071 | + await expect( |
| 1072 | + ReimbursementRequestService.setVendorTaxExemptStatus('non-existent-id', true, financeMember, org) |
| 1073 | + ).rejects.toThrow(new NotFoundException('Vendor', 'non-existent-id')); |
| 1074 | + }); |
| 1075 | + |
| 1076 | + test('Cannot set tax exempt status for vendor in different organization', async () => { |
| 1077 | + // Create a vendor in a different organization |
| 1078 | + const otherOrg = await prisma.organization.create({ |
| 1079 | + data: { |
| 1080 | + name: 'Other Org', |
| 1081 | + userCreated: { connect: { userId: financeHead.userId } } |
| 1082 | + } |
| 1083 | + }); |
| 1084 | + |
| 1085 | + const otherMember: User = await prisma.user.create({ |
| 1086 | + data: { |
| 1087 | + firstName: 'Other', |
| 1088 | + lastName: 'Member', |
| 1089 | + googleAuthId: '99', |
| 1090 | + email: 'email@email.other', |
| 1091 | + roles: { |
| 1092 | + create: { |
| 1093 | + roleType: Role_Type.MEMBER, |
| 1094 | + organization: { |
| 1095 | + connect: { organizationId: otherOrg.organizationId } |
| 1096 | + } |
| 1097 | + } |
| 1098 | + } |
| 1099 | + } |
| 1100 | + }); |
| 1101 | + |
| 1102 | + const otherVendor = await ReimbursementRequestService.createVendor( |
| 1103 | + otherMember, |
| 1104 | + 'Other Org Vendor', |
| 1105 | + otherOrg, |
| 1106 | + false, |
| 1107 | + [], |
| 1108 | + 'Some notes' |
| 1109 | + ); |
| 1110 | + |
| 1111 | + await expect( |
| 1112 | + ReimbursementRequestService.setVendorTaxExemptStatus(otherVendor.vendorId, true, financeMember, org) |
| 1113 | + ).rejects.toThrow(new InvalidOrganizationException('Vendor')); |
| 1114 | + }); |
| 1115 | + |
| 1116 | + test('head can set vendor tax exempt status', async () => { |
| 1117 | + const updatedVendor = await ReimbursementRequestService.setVendorTaxExemptStatus( |
| 1118 | + createdVendor.vendorId, |
| 1119 | + true, |
| 1120 | + financeHead, |
| 1121 | + org |
| 1122 | + ); |
| 1123 | + |
| 1124 | + expect(updatedVendor).not.toBeNull(); |
| 1125 | + expect(updatedVendor.taxExempt).toBe(true); |
| 1126 | + }); |
| 1127 | + }); |
1044 | 1128 | }); |
0 commit comments