Unit Testing Search Stubs

I’m currently in the process of refactoring our unit tests. For one particular service, we used Jest to stub all of our search, filter, and aggregation. I came across this page which details how to stub searches.

The problem is, this doesn’t really seem any different from using the Jest.mockImplementation() for a search because you’re still returning a pre-canned answer for your entire query. I’d love to be able to do an Object.create() for stub objects and then verify that my query for those objects is behaving as I was expecting. For example:

const obj1 = Objects.create().myObj('obj1');
obj1.timestamp = Time.now();

const obj2 = Object.create().myObj('obj2');
obj2.timestamp = Timestamp.now().minusDays(1);

// this function would search ontology, order by timestamp in descending order, then take the top result.
expect(await myService.getMostRecentObj()).toEqual(obj1);

If anyone has any suggestions on how to stub this without stubbing the entire query that would be super helpful!

2 Likes

Totally, this is a request that’s already been made previously and there’s a few of us hoping for this functionality.

@smith any update please?

CC @haru

1 Like

@jmazen cc: @green
I was able to resolve this issue thanks to an unofficial library provided by @smith. I highly recommend contacting @smith for assistance.

2 Likes

Hey @green, thanks for the ping on this! Unfortunately there haven’t been any updates the past few months. I’m still hopeful the testing infrastructure of new OSDK backed functions will include some kind of solution for emulating the behavior of the ontology.

1 Like

Thanks @smith , I’d be very interested in the unofficial library that @haru mentioned, it would give our team a huge bump in test capabilities if you’re willing to share it :slight_smile:

1 Like