it("Properly responds to recursive edits", async () =>
with_running_app(async ({ app }) => {
await assert_throws_async(
async () => {
const happy_numbers = await app.createChip(
app.Sealious.Collection,
{
name: "happy-numbers",
fields: [
{
name: "number",
type: "int",
required: true,
},
{
name: "double_number",
type: "cached-value",
params: {
base_field_type: { name: "int" },
get_value: async (
context,
number_id
) => {
const {
number,
} = await app.run_action(
context,
[
"collections",
"happy-numbers",
number_id,
],
"show"
);
return number * 2;
},
refresh_on: [
{
event_matcher: new app.Sealious.EventMatchers.Collection(
{
when: "after",
collection_name:
"happy-numbers",
action: "create",
}
),
resource_id_getter: (
emitted_event,
resource
) => resource.id,
},
],
},
},
],
}
);
},
error =>
assert.equal(
error,
`Error: In the happy-numbers collection definition you've tried to create the double_number cached-value field that refers to the collection itself. Consider using 'derived-value' field type to avoid problems with endless recurrence.`
)
);
}));
});
function make_refresh_on(app) {
return [
{
event_matcher: new app.Sealious.EventMatchers.Collection({