@@ -14,11 +14,9 @@ import { Location } from '../src/components/location/dto';
14
14
import { ProductMethodology } from '../src/components/product/dto' ;
15
15
import {
16
16
Project ,
17
- ProjectStatus ,
18
17
ProjectStep ,
19
18
ProjectType ,
20
19
} from '../src/components/project/dto' ;
21
- import { ProjectWorkflowTransition } from '../src/components/project/workflow/dto' ;
22
20
import { User } from '../src/components/user/dto' ;
23
21
import {
24
22
createDirectProduct ,
@@ -50,9 +48,10 @@ import {
50
48
} from './utility/transition-engagement' ;
51
49
import {
52
50
changeProjectStep ,
51
+ forceProjectTo ,
52
+ getProjectTransitions ,
53
53
stepsFromEarlyConversationToBeforeActive ,
54
- stepsFromEarlyConversationToBeforeCompleted ,
55
- stepsFromEarlyConversationToBeforeTerminated ,
54
+ transitionProject ,
56
55
} from './utility/transition-project' ;
57
56
58
57
describe ( 'Engagement e2e' , ( ) => {
@@ -1006,7 +1005,7 @@ describe('Engagement e2e', () => {
1006
1005
) ;
1007
1006
} ) ;
1008
1007
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 ( ) => {
1010
1009
const location = await runAsAdmin ( app , async ( ) => {
1011
1010
const fundingAccount = await createFundingAccount ( app ) ;
1012
1011
const location = await createLocation ( app , {
@@ -1022,91 +1021,75 @@ describe('Engagement e2e', () => {
1022
1021
projectId : project . id ,
1023
1022
} ) ;
1024
1023
1024
+ // Change the project & engagement to FinalizingCompletion
1025
+ await forceProjectTo ( app , project . id , 'FinalizingCompletion' ) ;
1026
+
1027
+ // Add another engagement not FinalizingCompletion
1025
1028
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
- */
1033
1029
await createLanguageEngagement ( app , {
1034
1030
projectId : project . id ,
1035
1031
} ) ;
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
+ } ) ;
1056
1033
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 ) ;
1061
1038
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' ) ;
1070
1040
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
+ ) ;
1097
1056
} ) ;
1098
1057
1099
1058
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
+ ] ,
1104
1079
// this only happens when an admin overrides to completed
1105
1080
// this is prohibited if there are non terminal engagements
1106
- [ EngagementStatus . Completed , stepsFromEarlyConversationToBeforeCompleted ] ,
1081
+ [
1082
+ ProjectStep . FinalizingCompletion ,
1083
+ ProjectStep . Completed ,
1084
+ EngagementStatus . Completed ,
1085
+ ] ,
1107
1086
] ) (
1108
1087
'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
+ ) => {
1110
1093
const location = await runAsAdmin ( app , async ( ) => {
1111
1094
const fundingAccount = await createFundingAccount ( app ) ;
1112
1095
const location = await createLocation ( app , {
@@ -1117,48 +1100,49 @@ describe('Engagement e2e', () => {
1117
1100
const project = await createProject ( app , {
1118
1101
primaryLocationId : location . id ,
1119
1102
} ) ;
1120
- expect ( project . status ) . toBe ( ProjectStatus . InDevelopment ) ;
1121
-
1122
1103
const engagement = await createLanguageEngagement ( app , {
1123
1104
projectId : project . id ,
1124
1105
} ) ;
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
1128
1111
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
+ } ) ;
1132
1118
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 {
1138
1128
id
1139
- engagements {
1140
- items {
1141
- id
1142
- status {
1143
- value
1144
- }
1145
- }
1129
+ status {
1130
+ value
1146
1131
}
1147
1132
}
1148
1133
}
1149
1134
}
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 ) ;
1162
1146
} ,
1163
1147
) ;
1164
1148
0 commit comments