OpenFn / primero-progres

Interoperability solution for UNICEF <> UNHCR interagency referrals between Primero and Progres v4 systems.
https://openfn.github.io/primero-progres/
0 stars 2 forks source link

f2-2.sendReferralToDTP job update: if 0 referrals, do not send any HTTP requests #54

Closed daissatou2 closed 2 years ago

daissatou2 commented 2 years ago

Describe the bug

The f2-2.sendReferralToDTP.js job is currently written to always send a GET request to the Primero /users endpoint... even if there are 0 referrals to send. If there are 0 referrals, we should take no further action and stop this job. https://github.com/OpenFn/primero-progres/blob/fb51245c6937382df6fe1d213d1eb7920fc5b9d8/jobs/PROD/f2-2.sendReferralToDTP.js#L10-L24

Please update the job to not execute the GET request on L10 if no cases are returned from the parent run of f2-1.getCasesFromPrimero.js.

Check if caseid.length = 0 --> if true, do NOT send the GET request. If caseid.length > 0 then proceed with the get request.

To Reproduce

  1. Run the first job in the flow f2-1.getCasesFromPrimero.js... and set the manual cursor to today's day and time to create a scenario where 0 cases will be returned.
  2. Use the output of this f2-1 job as the state.json for this next f2-2 job.

expression.js

Link to the job itself in Github: https://github.com/OpenFn/primero-progres/blob/master/jobs/PROD/f2-2.sendReferralToDTP.js

🚨 Please make changes on a separate branch and do not commit to master until approved. 🚨

state.json

f2-j1

{
  "configuration": ["SEE LAST PASS: 'Primero Gambella Demo - Get Referrals (open_function user)'"]
}

f2-j2

{
  "configuration": ["SEE LAST PASS: 'DTP UAT - ReceiveIncomingReferral (open_function)'"],
  "data": {"data is generated by f2-j1 job"}
}

Expected behavior

If the initial state of f2-j2 is no cases, we should not be attempting to send a GET request to Primero, and should stop running.

To test/resolve

  1. After the desired output is working locally (from the CLI), please open a pull request.
daissatou2 commented 2 years ago

@aleksa-krolls please confirm these are the correct staging credentials.