Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#1834 - Hierarchical mocks for workflow E2E tests #1865

Merged
merged 8 commits into from
Apr 10, 2023

Conversation

andrewsignori-aot
Copy link
Collaborator

@andrewsignori-aot andrewsignori-aot commented Apr 6, 2023

The service task ids are now the root of the mocked objects. When the same service task id exists for multiple subprocesses, these subprocesses are added as a child of the root service task id object. In the below sample, create_supporting_users_for_parents_task is not invoked by any subprocess, so the mocked objects for result and messageResult are direct properties of the root service task id. On the other hand, create_income_request_task is invoked by multiple subprocesses, and result and messageResult are associated with each one of them.

The load-assessment-data-? subprocess, which is potentially invoked twice, is now treated as a regular subprocess where we should provide mocked data for both subprocesses (the same data can be provided twice).

Sample Hierarchical Mocks

Please that some null or empty values were removed from consolidated data for better visualization here.
The main differences between load_assessment_data_submit_or_reassessment_subprocess and load_assessment_data_pre_assessment_subprocess are related to the variables prefixed with parent1 and parent2.

{
  "load_assessment_data_task": {
    "load_assessment_data_submit_or_reassessment_subprocess": {
      "result": {
        "assessmentTriggerType": "Original assessment",
        "studentDataParentValidSinNumber": "yes",
        "studentDataNumberOfParents": 2,
        "studentDataSelectedOffering": 1,
        "studentDataDependantstatus": "dependant",
        "programYear": "2022-2023",
        "programYearStartDate": "2022-08-01",
        "studentDataRelationshipStatus": "single",
        "studentDataTaxReturnIncome": 40000,
        "studentDataWhenDidYouGraduateOrLeaveHighSchool": "2017-03-01",
        "studentDataIndigenousStatus": "no",
        "studentDataHasDependents": "no",
        "studentDataLivingWithParents": "no",
        "studentDataYouthInCare": "no",
        "studentPDStatus": false,
        "studentTaxYear": 2021,
        "programLocation": "BC",
        "institutionLocationProvince": "BC",
        "institutionType": "BC Public",
        "programLength": "1YearToLessThan2Years",
        "programCredentialType": "undergraduateDegree",
        "offeringDelivered": "onsite",
        "offeringProgramRelatedCosts": 5000,
        "offeringActualTuitionCosts": 20000,
        "offeringMandatoryFees": 500,
        "offeringExceptionalExpenses": 500,
        "offeringWeeks": 16,
        "offeringIntensity": "Full Time",
        "offeringStudyStartDate": "2023-02-01",
        "offeringStudyEndDate": "2023-05-24"
      }
    },
    "load_assessment_data_pre_assessment_subprocess": {
      "result": {
        "assessmentTriggerType": "Original assessment",
        "studentDataParentValidSinNumber": "yes",
        "studentDataNumberOfParents": 2,
        "parent1Contributions": 10000,
        "parent1Ei": 0,
        "parent1NetAssests": 300000,
        "parent1Tax": 0,
        "parent1TotalIncome": 75000,
        "parent1CppEmployment": 5000,
        "parent1CppSelfemploymentOther": 200,
        "parent2Contributions": 10000,
        "parent2CppSelfemploymentOther": 200,
        "parent2Ei": 0,
        "parent2NetAssests": 300000,
        "parent2Tax": 0,
        "parent2TotalIncome": 75000,
        "parent2CppEmployment": 5000,
        "studentDataDependantstatus": "dependant",
        "programYear": "2022-2023",
        "programYearStartDate": "2022-08-01",
        "studentDataRelationshipStatus": "single",
        "studentDataTaxReturnIncome": 40000,
        "studentDataWhenDidYouGraduateOrLeaveHighSchool": "2017-03-01",
        "studentDataIndigenousStatus": "no",
        "studentDataHasDependents": "no",
        "studentDataLivingWithParents": "no",
        "studentDataYouthInCare": "no",
        "studentPDStatus": false,
        "studentTaxYear": 2021,
        "programLocation": "BC",
        "institutionLocationProvince": "BC",
        "institutionType": "BC Public",
        "programLength": "1YearToLessThan2Years",
        "programCredentialType": "undergraduateDegree",
        "offeringDelivered": "onsite",
        "offeringProgramRelatedCosts": 5000,
        "offeringActualTuitionCosts": 20000,
        "offeringMandatoryFees": 500,
        "offeringExceptionalExpenses": 500,
        "offeringWeeks": 16,
        "offeringIntensity": "Full Time",
        "offeringStudyStartDate": "2023-02-01",
        "offeringStudyEndDate": "2023-05-24"
      }
    }
  },
  "verify_application_exceptions_task": {
    "result": {
      "applicationExceptionStatus": "Approved"
    }
  },
  "create_supporting_users_for_parents_task": {
    "result": {
      "createdSupportingUsersIds": [
        1000,
        1001
      ]
    },
    "messageResult": [
      {
        "name": "supporting-user-info-received",
        "correlationKey": "1000",
        "variables": {},
        "timeToLive": {
          "type": "SECONDS",
          "value": 10,
          "valueType": "TYPED_DURATION",
          "unit": "s"
        }
      },
      {
        "name": "supporting-user-info-received",
        "correlationKey": "1001",
        "variables": {},
        "timeToLive": {
          "type": "SECONDS",
          "value": 10,
          "valueType": "TYPED_DURATION",
          "unit": "s"
        }
      }
    ]
  },
  "check_supporting_user_response_task": {
    "retrieve_supporting_info_for_parent_1_subprocess": {
      "result": {
        "totalIncome": 1
      }
    },
    "retrieve_supporting_info_for_parent_2_subprocess": {
      "result": {
        "totalIncome": 1
      }
    }
  },
  "create_income_request_task": {
    "student_income_verification_subprocess": {
      "result": {
        "incomeVerificationCompleted": true,
        "incomeVerificationId": 1000
      },
      "messageResult": [
        {
          "name": "income-verified",
          "correlationKey": "1000",
          "variables": {},
          "timeToLive": {
            "type": "SECONDS",
            "value": 10,
            "valueType": "TYPED_DURATION",
            "unit": "s"
          }
        }
      ]
    },
    "parent_1_income_verification_subprocess": {
      "result": {
        "incomeVerificationCompleted": true,
        "incomeVerificationId": 1001
      },
      "messageResult": [
        {
          "name": "income-verified",
          "correlationKey": "1001",
          "variables": {},
          "timeToLive": {
            "type": "SECONDS",
            "value": 10,
            "valueType": "TYPED_DURATION",
            "unit": "s"
          }
        }
      ]
    },
    "parent_2_income_verification_subprocess": {
      "result": {
        "incomeVerificationCompleted": true,
        "incomeVerificationId": 1002
      },
      "messageResult": [
        {
          "name": "income-verified",
          "correlationKey": "1002",
          "variables": {},
          "timeToLive": {
            "type": "SECONDS",
            "value": 10,
            "valueType": "TYPED_DURATION",
            "unit": "s"
          }
        }
      ]
    }
  },
  "check_income_request_task": {
    "student_income_verification_subprocess": {
      "result": {
        "incomeVerificationCompleted": true
      }
    },
    "parent_1_income_verification_subprocess": {
      "result": {
        "incomeVerificationCompleted": true
      }
    },
    "parent_2_income_verification_subprocess": {
      "result": {
        "incomeVerificationCompleted": true
      }
    }
  }
}

Resuing the same mock for multiple subprocesses.

A mocked object can be reused for multiple tasks under different subprocesses, as shown below.

image

image

Test summary readability

To allow better readability of the test summary, the Zeebe logging is disabled.

image

Varibales naming conventions

The possible change in the naming conventions for the service task ids is not considered for this PR.

WorkflowServiceTasks and WorkflowSubprocesses are now following the same convention, as shown below.
Right now service task ids are still using the "-" as separators while Camunda E2E-related variables are using "_", which makes it easier to identify a variable on the workflow that is related to E2E.

image

@andrewsignori-aot andrewsignori-aot added E2E/Unit tests Camunda Worflow Involves camunda workflow changes labels Apr 6, 2023
@andrewsignori-aot andrewsignori-aot self-assigned this Apr 6, 2023
@andrewsignori-aot andrewsignori-aot marked this pull request as ready for review April 6, 2023 22:16
return createMockedWorkerResult(
WorkflowServiceTasks.LoadAssessmentConsolidatedData,
{
subprocess:
Copy link
Contributor

@ann-aot ann-aot Apr 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pls add comments and review the comments

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comments updated.

* - `result`: suffix that identifies the job completed object.
* @param serviceTaskId service task id that will have the job completed returned.
* @returns mock identifier for a completed job to be sent to the workflow.
* - `passthrough`: suffix that identifies the job passthrough identifier.
Copy link
Contributor

@ann-aot ann-aot Apr 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

passthrough is just a word change right, logically it is the same right. it represent the passed/completed task/flow

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I was not so sure at the beginning but it seems to be "The act or process of passing through" (https://en.wiktionary.org/wiki/passthrough#). If it is confusing I can change it.

@@ -66,7 +56,9 @@ export class ZeebeMockedClient {
taskType,
taskHandler: mockTaskHandler,
}));
ZeebeMockedClient.mockedZeebeClient = new ZBClient();
// Zeebe client logs disabled for a better test summary display.
// It can be enable as needed for troubleshooting.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

const dataPreAssessment: AssessmentConsolidatedData = {
assessmentTriggerType: AssessmentTriggerType.OriginalAssessment,
...createFakeConsolidatedFulltimeData(PROGRAM_YEAR),
...createParentsData({
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❤️

Copy link
Contributor

@ann-aot ann-aot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good effort @andrewsignori-aot 👍

@@ -28,15 +31,19 @@ describe(`E2E Test Workflow assessment gateway on student appeal for ${PROGRAM_Y
...createFakeSingleIndependentStudentData(),
};

const workersMockedData = createWorkersMockedData([
createLoadAssessmentDataTaskMock({
assessmentConsolidatedData: assessmentConsolidatedData,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are ignoring the subprocess context here, which is great 👍

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I resolved this comment using the same 😉
#1865 (comment)

Copy link
Collaborator

@andrepestana-aot andrepestana-aot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

/**
* Suffix that indicates if a task or subprocess was invoked by the workflow.
*/
export const JOB_PASSTHROUGH_SUFFIX = "passthrough";
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What was the intention having passthrough suffixed(in the bpmn output value of variable)? to follow the pattern of aligning with it's purpose?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without the suffix, we would be actually updating the entire mocked object that is now the root of the mock.
For instance, we would be replacing the below:

 "verify_application_exceptions_task": {
    "result": {
      "applicationExceptionStatus": "Approved"
    }
  },

by

 "verify_application_exceptions_task": "verify_application_exceptions_task"

@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@github-actions
Copy link

Backend Unit Tests Coverage Report

Totals Coverage
Statements: 17.99% ( 1960 / 10892 )
Methods: 8.12% ( 115 / 1417 )
Lines: 20.71% ( 1716 / 8286 )
Branches: 10.85% ( 129 / 1189 )

@github-actions
Copy link

E2E Workflow Workers Coverage Report

Totals Coverage
Statements: 32.41% ( 176 / 543 )
Methods: 21.25% ( 17 / 80 )
Lines: 39.25% ( 157 / 400 )
Branches: 3.17% ( 2 / 63 )

@github-actions
Copy link

E2E Queue Consumers Coverage Report

Totals Coverage
Statements: 56.72% ( 308 / 543 )
Methods: 46.38% ( 32 / 69 )
Lines: 59.48% ( 276 / 464 )
Branches: 0% ( 0 / 10 )

@github-actions
Copy link

E2E SIMS API Coverage Report

Totals Coverage
Statements: 38.08% ( 2580 / 6775 )
Methods: 29.82% ( 263 / 882 )
Lines: 43.7% ( 2208 / 5053 )
Branches: 12.98% ( 109 / 840 )

Copy link
Collaborator

@dheepak-aot dheepak-aot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for making the changes, Great work again 👍

Copy link
Collaborator

@guru-aot guru-aot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, good work @andrewsignori-aot

@andrewsignori-aot andrewsignori-aot merged commit 14c91cc into main Apr 10, 2023
@andrewsignori-aot andrewsignori-aot temporarily deployed to DEV April 10, 2023 20:46 — with GitHub Actions Inactive
@andrewsignori-aot andrewsignori-aot deleted the feature/#1834-hierarchical-mocks branch April 10, 2023 20:46
@andrewsignori-aot andrewsignori-aot temporarily deployed to DEV April 10, 2023 20:46 — with GitHub Actions Inactive
@andrewsignori-aot andrewsignori-aot temporarily deployed to DEV April 10, 2023 20:56 — with GitHub Actions Inactive
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Camunda Worflow Involves camunda workflow changes E2E/Unit tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants