Changeset View
Changeset View
Standalone View
Standalone View
lib/app/base-chips/field-types/derived-value.subtest.js
Show First 20 Lines • Show All 114 Lines • ▼ Show 20 Lines | with_running_app(async ({ app, rest_api }) => { | ||||
`${username} ${surname}`, | `${username} ${surname}`, | ||||
})(); | })(); | ||||
const person = await rest_api.post("/api/v1/collections/people", { | const person = await rest_api.post("/api/v1/collections/people", { | ||||
username: "Jan", | username: "Jan", | ||||
surname: "Kowalski", | surname: "Kowalski", | ||||
}); | }); | ||||
assert.deepEqual("Jan Kowalski", person.body.name_and_surname); | assert.deepEqual("Jan Kowalski", person.name_and_surname); | ||||
})); | })); | ||||
it("properly reacts to pre:edit handler", async () => | it("properly reacts to pre:edit handler", async () => | ||||
with_running_app(async ({ app, rest_api }) => { | with_running_app(async ({ app, rest_api }) => { | ||||
await make_test_collection(app, { | await make_test_collection(app, { | ||||
fields: ["username", "surname"], | fields: ["username", "surname"], | ||||
derived_fn: async (username, surname) => | derived_fn: async (username, surname) => | ||||
`${username} ${surname}`, | `${username} ${surname}`, | ||||
})(); | })(); | ||||
const person = await rest_api.post("/api/v1/collections/people", { | const person = await rest_api.post("/api/v1/collections/people", { | ||||
username: "Jan", | username: "Jan", | ||||
surname: "Kowalski", | surname: "Kowalski", | ||||
}); | }); | ||||
assert.deepEqual("Jan Kowalski", person.body.name_and_surname); | assert.deepEqual("Jan Kowalski", person.name_and_surname); | ||||
const updated_person = await rest_api.patch( | const updated_person = await rest_api.patch( | ||||
`/api/v1/collections/people/${person.id}`, | `/api/v1/collections/people/${person.id}`, | ||||
{ | { | ||||
username: "Janusz", | username: "Janusz", | ||||
} | } | ||||
); | ); | ||||
assert.deepEqual(updated_person.body.username, "Janusz"); | assert.deepEqual(updated_person.username, "Janusz"); | ||||
assert.deepEqual( | assert.deepEqual( | ||||
updated_person.body.name_and_surname, | updated_person.name_and_surname, | ||||
"Janusz Kowalski" | "Janusz Kowalski" | ||||
); | ); | ||||
const updated_person2 = await rest_api.patch( | const updated_person2 = await rest_api.patch( | ||||
`/api/v1/collections/people/${person.id}`, | `/api/v1/collections/people/${person.id}`, | ||||
{ | { | ||||
username: "John", | username: "John", | ||||
surname: "Doe", | surname: "Doe", | ||||
} | } | ||||
); | ); | ||||
assert.deepEqual(updated_person2.body.username, "John"); | assert.deepEqual(updated_person2.username, "John"); | ||||
assert.deepEqual(updated_person2.body.surname, "Doe"); | assert.deepEqual(updated_person2.surname, "Doe"); | ||||
assert.deepEqual(updated_person2.body.name_and_surname, "John Doe"); | assert.deepEqual(updated_person2.name_and_surname, "John Doe"); | ||||
})); | })); | ||||
it("value isn't undefined after edit on fields other than the ones conerning derived_value", async () => | it("value isn't undefined after edit on fields other than the ones conerning derived_value", async () => | ||||
with_running_app(async ({ app, rest_api }) => { | with_running_app(async ({ app, rest_api }) => { | ||||
await make_test_collection(app, { | await make_test_collection(app, { | ||||
fields: ["username", "surname"], | fields: ["username", "surname"], | ||||
derived_fn: async (username, surname) => | derived_fn: async (username, surname) => | ||||
`${username} ${surname}`, | `${username} ${surname}`, | ||||
})(); | })(); | ||||
const person = await rest_api.post("/api/v1/collections/people", { | const person = await rest_api.post("/api/v1/collections/people", { | ||||
username: "Jan", | username: "Jan", | ||||
surname: "Kowalski", | surname: "Kowalski", | ||||
age: 60, | age: 60, | ||||
}); | }); | ||||
assert.deepEqual(60, person.body.age); | assert.deepEqual(60, person.age); | ||||
const updated_person = await rest_api.patch( | const updated_person = await rest_api.patch( | ||||
`/api/v1/collections/people/${person.id}`, | `/api/v1/collections/people/${person.id}`, | ||||
{ | { | ||||
age: 22, | age: 22, | ||||
} | } | ||||
); | ); | ||||
assert.deepEqual(updated_person.body.age, 22); | assert.deepEqual(updated_person.age, 22); | ||||
assert.deepEqual( | assert.deepEqual(updated_person.name_and_surname, "Jan Kowalski"); | ||||
updated_person.body.name_and_surname, | |||||
"Jan Kowalski" | |||||
); | |||||
})); | })); | ||||
it("throws when the value returned from derived_fn is unnacceptable by target_field_type of derived-value", async () => | it("throws when the value returned from derived_fn is unnacceptable by target_field_type of derived-value", async () => | ||||
with_running_app(async ({ app, rest_api }) => { | with_running_app(async ({ app, rest_api }) => { | ||||
await make_test_collection(app, { | await make_test_collection(app, { | ||||
fields: ["username", "surname"], | fields: ["username", "surname"], | ||||
derived_fn: async (username, surname) => 555, | derived_fn: async (username, surname) => 555, | ||||
})(); | })(); | ||||
Show All 19 Lines |