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

[Bug]Failure to change preferred name, or identifier using a POST req… #305

Merged
merged 1 commit into from
Oct 4, 2017

Conversation

chibujax
Copy link
Contributor

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

@chibujax
Copy link
Contributor Author

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());
Copy link
Member

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?

Copy link
Contributor Author

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);
}
Copy link
Member

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?

Copy link
Contributor Author

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

@dkayiwa
Copy link
Member

dkayiwa commented Sep 29, 2017

You also need to add a test for these changes like Darius did for the commit you are copying from.

@chibujax chibujax force-pushed the RESTWS-677 branch 2 times, most recently from 786a511 to 671863d Compare September 29, 2017 16:22
@chibujax
Copy link
Contributor Author

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?

@dkayiwa
Copy link
Member

dkayiwa commented Oct 1, 2017

@andela-cuchendu replace service.savePatient() with service().savePatientIdentifier(delegate)

@chibujax
Copy link
Contributor Author

chibujax commented Oct 3, 2017

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());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.02%) to 40.381% when pulling 8600a98 on andela-cuchendu:RESTWS-677 into f0711b8 on openmrs:master.

@chibujax
Copy link
Contributor Author

chibujax commented Oct 3, 2017

I shot myself on the leg, corrected 😄

@dkayiwa
Copy link
Member

dkayiwa commented Oct 3, 2017

Did you use an AK-47? 🔫

@chibujax
Copy link
Contributor Author

chibujax commented Oct 3, 2017

No. With my action 😄 Is there any more work to be done on this? 😄

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.02%) to 40.381% when pulling 8600a98 on andela-cuchendu:RESTWS-677 into f0711b8 on openmrs:master.

Boolean originalPreferredStatus = patientIdentifier.getPreferred();
Boolean postPreferredStatus = !originalPreferredStatus;
SimpleObject postPatientIdentifier = new SimpleObject();
postPatientIdentifier.add("preferred", postPreferredStatus);
Copy link
Member

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?

Copy link
Contributor Author

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

Copy link
Member

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;
Copy link
Member

@dkayiwa dkayiwa Oct 4, 2017

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

Copy link
Contributor Author

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());
Copy link
Member

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?

Copy link
Contributor Author

@chibujax chibujax Oct 4, 2017

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.

Copy link
Contributor Author

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.

Copy link
Contributor Author

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;

Copy link
Contributor Author

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)

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.02%) to 40.381% when pulling 5986a30 on andela-cuchendu:RESTWS-677 into f0711b8 on openmrs:master.

@chibujax
Copy link
Contributor Author

chibujax commented Oct 4, 2017

I have removed the unwanted test. Also, I have tested on the app and postman locally.

@dkayiwa
Copy link
Member

dkayiwa commented Oct 4, 2017

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?

@chibujax
Copy link
Contributor Author

chibujax commented Oct 4, 2017

Ok I will. Is there anything more to be done on this?

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.02%) to 40.381% when pulling 3c489de on andela-cuchendu:RESTWS-677 into f0711b8 on openmrs:master.


String preferredUuid = (String) PropertyUtils.getProperty(newPatientIdentifier, "uuid");
PatientIdentifier preferredIdentifer = service.getPatientIdentifierByUuid(preferredUuid);
assertEquals(nonPreferred.isPreferred(), false);
Copy link
Member

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?

Copy link
Contributor Author

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.

Copy link
Member

@dkayiwa dkayiwa Oct 4, 2017

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?

Copy link
Contributor Author

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);
Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Corrected

@chibujax
Copy link
Contributor Author

chibujax commented Oct 4, 2017

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. 😄

@chibujax
Copy link
Contributor Author

chibujax commented Oct 4, 2017

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

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.02%) to 40.381% when pulling d41bf40 on andela-cuchendu:RESTWS-677 into f0711b8 on openmrs:master.

assertNotNull(PropertyUtils.getProperty(newPatientIdentifier, "uuid"));
assertEquals(originalCount + 1, getAllCount());

String preferredUuid = (String) PropertyUtils.getProperty(newPatientIdentifier, "uuid");
Copy link
Member

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?

Copy link
Contributor Author

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

Copy link
Member

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed.

@chibujax
Copy link
Contributor Author

chibujax commented Oct 4, 2017

Changed

assertNotNull(uuid);
assertEquals(originalCount + 1, getAllCount());

String preferredUuid = (String) uuid;
Copy link
Member

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())

@chibujax
Copy link
Contributor Author

chibujax commented Oct 4, 2017

Ok, fixed. thank you 😄

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.02%) to 40.381% when pulling 861ff8a on andela-cuchendu:RESTWS-677 into f0711b8 on openmrs:master.

assertEquals(originalCount + 1, getAllCount());

PatientIdentifier preferredIdentifer = service.getPatientIdentifierByUuid(uuid.toString());
assertFalse(nonPreferred.isPreferred());
Copy link
Member

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?

Copy link
Contributor Author

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.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.02%) to 40.381% when pulling 861ff8a on andela-cuchendu:RESTWS-677 into f0711b8 on openmrs:master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.02%) to 40.381% when pulling 861ff8a on andela-cuchendu:RESTWS-677 into f0711b8 on openmrs:master.

@chibujax
Copy link
Contributor Author

chibujax commented Oct 4, 2017

I have added assertEquals(preferredIdentifer.getIdentifier(), "abc123ez"); which was set on line 123. I guess this confirms it.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.02%) to 40.381% when pulling f84b5e9 on andela-cuchendu:RESTWS-677 into f0711b8 on openmrs:master.

@@ -114,6 +115,33 @@ public void shouldEditAPatientIdentifier() throws Exception {
}

@Test
public void shouldUnsetOtherPreferredIdentifiers() throws Exception {
PatientIdentifier nonPreferred = service.getPatientIdentifierByUuid(getUuid());
Copy link
Member

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?

Copy link
Contributor Author

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

@chibujax
Copy link
Contributor Author

chibujax commented Oct 4, 2017

Yes, makes sense. Changed to exisitingIdentifer

assertNotNull(uuid);
assertEquals(originalCount + 1, getAllCount());

PatientIdentifier preferredIdentifer = service.getPatientIdentifierByUuid(uuid.toString());
Copy link
Member

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, done.

@chibujax
Copy link
Contributor Author

chibujax commented Oct 4, 2017

Ok, done.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.02%) to 40.381% when pulling eeb1749 on andela-cuchendu:RESTWS-677 into f0711b8 on openmrs:master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.02%) to 40.381% when pulling eeb1749 on andela-cuchendu:RESTWS-677 into f0711b8 on openmrs:master.

@dkayiwa dkayiwa merged commit 799057d into openmrs:master Oct 4, 2017
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.

3 participants