-
Notifications
You must be signed in to change notification settings - Fork 523
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
[Bug]Failure to change preferred name, or identifier using a POST req… #305
Conversation
This is what I came up with, but fails test with "'Patient#2' failed to validate with reason: error.preferredIdentifier" I have not written the unit test for this, but for you to guide. |
return service().savePatientIdentifier(delegate); | ||
} | ||
service().savePatientIdentifier(delegate); | ||
//service().savePatient(delegate.getPatient()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the use of the above commented out line?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My bad, will remove
for (PatientIdentifier pi : delegate.getPatient().getActiveIdentifiers()) { | ||
if (!pi.equals(delegate)) { | ||
pi.setPreferred(false); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The changes you have in PatientIdentifierResource1_8.java look more than the ones for PersonAddressResource1_8.java in this commit d23b7dd
Can you please do exactly the changes like Darius committed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok. Thank you. !Great tip
You also need to add a test for these changes like Darius did for the commit you are copying from. |
786a511
to
671863d
Compare
I have updated but still with error: 'Patient#2' failed to validate with reason: error.preferredIdentifier and this is caused by line 230 to 236. Please how may I proceed? |
@andela-cuchendu replace service.savePatient() with service().savePatientIdentifier(delegate) |
Changes made, two tests added, tests passing 😄 |
|
||
String preferredUuid = (String) PropertyUtils.getProperty(newPatientIdentifier, "uuid"); | ||
PatientIdentifier preferredIdentifer = service.getPatientIdentifierByUuid(preferredUuid); | ||
System.out.print("none prefered is " + nonPreferred.isPreferred()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have you looked at this? https://wiki.openmrs.org/display/docs/Java+Conventions#JavaConventions-Donotprintout
I shot myself on the leg, corrected 😄 |
Did you use an AK-47? 🔫 |
No. With my action 😄 Is there any more work to be done on this? 😄 |
Boolean originalPreferredStatus = patientIdentifier.getPreferred(); | ||
Boolean postPreferredStatus = !originalPreferredStatus; | ||
SimpleObject postPatientIdentifier = new SimpleObject(); | ||
postPatientIdentifier.add("preferred", postPreferredStatus); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this test fail before your changes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was no test for editing preferred. So I added it to test if it could edit preferred
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In other words, this test is not related to the ticket. Correct?
public void shouldEditAPatientIdentifierWithPreferredAttibuite() throws Exception { | ||
PatientIdentifier patientIdentifier = service.getPatientIdentifierByUuid(getUuid()); | ||
Boolean originalPreferredStatus = patientIdentifier.getPreferred(); | ||
Boolean postPreferredStatus = !originalPreferredStatus; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the use of the above variable? postPreferredStatus
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The identifier to be changed. I guess I should change the name
MockHttpServletRequest req = request(RequestMethod.POST, getURI() + "/" + getUuid()); | ||
req.setContent(json.getBytes()); | ||
handle(req); | ||
assertNotEquals(originalPreferredStatus, patientIdentifier.getPreferred()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After posting, how do you confirm that the preferred was persisted?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
assertNotEquals(originalPreferredStatus, patientIdentifier.getPreferred()); Assert that the new value is not the same with old one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
assertNotEquals(originalPreferredStatus, patientIdentifier.getPreferred()); Assert that the new value is not the same with old one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I toggled the value on line 120 newPreferredStatus = !originalPreferredStatus;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So assuming patientIdentifier.getPreferred() is TRUE, then posting with toggled value will make it FALSE. then I will assert that the new value which is now FALSE is no longer the original value(TRUE)
I have removed the unwanted test. Also, I have tested on the app and postman locally. |
The test is still useful. Though you would need to create a new ticket and hence a separate pull request for it. Does it make sense? |
Ok I will. Is there anything more to be done on this? |
|
||
String preferredUuid = (String) PropertyUtils.getProperty(newPatientIdentifier, "uuid"); | ||
PatientIdentifier preferredIdentifer = service.getPatientIdentifierByUuid(preferredUuid); | ||
assertEquals(nonPreferred.isPreferred(), false); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How sure are you that nonPreferred.isPreferred() did not have a value of false even before the POST rest call?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because, since I have new preferred(preferredIdentifer), the nonPreferred must become false. This is the fix I worked on, setting others false when we have new preferred.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you say that it must become false, how sure are you that it was true?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have added assertTrue(nonPreferred.isPreferred()); to prove that nonPreferred.isPreferred() == false.
String preferredUuid = (String) PropertyUtils.getProperty(newPatientIdentifier, "uuid"); | ||
PatientIdentifier preferredIdentifer = service.getPatientIdentifierByUuid(preferredUuid); | ||
assertEquals(nonPreferred.isPreferred(), false); | ||
assertEquals(preferredIdentifer.isPreferred(), true); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also instead of assertEquals, assertTrue or assertFalse is clearer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Corrected
I have added assertTrue(nonPreferred.isPreferred()); before the call to prove that nonPreferred.isPreferred() == true and I have used assertTrue and assertFalse instead of assertEquals. I have also proved the outcome. 😄 |
So line 121 which is assertTrue(nonPreferred.isPreferred()); proves that nonPreferred was the preferred identifier before the call. Line 140 to 141 (assertFalse(nonPreferred.isPreferred()); and assertTrue(preferredIdentifer.isPreferred());) Proves that nonPrefered after the call is now false and the preferredIdentifer is True |
assertNotNull(PropertyUtils.getProperty(newPatientIdentifier, "uuid")); | ||
assertEquals(originalCount + 1, getAllCount()); | ||
|
||
String preferredUuid = (String) PropertyUtils.getProperty(newPatientIdentifier, "uuid"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't this the same call being repeated as online 135?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On line 135, I just assert that the property is not null, then on 138, I only got the uuid (which I made sure in 135 that it is not null), used the uuid on line 139 to get the preferredIdentifier. So I don't think its a repeated call
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you sure PropertyUtils.getProperty(newPatientIdentifier, "uuid") is not repeated?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed.
Changed |
assertNotNull(uuid); | ||
assertEquals(originalCount + 1, getAllCount()); | ||
|
||
String preferredUuid = (String) uuid; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need of the above variable. You could just service.getPatientIdentifierByUuid(uuid.toString())
Ok, fixed. thank you 😄 |
assertEquals(originalCount + 1, getAllCount()); | ||
|
||
PatientIdentifier preferredIdentifer = service.getPatientIdentifierByUuid(uuid.toString()); | ||
assertFalse(nonPreferred.isPreferred()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add another assertion or two to confirm that this is the one you have just posted?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have added assertEquals(preferredIdentifer.getIdentifier(), "abc123ez"); which was set on line 123. I guess this confirms it.
I have added assertEquals(preferredIdentifer.getIdentifier(), "abc123ez"); which was set on line 123. I guess this confirms it. |
@@ -114,6 +115,33 @@ public void shouldEditAPatientIdentifier() throws Exception { | |||
} | |||
|
|||
@Test | |||
public void shouldUnsetOtherPreferredIdentifiers() throws Exception { | |||
PatientIdentifier nonPreferred = service.getPatientIdentifierByUuid(getUuid()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The nonPreferred variable name is a bit confusing. Can you think of better name?
For instance, look at this on line 121 assertTrue(nonPreferred.isPreferred());
In other words, how can non preferred be expected to be preferred? 😊
Do you agree?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, makes sense. Changed to exisitingIdentifer
Yes, makes sense. Changed to exisitingIdentifer |
assertNotNull(uuid); | ||
assertEquals(originalCount + 1, getAllCount()); | ||
|
||
PatientIdentifier preferredIdentifer = service.getPatientIdentifierByUuid(uuid.toString()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then in that case preferredIdentifer becomes newIdentifer
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, done.
…uest to the REST API
Ok, done. |
JIRA TICKET NAME:
RESTWS-677: Failure to change preferred name, or identifier using a POST request to the REST API
SUMMARY:
Fixes the Failure to change preferred name, or identifier using a POST request to the REST API