it("throws when the value returned from deriving_fn is unnacceptable by target_field_type of derived-value",async()=>{
conststr=555;
awaitwithRunningApp(
extend<FieldTypes.Int>({
fields:["username","surname"],
deriving_fn:async(_:string,__:string)=>str,
}),
async({app,rest_api})=>{
awaitassertThrowsAsync(
async()=>{
awaitrest_api.post("/api/v1/collections/people",{
username:"Jan",
surname:"Kowalski",
});
},
(error)=>{
assert.deepStrictEqual(
error.response.data.data.field_messages
.name_and_surname.message,
app.i18n("invalid_text",[str,typeofstr])
);
}
);
}
);
it("should init the base field with the given app",()=>
withRunningApp(
(app_class:TestAppConstructor)=>{
returnclassextendsapp_class{
collections={
...TestApp.BaseCollections,
A:new(classextendsCollection{
fields={
simple:newFieldTypes.Text(),
derived:newFieldTypes.DerivedValue(
newFieldTypes.SingleReference("A"),
{
fields:["simple"],
deriving_fn:async(simple)=>{
return"any_id";// this isn't a proper ID, and the SingleReference should detect that by being able to access the `this.app` instance and reading the database. If any other error than "bad id" will be thrown, it means that the base field is not initiated properly