medic / angular10-migration

0 stars 0 forks source link

setSelectedContact effect is loading children from previously selected contact #123

Open dianabarsan opened 3 years ago

dianabarsan commented 3 years ago

Code: https://github.com/medic/cht-core/blob/4750-angular-10-take-2/webapp/src/ts/effects/contacts.effects.ts#L85

This effect is purposefully loading the children of the previously selected contact. The bug is hidden behind a race condition, where we have a both an reducer and an effect reacting to the same action. As a result, most of the times, the previously selected contact is actually the newly selected contact (when the reducer runs before the effect).

We should fix this so:

  1. There is no race condition to speak of. Updating the store should be achieved by a different action that is only triggered from within the setSelectedContact effect.
  2. The newly selected contact's children are loaded instead of the previous.
  3. Full unit test coverage is added for the effect., covering all possible situations.