Skip to content

Commit 202196c

Browse files
committed
Update test suite to use transitionProject mutation
1 parent 4056243 commit 202196c

7 files changed

+205
-212
lines changed

test/engagement-changeset-aware.e2e-spec.ts

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { CalendarDate, ID, Role } from '~/common';
22
import { EngagementStatus } from '../src/components/engagement/dto';
33
import { Language } from '../src/components/language/dto';
44
import { ProjectChangeRequestType } from '../src/components/project-change-request/dto';
5-
import { ProjectStep } from '../src/components/project/dto';
65
import {
76
approveProjectChangeRequest,
87
createFundingAccount,
@@ -22,10 +21,7 @@ import {
2221
updateProject,
2322
} from './utility';
2423
import { fragments } from './utility/fragments';
25-
import {
26-
changeProjectStep,
27-
stepsFromEarlyConversationToBeforeActive,
28-
} from './utility/transition-project';
24+
import { forceProjectTo } from './utility/transition-project';
2925

3026
const readEngagements = (app: TestApp, id: string, changeset?: string) =>
3127
app.graphql.query(
@@ -135,14 +131,7 @@ const activeProject = async (app: TestApp, projectId: ID) => {
135131
primaryLocationId: location.id,
136132
fieldRegionId: region.id,
137133
});
138-
await runAsAdmin(app, async () => {
139-
for (const next of [
140-
...stepsFromEarlyConversationToBeforeActive,
141-
ProjectStep.Active,
142-
]) {
143-
await changeProjectStep(app, projectId, next);
144-
}
145-
});
134+
await forceProjectTo(app, projectId, 'Active');
146135
};
147136

148137
describe('Engagement Changeset Aware e2e', () => {

test/engagement.e2e-spec.ts

Lines changed: 92 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,9 @@ import { Location } from '../src/components/location/dto';
1414
import { ProductMethodology } from '../src/components/product/dto';
1515
import {
1616
Project,
17-
ProjectStatus,
1817
ProjectStep,
1918
ProjectType,
2019
} from '../src/components/project/dto';
21-
import { ProjectWorkflowTransition } from '../src/components/project/workflow/dto';
2220
import { User } from '../src/components/user/dto';
2321
import {
2422
createDirectProduct,
@@ -50,9 +48,10 @@ import {
5048
} from './utility/transition-engagement';
5149
import {
5250
changeProjectStep,
51+
forceProjectTo,
52+
getProjectTransitions,
5353
stepsFromEarlyConversationToBeforeActive,
54-
stepsFromEarlyConversationToBeforeCompleted,
55-
stepsFromEarlyConversationToBeforeTerminated,
54+
transitionProject,
5655
} from './utility/transition-project';
5756

5857
describe('Engagement e2e', () => {
@@ -1006,7 +1005,7 @@ describe('Engagement e2e', () => {
10061005
);
10071006
});
10081007

1009-
it('should not enable a Project step transition if the step is FinalizingCompletion and there are Engagements with non-terminal statuses', async () => {
1008+
it('Projects cannot be completed with engagements not finalizing or terminal', async () => {
10101009
const location = await runAsAdmin(app, async () => {
10111010
const fundingAccount = await createFundingAccount(app);
10121011
const location = await createLocation(app, {
@@ -1022,91 +1021,75 @@ describe('Engagement e2e', () => {
10221021
projectId: project.id,
10231022
});
10241023

1024+
// Change the project & engagement to FinalizingCompletion
1025+
await forceProjectTo(app, project.id, 'FinalizingCompletion');
1026+
1027+
// Add another engagement not FinalizingCompletion
10251028
await runAsAdmin(app, async () => {
1026-
for (const next of stepsFromEarlyConversationToBeforeCompleted) {
1027-
await changeProjectStep(app, project.id, next);
1028-
}
1029-
/**
1030-
* https://github.com/SeedCompany/cord-api-v3/issues/2526
1031-
* Need to another non-terminal Engagement (Not FinalizingCompletion)
1032-
*/
10331029
await createLanguageEngagement(app, {
10341030
projectId: project.id,
10351031
});
1036-
const projectQueryResult = await app.graphql.query(
1037-
gql`
1038-
query project($id: ID!) {
1039-
project(id: $id) {
1040-
id
1041-
step {
1042-
value
1043-
transitions {
1044-
to
1045-
disabled
1046-
disabledReason
1047-
}
1048-
}
1049-
}
1050-
}
1051-
`,
1052-
{
1053-
id: project.id,
1054-
},
1055-
);
1032+
});
10561033

1057-
const toCompletedTransition =
1058-
projectQueryResult.project.step.transitions.find(
1059-
(t: ProjectWorkflowTransition) => t.to === 'Completed',
1060-
);
1034+
// Read available transitions
1035+
const {
1036+
step: { transitions },
1037+
} = await getProjectTransitions(app, project.id);
10611038

1062-
expect(projectQueryResult.project.step.value).toBe(
1063-
ProjectStep.FinalizingCompletion,
1064-
);
1065-
expect(toCompletedTransition.disabled).toBe(true);
1066-
expect(toCompletedTransition.disabledReason).toBe(
1067-
'The project cannot be completed since some ongoing engagements are not "Finalizing Completion"',
1068-
);
1069-
});
1039+
const toCompletedTransition = transitions.find((t) => t.to === 'Completed');
10701040

1071-
// can't complete a project if you're not an admin and transition is disabled because of non terminal engagements
1072-
await app.graphql
1073-
.mutate(
1074-
gql`
1075-
mutation updateProject($id: ID!, $step: ProjectStep) {
1076-
updateProject(input: { project: { id: $id, step: $step } }) {
1077-
project {
1078-
id
1079-
engagements {
1080-
items {
1081-
id
1082-
status {
1083-
value
1084-
}
1085-
}
1086-
}
1087-
}
1088-
}
1089-
}
1090-
`,
1091-
{
1092-
id: project.id,
1093-
step: ProjectStep.Completed,
1094-
},
1095-
)
1096-
.expectError();
1041+
expect(toCompletedTransition?.disabled).toBe(true);
1042+
expect(toCompletedTransition?.disabledReason).toBe(
1043+
'The project cannot be completed since some ongoing engagements are not "Finalizing Completion"',
1044+
);
1045+
1046+
await expect(
1047+
transitionProject(app, {
1048+
project: project.id,
1049+
transition: toCompletedTransition?.key,
1050+
}),
1051+
).rejects.toThrowGqlError(
1052+
errors.unauthorized({
1053+
message: 'This transition is not available',
1054+
}),
1055+
);
10971056
});
10981057

10991058
it.each([
1100-
[EngagementStatus.Active, stepsFromEarlyConversationToBeforeActive],
1101-
[EngagementStatus.DidNotDevelop, []],
1102-
[EngagementStatus.Rejected, stepsFromEarlyConversationToBeforeActive],
1103-
[EngagementStatus.Terminated, stepsFromEarlyConversationToBeforeTerminated],
1059+
[
1060+
ProjectStep.PendingFinanceConfirmation,
1061+
ProjectStep.Active,
1062+
EngagementStatus.Active,
1063+
],
1064+
[
1065+
ProjectStep.EarlyConversations,
1066+
ProjectStep.DidNotDevelop,
1067+
EngagementStatus.DidNotDevelop,
1068+
],
1069+
[
1070+
ProjectStep.PendingFinanceConfirmation,
1071+
ProjectStep.Rejected,
1072+
EngagementStatus.Rejected,
1073+
],
1074+
[
1075+
ProjectStep.PendingTerminationApproval,
1076+
ProjectStep.Terminated,
1077+
EngagementStatus.Terminated,
1078+
],
11041079
// this only happens when an admin overrides to completed
11051080
// this is prohibited if there are non terminal engagements
1106-
[EngagementStatus.Completed, stepsFromEarlyConversationToBeforeCompleted],
1081+
[
1082+
ProjectStep.FinalizingCompletion,
1083+
ProjectStep.Completed,
1084+
EngagementStatus.Completed,
1085+
],
11071086
])(
11081087
'should update Engagement status to match Project step when it becomes %s',
1109-
async (newStatus: EngagementStatus, steps: ProjectStep[] | []) => {
1088+
async (
1089+
currentStepSetup: ProjectStep,
1090+
nextStep: ProjectStep,
1091+
expectedNewStatus: EngagementStatus,
1092+
) => {
11101093
const location = await runAsAdmin(app, async () => {
11111094
const fundingAccount = await createFundingAccount(app);
11121095
const location = await createLocation(app, {
@@ -1117,48 +1100,49 @@ describe('Engagement e2e', () => {
11171100
const project = await createProject(app, {
11181101
primaryLocationId: location.id,
11191102
});
1120-
expect(project.status).toBe(ProjectStatus.InDevelopment);
1121-
11221103
const engagement = await createLanguageEngagement(app, {
11231104
projectId: project.id,
11241105
});
1125-
expect(engagement.status.value === EngagementStatus.InDevelopment).toBe(
1126-
true,
1127-
);
1106+
const {
1107+
step: { transitions },
1108+
} = await forceProjectTo(app, project.id, currentStepSetup);
1109+
1110+
// ignoring proper transition permissions
11281111
await runAsAdmin(app, async () => {
1129-
for (const next of steps) {
1130-
await changeProjectStep(app, project.id, next);
1131-
}
1112+
const transition = transitions.find((t) => t.to === nextStep);
1113+
await transitionProject(app, {
1114+
project: project.id,
1115+
transition: transition?.key,
1116+
});
1117+
});
11321118

1133-
const result = await app.graphql.mutate(
1134-
gql`
1135-
mutation updateProject($id: ID!, $step: ProjectStep) {
1136-
updateProject(input: { project: { id: $id, step: $step } }) {
1137-
project {
1119+
const {
1120+
project: { engagements },
1121+
} = await app.graphql.query(
1122+
gql`
1123+
query ($id: ID!) {
1124+
project(id: $id) {
1125+
id
1126+
engagements {
1127+
items {
11381128
id
1139-
engagements {
1140-
items {
1141-
id
1142-
status {
1143-
value
1144-
}
1145-
}
1129+
status {
1130+
value
11461131
}
11471132
}
11481133
}
11491134
}
1150-
`,
1151-
{
1152-
id: project.id,
1153-
step: newStatus,
1154-
},
1155-
);
1156-
1157-
const actual = result.updateProject.project.engagements.items.find(
1158-
(e: { id: ID }) => e.id === engagement.id,
1159-
);
1160-
expect(actual.status.value).toBe(EngagementStatus[newStatus]);
1161-
});
1135+
}
1136+
`,
1137+
{
1138+
id: project.id,
1139+
step: expectedNewStatus,
1140+
},
1141+
);
1142+
const actual = engagements.items.find(
1143+
(e: { id: ID }) => e.id === engagement.id,
1144+
);
1145+
expect(actual.status.value).toBe(expectedNewStatus);
11621146
},
11631147
);
11641148

test/language-changeset-aware.e2e-spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import {
1515
TestApp,
1616
} from './utility';
1717
import { fragments } from './utility/fragments';
18-
import { transitionNewProjectToActive } from './utility/transition-project';
18+
import { forceProjectTo } from './utility/transition-project';
1919

2020
const readLanguage = (app: TestApp, id: string, changeset?: string) =>
2121
app.graphql.query(
@@ -44,7 +44,7 @@ const activeProject = async (app: TestApp) => {
4444
primaryLocationId: location.id,
4545
fieldRegionId: fieldRegion.id,
4646
});
47-
await transitionNewProjectToActive(app, project);
47+
await forceProjectTo(app, project.id, 'Active');
4848

4949
return project;
5050
};

test/partnership-changeset-aware.e2e-spec.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import {
1717
TestApp,
1818
} from './utility';
1919
import { fragments } from './utility/fragments';
20-
import { transitionNewProjectToActive } from './utility/transition-project';
20+
import { forceProjectTo } from './utility/transition-project';
2121

2222
const readPartnerships = (app: TestApp, id: string, changeset?: string) =>
2323
app.graphql.query(
@@ -71,9 +71,7 @@ const activeProject = async (app: TestApp) => {
7171
primaryLocationId: location.id,
7272
fieldRegionId: fieldRegion.id,
7373
});
74-
await runAsAdmin(app, async () => {
75-
await transitionNewProjectToActive(app, project);
76-
});
74+
await forceProjectTo(app, project.id, 'Active');
7775

7876
return project;
7977
};

test/project-workflow.e2e-spec.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,6 @@ describe('Project-Workflow e2e', () => {
6969
it('should have project step', async () => {
7070
const project = await createProject(app);
7171
expect(project.step.value).toBe(ProjectStep.EarlyConversations);
72-
});
73-
74-
it('should have project status', async () => {
75-
const project = await createProject(app);
7672
expect(project.status).toBe(ProjectStatus.InDevelopment);
7773
});
7874

0 commit comments

Comments
 (0)