`Finding resources without cached value for field ${this.collection.name}.${this.name}. For this, we're looking for items from ${referenced_collection_name} and we'll be looking at them newest-to-oldest.`
`Continuing searching for resources without cached value for field ${this.collection.name}.${this.name}. Now, we find resources that are potentially outdated.`
it("throws a ts error when a required field is missing", () => {
// this test does not have to run in runitme, just creating a code structure to reflect the use case mentioned here: https://forum.sealcode.org/t/sealious-problem-z-typami/1399/3
return withRunningApp(
(t: TestAppConstructor<TestApp>) =>
class TheApp extends t {
collections = {
...App.BaseCollections,
withRequired:
new (class withRequired extends Collection {
fields = {
required: FieldTypes.Required(
new FieldTypes.Int()
),
};
})(),
};
},
async ({ app }) => {
await app.collections.withRequired.create(
new app.SuperContext(),
{ required: 2 } // try removing or renaming this property and you should get an error
it("only sets the fields that hve changed, doesn't submit the fields whose value is same as before", async () =>
withRunningApp(
(t) =>
class extends t {
collections = {
...App.BaseCollections,
patrons: new (class extends Collection {
fields = {
email: new FieldTypes.Email(),
amount_monthly: new FieldTypes.Float(),
end_date: new FieldTypes.Date(),
};
})(),
};
},
async ({ app }) => {
await app.collections.patrons.upsert(
new app.SuperContext(),
"email",
[
{
email: "adam@example.com",
amount_monthly: 3,
end_date: "2023-12-24",
},
]
);
let changes;
app.collections.patrons.on(
"before:edit",
async function ([context, item]) {
changes = await item.summarizeChanges(context);
}
);
await app.collections.patrons.upsert(
new app.SuperContext(),
"email",
[
{
email: "adam@example.com",
amount_monthly: 3,
end_date: "2023-12-24",
},
]
);
await app.collections.patrons.upsert(
new app.SuperContext(),
"email",
[
{
email: "adam@example.com",
amount_monthly: 7,
end_date: "2023-12-24",
},
]
);
assert.deepStrictEqual(changes, {
amount_monthly: { was: 3, is: 7 },
});
}
));
it("only sets the fields that hve changed, doesn't submit the fields whose value is same as before, even when they are encoded differently", async () =>
withRunningApp(
(t) =>
class extends t {
collections = {
...App.BaseCollections,
patrons: new (class extends Collection {
fields = {
email: new FieldTypes.Email(),
amount_monthly: new FieldTypes.Float(),
end_date: new FieldTypes.Date(),
};
})(),
};
},
async ({ app }) => {
await app.collections.patrons.upsert(
new app.SuperContext(),
"email",
[
{
email: "adam@example.com",
amount_monthly: 3,
end_date: "2023-12-24",
},
]
);
let changes;
app.collections.patrons.on(
"before:edit",
async function ([context, item]) {
changes = await item.summarizeChanges(context);
}
);
await app.collections.patrons.upsert(
new app.SuperContext(),
"email",
[
{
email: "adam@example.com",
amount_monthly: "3",
end_date: "2023-12-24",
},
]
);
assert.deepStrictEqual(changes, undefined);
}
));
});
describe("atom feed", () => {
it("generates a valid XML feed for a list of blog items", async () =>
values: any[], // this method gets called once for multiple resources, to limit the number of queries. Field values of all the resources are passed in this array
attachment_options: any,
format_params: any
): Promise<ItemListResult<any>> {
if (attachment_options !== undefined) {
throw new BadSubjectAction(
`Field '${this.name}' does not support attachments`
);
}
return new ItemListResult([], [], {});
}
/** Creates parts of a Mongo Pipieline that will be used to filter