AttachmentsService ahead of REST API work (ATT-24)

Ok sorry I was busy and unavailable.

For the encounter case you are adding 3 complex obs and 1 non-complex obs to an encounter and you verify that you are indeed fetching 3 attachments for that encounter.

For the visit case, you will have to add complex obs and non complex obs across multiple encounters during that visit, and ensure that you are fetching the attachments that correspond to the complex obs for that visit.

@mksd It is alright :slight_smile:

@mksd I added the two test methods. Feel free to give feedback at your leisure

Actually I have a small question. I create separate non context-sensitive method in Attachment resource for all the AttachmentService. So using mock test class is it enough to test that search method or do I need to rest API by sending the mock request ?

@ridmal can you point me to some code?

Actually I am still try on sending API request to AttachmentResource from the Mock Testing class. After finishing that I will send you my updated code. Is it ok ?

1 Like

@mksd,

Sorry for so much time taken to mockup testing part. But Actually I am little bit stuck with that test implementation. I have add the new context independent search method to Attachment Resource.

But I am unable to test those methods. Can you please check that I am going the in the right path. ( And if you can please give me some suggestion about how to call the API in the Attachment Resource from the Mock test. )

What you need in your test is to get your hand on a instance of AttachmentResource1_10. For the sake of that test you should just be able to do a:

AttachmentResource1_10 res = new AttachmentResource1_10();

Then, you want to invoke

res.search(as, patient, visit, encounter, includeEncounterless, includeVoided)

with, for each test method, the parameters either mocked or set in a way that will trigger a certain call on as.

As you can see, you have missed one parameter to the search method. It should also take the service as a parameter, that’s precisely in order to spy on it for eventually verifying that the appropriate methods where called.

1 Like

Ok I will look into that and add changes ASAP. :slight_smile:

Hi @mksd ,

There is an error occured when I tried to create the AttachmentResource1_10 object inside the AttachmentResourceTest . I think some configuration will failed when initiate the AttachmentResource1_10 object. So I modified the Search method as static method and it works. Is it ok to do that ?

Modified the test cases and sent a new PR . :slight_smile:

Hi @mksd ,

I sent the PR yesterday. But it failed to build because of some old error we solved. Seems like it occurs again. :frowning: Any idea for what we can do about that ? I will go trough again with that.

Something confuses me first, I see that in your PR, you are bringing again changes relating to the refactoring includeRetired → includeVoided. That shouldn’t be since this was merged into master already.

Please always start your PR branch off master and bring in your incremental changes there.

When you have done that, can you confirm whether you see this problem arising locally as well?

1 Like

Oh sorry , I saw it now. I will change that immediately. :slight_smile:

I update the PR. Locally I didn’t get above mentioned problem and Lasted Build also successful. :slight_smile:

Just to be sure and looking at the first test case example, this assert:

verify(attachmentsService, times(1)).getAttachments(patient, encounter, true);

It should sensitive to exact parameters. What I mean is that it should fail for another instance of Encounter for instance:

Encounter encounter2 = new Encounter();
verify(attachmentsService, times(1)).getAttachments(patient, encounter2, true);

Can you confirm this?

1 Like

Yes I tested with the different parameters and get this error .

https://pastebin.com/nqMpKHgY

So which means test cases will fail for different parameters ( Different Instances ).

1 Like

Perfect! Now to fine tune the test, on top of what you have verified, we also need to verify that no other interactions happened with AttachmentsService.

Could you look into that? You might find this useful: https://stackoverflow.com/a/45090388/321797

Hi @mksd ;

Sorry for late. I tried some solutions for this error . so I have to go for initial stage. This is the full error.

https://pastebin.com/LtvE3Bur

This error should show up in a unit test that simply attempts to autowire AttachmentsContext, could you confirm that?

1 Like