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"
},
});
});
});