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

Refactor Enketo service code to allow for reuse by test harness #7567

Closed
wants to merge 248 commits into from

Conversation

jkuester
Copy link
Contributor

@jkuester jkuester commented Mar 22, 2022

Refactors code for Enketo forms to allow for reuse by https://github.com/medic/cht-conf-test-harness. The goal of these changes is to minimize the amount of duplicate code required in the test harness for working with Enketo forms. This should make it easier to maintain the test harness going forwards (simplifying the process of uplifting to new versions of Enketo/cht-core).

@kennsippell has been working on integrating the test harness with this refactored code in https://github.com/medic/cht-conf-test-harness/tree/enketo-uplift.

Changelist:

  • api/
    • The generate-xform service contained logic both for generating the xForm html files and for updating the forms stored on the client when one changed. This update logic was discrete from the generation logic and had some dependencies that caused issues for the test harness code when trying to consume the generation logic. So, I have refactored the update logic into a new update-xform service.
  • webapp/
    • The logic in the enketo Angular service is the main bit that we want to be able to reuse in the test harness. To do this, I had to decouple it from all the Angular-specific code and services. I created the enketo-form-manager.js which contains the refactored logic and can be pulled in by both the test harness and the enketo service.
    • The enketo-prepopulation-data service was only used by the enketo service, so I have refactored it into the enketo-data-prepopulator.js that is consumed directly by enketo-form-manager.
    • The xpath-element-path provider was only used by the enketo service, so I have refactored it into xpath-element-path.js that is consumed directly by enketo-form-manager.
    • The logic in the contact-save service is also needed by the test harness (to save their contact forms). So, I have refactored this logic into contact-saver.js.
      • The EnketoFormManager exposes the contact-saver functionality via the saveContactForm method to give a single point of reference for rendering and saving all Enketo forms.
      • I have updated the enketo service to have a saveContactForm method that can be used by the contacts-edit component to save the contact form (instead of using the (now removed) contact-save service).
    • The logic in the enketo-translation service was only being used by code that is now centralized in the enketo-form-manager. I have refactored that logic into a enketo-data-translator.js which is referenced directly by enketo logic.

#7462

Code review checklist

  • Readable: Concise, well named, follows the style guide, documented if necessary.
  • Tested: Unit and/or e2e where appropriate
  • Backwards compatible: Works with existing data and configuration or includes a migration. Any breaking changes documented in the release notes.

License

The software is provided under AGPL-3.0. Contributions to this project are accepted under the same license.

# Conflicts:
#	config/standard/forms/app/immunization_visit.xlsx
# Conflicts:
#	webapp/src/ts/modules/contacts/contacts-edit.component.ts
#	webapp/src/ts/services/contact-save.service.ts
#	webapp/tests/karma/ts/modules/contacts/contacts-edit.component.spec.ts
Base automatically changed from 6345-enketo-uplift to master August 16, 2022 19:03
# Conflicts:
#	api/src/services/generate-xform.js
#	api/tests/mocha/services/generate-xform.spec.js
#	package.json
#	webapp/src/ts/services/enketo.service.ts
#	webapp/tests/karma/ts/services/enketo.service.spec.ts
# Conflicts:
#	api/server.js
#	api/src/services/config-watcher.js
#	api/src/services/generate-xform.js
#	api/tests/mocha/services/generate-xform.spec.js
#	package.json
#	shared-libs/rules-engine/package-lock.json
#	shared-libs/rules-engine/package.json
#	webapp/src/ts/services/enketo-translation.service.ts
#	webapp/src/ts/services/enketo.service.ts
#	webapp/tests/karma/js/enketo/enketo-data-translator.spec.ts
#	webapp/tests/karma/ts/services/enketo.service.spec.ts
@jkuester
Copy link
Contributor Author

This PR will not be merged, but this enketo-service-refactor branch will serve as a temporary integration for the 4.0.0-compatible version of cht-conf-test-harness while we work on a more maintainable solution (hopefully coming in 4.1.0).

@jkuester jkuester closed this Nov 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants