harness.getContactSummary() : Unable to get contact summary that applies to conact

Hi
Am trying to implement test for condition cards but harness.getContactSummary() doesn’t returns cards that applies to contact

appliesTo: 'contacts',
appliesToType: 'household_member',

it only returns those that applies to report :arrow_down:

appliesTo: 'reports',
appliesToType: 'household_assessment',

const contactSummary = await harness.getContactSummary();
logging contactSummary Returns :arrow_down:
{ cards: [], fields: [], context: {} }

A great question.

What is the value of harness.subject when you call harness.getContactSummary()?

I would expect that this card would display if the harness.subject has the properties type: 'contact', contact_type: 'household_member'. If this is not a properly formatted contact document, or if it is a contact with a different type then I would expect the card to not display.

If you don’t want to change the test’s subject for whatever reason - there is also an option to provide the contact you are calculating a summary for. See the optional parameters on getContactSummary

const contact = { type: 'contact', contact_type: 'household_member' };
const contactSummary = await harness.getContactSummary(contact);
console.log(contactSummary);
1 Like

Thank you @kenn
My harness .subject has the properties type: 'contact', contact_type: 'household_member' but still harness.getContactSummary(); returns { cards: [], fields: [], context: {} }

1 Like

Okay interesting. Is the code snippet provided above also returning without any cards?

Can you share the full definition for the card? If you share a pull request or the code, we can help to debug your complete situation.

Hello @David_Kiragu,

That’s an interesting scenario you present. I would spend time to dig into the various components that might lead to what you are observing.

  1. Ensure that your subject, likely defaulting to one set in harness.defaults.json has the same contact_type ID expected in appliesToType of your card.
  2. Check that the condition you pass in appliesIf is satisfied by your test case. For example, if you are testing a card that applies to contacts over 5 years, you would have to set the date_of_birth attribute of your harness contact to a date that results in age over 5 years lest your get an empty cards array. In addition to that, if you proceed to check nested card components such as fields on a card that actually does not exist, the test will further fail because of an attempt to extract attributes of null.
  3. Check that you are handling objects such as null or undefined that you further use to extract values you use with fields in your card. For instance, an attempt to use getField(report, field) (see Utils) on a non-existing report will easily get messy when you run tests. Of course you will get a descriptive error message when you attempt such, but just ensure you handle such exceptions before they affect the card.

Let us know how it goes, and share snippets to help narrow down the issue.

Thanks @kitsao and @kenn
This is how my card looks like
@kenn Above snippet doesn’t return cards as we want to.
@kitsao My subject in harness.defaults.json has the following properties

"_id": "patient_id",
"type": "person",
"contact_type": "household_member",
"name": "Patient Name",
"role": "patient",
"date_of_birth": "1970-07-09",
"sex": "female",
"reported_date": 1550762498368,

function ageInMonths(dateOfBirth) {
  const dob = DateTime.fromISO(dateOfBirth);
  const now = DateTime.now();
  return now.diff(dob, 'months').months;
}


const under5AssessmentReport = getMostRecentReport(reports, [FORMS.CHILD_ASSESSMENT]);
const under5AssessmentReport = getMostRecentReport(reports, [FORMS.CHILD_ASSESSMENT]);
  {
    label: 'contact.profile.child_health',
    appliesToType: [CONTACT_TYPES.HOUSEHOLD_MEMBER],
    appliesIf: function() {
      return ageInMonths(thisContact.date_of_birth) < 60;
    },
    fields: [
      {
        label: 'contact.profile.sleeps_under_llin',
        icon: 'sleeps_under_llin',
        translate: true,
        value: function() {
          return getField(under5AssessmentReport, 'children_under_assessment.nets_treated');
        },
      },
      {
        label: 'contact.profile.suspected_malaria',
        icon: function() {
          return getField(under5AssessmentReport, 'children_under_assessment.suspected_of_malaria') === 'Yes' ? 'danger' : 'suspected_malaria';
        },
        translate: true,
        value: function() {
          return getField(under5AssessmentReport, 'children_under_assessment.suspected_of_malaria');
        },
      }
    ],
  },