Skip to content

Commit da17421

Browse files
committed
#3494 fixes in both places + tests
1 parent 4ac11d0 commit da17421

2 files changed

Lines changed: 293 additions & 2 deletions

File tree

src/backend/src/services/change-requests.services.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1174,7 +1174,7 @@ export default class ChangeRequestsService {
11741174
wbsProposedChanges: {
11751175
create: {
11761176
name: workPackage.originalElement.name,
1177-
status: WBS_Element_Status.INACTIVE,
1177+
status: wbsElement.status,
11781178
proposedDescriptionBulletChanges: {
11791179
create: workPackage.descriptionBullets.map((bullet) => ({
11801180
detail: bullet.detail,
@@ -1237,7 +1237,7 @@ export default class ChangeRequestsService {
12371237
data: {
12381238
scopeChangeRequest: { connect: { scopeCrId: createdCR.scopeChangeRequest!.scopeCrId } },
12391239
name,
1240-
status: WBS_Element_Status.ACTIVE,
1240+
status: wbsElement.status,
12411241
proposedDescriptionBulletChanges: {
12421242
create: validationResult.descriptionBullets.map((bullet) => ({
12431243
detail: bullet.detail,
Lines changed: 291 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,291 @@
1+
import { CR_Type, Organization, Scope_CR_Why_Type, User, WBS_Element_Status } from '@prisma/client';
2+
import { createTestOrganization, createTestProject, createTestUser, resetUsers } from '../test-utils';
3+
import ChangeRequestsService from '../../src/services/change-requests.services';
4+
import { supermanAdmin } from '../test-data/users.test-data';
5+
import { ProjectProposedChangesCreateArgs, WorkPackageProposedChangesCreateArgs } from 'shared';
6+
import prisma from '../../src/prisma/prisma';
7+
8+
describe('Change Request Tests', () => {
9+
let orgId: string;
10+
let organization: Organization;
11+
let user: User;
12+
13+
beforeEach(async () => {
14+
organization = await createTestOrganization();
15+
orgId = organization.organizationId;
16+
user = await createTestUser(supermanAdmin, orgId);
17+
});
18+
19+
afterEach(async () => {
20+
await resetUsers();
21+
});
22+
23+
describe('Create Change Request', () => {
24+
it('create change request on an inactive project - project changes', async () => {
25+
await prisma.wBS_Element.update({
26+
where: {
27+
wbsNumber: {
28+
carNumber: 0,
29+
projectNumber: 1,
30+
workPackageNumber: 0,
31+
organizationId: organization.organizationId
32+
}
33+
},
34+
data: {
35+
status: WBS_Element_Status.INACTIVE
36+
}
37+
});
38+
39+
const projPropChanges: ProjectProposedChangesCreateArgs = {
40+
name: 'Project name changes',
41+
descriptionBullets: [],
42+
links: [],
43+
budget: 10,
44+
summary: 'Summary',
45+
teamIds: [],
46+
workPackageProposedChanges: []
47+
};
48+
49+
const cr = await ChangeRequestsService.createStandardChangeRequest(
50+
user,
51+
0,
52+
1,
53+
0,
54+
CR_Type.DEFINITION_CHANGE,
55+
'What',
56+
[
57+
{
58+
type: Scope_CR_Why_Type.COMPETITION,
59+
explain: 'Explaining'
60+
}
61+
],
62+
[],
63+
organization,
64+
projPropChanges,
65+
null
66+
);
67+
68+
expect(cr.submitter.userId).toEqual(user.userId);
69+
expect(cr.wbsNum?.carNumber).toEqual(0);
70+
expect(cr.wbsNum?.projectNumber).toEqual(1);
71+
expect(cr.wbsNum?.workPackageNumber).toEqual(0);
72+
73+
expect(cr.type).toEqual(CR_Type.DEFINITION_CHANGE);
74+
expect(cr.what).toEqual('What');
75+
expect(cr.proposedSolutions).toHaveLength(0);
76+
77+
expect(cr.wbsNum).toBeDefined();
78+
expect(cr.wbsNum).not.toBeNull();
79+
80+
const wbsElement = await prisma.wBS_Element.findUnique({
81+
where: {
82+
wbsNumber: {
83+
carNumber: 0,
84+
projectNumber: 1,
85+
workPackageNumber: 0,
86+
organizationId: organization.organizationId
87+
}
88+
}
89+
});
90+
91+
expect(wbsElement?.status).toEqual(WBS_Element_Status.INACTIVE);
92+
expect(wbsElement?.carNumber).toEqual(0);
93+
expect(wbsElement?.projectNumber).toEqual(1);
94+
expect(wbsElement?.workPackageNumber).toEqual(0);
95+
});
96+
it('create change request does not make active project inactive - project changes', async () => {
97+
await prisma.wBS_Element.update({
98+
where: {
99+
wbsNumber: {
100+
carNumber: 0,
101+
projectNumber: 1,
102+
workPackageNumber: 0,
103+
organizationId: organization.organizationId
104+
}
105+
},
106+
data: {
107+
status: WBS_Element_Status.ACTIVE
108+
}
109+
});
110+
111+
const wpPropChanges: WorkPackageProposedChangesCreateArgs = {
112+
name: 'wp',
113+
descriptionBullets: [],
114+
links: [],
115+
duration: 3,
116+
startDate: '2025-09-13',
117+
blockedBy: [],
118+
leadId: user.userId,
119+
managerId: user.userId
120+
};
121+
122+
await ChangeRequestsService.createStandardChangeRequest(
123+
user,
124+
0,
125+
1,
126+
0,
127+
CR_Type.DEFINITION_CHANGE,
128+
'What',
129+
[
130+
{
131+
type: Scope_CR_Why_Type.COMPETITION,
132+
explain: 'Explaining'
133+
}
134+
],
135+
[],
136+
organization,
137+
null,
138+
wpPropChanges
139+
);
140+
141+
const wbsElement = await prisma.wBS_Element.findUnique({
142+
where: {
143+
wbsNumber: {
144+
carNumber: 0,
145+
projectNumber: 1,
146+
workPackageNumber: 0,
147+
organizationId: organization.organizationId
148+
}
149+
}
150+
});
151+
152+
expect(wbsElement?.status).toEqual(WBS_Element_Status.ACTIVE);
153+
expect(wbsElement?.carNumber).toEqual(0);
154+
expect(wbsElement?.projectNumber).toEqual(1);
155+
expect(wbsElement?.workPackageNumber).toEqual(0);
156+
});
157+
it('create change request does not make active project inactive - work package changes', async () => {
158+
await prisma.wBS_Element.update({
159+
where: {
160+
wbsNumber: {
161+
carNumber: 0,
162+
projectNumber: 1,
163+
workPackageNumber: 0,
164+
organizationId: organization.organizationId
165+
}
166+
},
167+
data: {
168+
status: WBS_Element_Status.ACTIVE
169+
}
170+
});
171+
172+
const wpPropChanges: WorkPackageProposedChangesCreateArgs = {
173+
name: 'wp',
174+
descriptionBullets: [],
175+
links: [],
176+
duration: 3,
177+
startDate: '2025-09-13',
178+
blockedBy: [],
179+
leadId: user.userId,
180+
managerId: user.userId
181+
};
182+
183+
const cr = await ChangeRequestsService.createStandardChangeRequest(
184+
user,
185+
0,
186+
1,
187+
0,
188+
CR_Type.DEFINITION_CHANGE,
189+
'What',
190+
[
191+
{
192+
type: Scope_CR_Why_Type.COMPETITION,
193+
explain: 'Explaining'
194+
}
195+
],
196+
[],
197+
organization,
198+
null,
199+
wpPropChanges
200+
);
201+
202+
const wbsElement = await prisma.wBS_Element.findUnique({
203+
where: {
204+
wbsNumber: {
205+
carNumber: 0,
206+
projectNumber: 1,
207+
workPackageNumber: 0,
208+
organizationId: organization.organizationId
209+
}
210+
}
211+
});
212+
expect(cr.submitter.userId).toEqual(user.userId);
213+
expect(cr.wbsNum?.carNumber).toEqual(0);
214+
expect(cr.wbsNum?.projectNumber).toEqual(1);
215+
expect(cr.wbsNum?.workPackageNumber).toEqual(0);
216+
217+
expect(cr.type).toEqual(CR_Type.DEFINITION_CHANGE);
218+
expect(cr.what).toEqual('What');
219+
expect(cr.proposedSolutions).toHaveLength(0);
220+
221+
expect(cr.wbsNum).toBeDefined();
222+
expect(cr.wbsNum).not.toBeNull();
223+
224+
expect(wbsElement?.status).toEqual(WBS_Element_Status.ACTIVE);
225+
expect(wbsElement?.carNumber).toEqual(0);
226+
expect(wbsElement?.projectNumber).toEqual(1);
227+
expect(wbsElement?.workPackageNumber).toEqual(0);
228+
});
229+
it('create change request on an inactive project - work package changes', async () => {
230+
await prisma.wBS_Element.update({
231+
where: {
232+
wbsNumber: {
233+
carNumber: 0,
234+
projectNumber: 1,
235+
workPackageNumber: 0,
236+
organizationId: organization.organizationId
237+
}
238+
},
239+
data: {
240+
status: WBS_Element_Status.INACTIVE
241+
}
242+
});
243+
244+
const wpPropChanges: WorkPackageProposedChangesCreateArgs = {
245+
name: 'wp',
246+
descriptionBullets: [],
247+
links: [],
248+
duration: 3,
249+
startDate: '2025-09-13',
250+
blockedBy: [],
251+
leadId: user.userId,
252+
managerId: user.userId
253+
};
254+
255+
await ChangeRequestsService.createStandardChangeRequest(
256+
user,
257+
0,
258+
1,
259+
0,
260+
CR_Type.DEFINITION_CHANGE,
261+
'What',
262+
[
263+
{
264+
type: Scope_CR_Why_Type.COMPETITION,
265+
explain: 'Explaining'
266+
}
267+
],
268+
[],
269+
organization,
270+
null,
271+
wpPropChanges
272+
);
273+
274+
const wbsElement = await prisma.wBS_Element.findUnique({
275+
where: {
276+
wbsNumber: {
277+
carNumber: 0,
278+
projectNumber: 1,
279+
workPackageNumber: 0,
280+
organizationId: organization.organizationId
281+
}
282+
}
283+
});
284+
285+
expect(wbsElement?.status).toEqual(WBS_Element_Status.INACTIVE);
286+
expect(wbsElement?.carNumber).toEqual(0);
287+
expect(wbsElement?.projectNumber).toEqual(1);
288+
expect(wbsElement?.workPackageNumber).toEqual(0);
289+
});
290+
});
291+
});

0 commit comments

Comments
 (0)