Testing Object Search Logic in Palantir Foundry without Pre-defining Results

I want to write unit tests for a function that searches for and modifies objects. I’m trying to avoid the approach documented here: https://www.palantir.com/docs/foundry/functions/unit-test-object-searches because I want to test the accuracy of the object search criteria without pre-defining the returned objects as key-value pairs.

Is it possible to, for example, pre-define multiple objects as potential search results and then have the test verify that only the objects matching the search criteria are returned and modified?

Here’s my code:

export class FooBarClass {
    async myObjectEditFunction(rangeNum: number): Promise<void> {
        let result = await Objects.search()
            .FooBarObjectType()
            .filter(e => Filters.and(
                // ... other filters ...
                e.FooBarProperty.range().gte(rangeNum),
                // ... other filters ...
            )).allAsync();

        result.forEach(obj => {
            obj.testTargetProperty = "editedValue";
        });
    };
}

And my current (non-working) test:

describe("test: myObjectEditFunction", () => {
    const fooBar = new FooBarClass();

    test("00X", async () => {
        // Is there a way to pre-define the pool of objects for the search without using the key-value pair method?
        // This is just an example and doesn't work.
        let obj00 = Objects.create().FooBarObjectType("00");
        let obj01 = Objects.create().FooBarObjectType("01");
        let obj02 = Objects.create().FooBarObjectType("02");
        let obj03 = Objects.create().FooBarObjectType("03");

        (await verifyOntologyEditFunction(() => fooBar.myObjectEditFunction(2)))
            .modifiesObject({
                object: obj02,
                properties: {
                    testTargetProperty: "editedValue"
                },
            },{
                object: obj03,
                properties: {
                    testTargetProperty: "editedValue"
                },
            });
    });
});
1 Like

:100:

I’d also really like to see this feature so you can validate the object filter criteria used in a function along with the other steps.

1 Like

Could the release of the emulator mentioned here solve this?

1 Like

Hi @haru, this work is still ongoing but I’ve shifted focus to a solution for OSDK backed functions (which have rolled out for Python and are in the process of rolling out for TypeScript).

We’re still figuring out internally how the testing infrastructure will work for these new OSDK backed functions but I’m hopeful it will include some kind of solution for actually emulating the behavior of the ontology. In the meantime, if you do want to use the existing solution, I can always send you an email with more details or you can reach out to your palantir representative.

Thanks for the update, Smith. I’d like to use the existing solution if possible. Could you please email me the details?