Page Menu
Home
Sealhub
Search
Configure Global Search
Log In
Files
F969968
D288.id982.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
6 KB
Referenced Files
None
Subscribers
None
D288.id982.diff
View Options
diff --git a/lib/app/base-chips/field-types/cached-value.js b/lib/app/base-chips/field-types/cached-value.js
--- a/lib/app/base-chips/field-types/cached-value.js
+++ b/lib/app/base-chips/field-types/cached-value.js
@@ -143,8 +143,13 @@
),
};
},
- decode: function(context, params, { value }) {
- return this._call_base_method("decode", context, params, value);
+ decode: function(context, params, value_in_db) {
+ return this._call_base_method(
+ "decode",
+ context,
+ params,
+ value_in_db ? value_in_db.value : null
+ );
},
format: function(context, params, decoded_value, format) {
const base_field_type = app.FieldType(params.base_field_type.name);
diff --git a/lib/app/base-chips/field-types/single_reference.js b/lib/app/base-chips/field-types/single_reference.js
--- a/lib/app/base-chips/field-types/single_reference.js
+++ b/lib/app/base-chips/field-types/single_reference.js
@@ -161,7 +161,7 @@
field_name
);
filter[
- temp_field_name + ".0." + field_value_path
+ `${temp_field_name}.0.body.${field_name}`
] = field.filter_to_query(context, request_filter[field_name]);
}
return Promise.props(filter).then(function(_filter) {
diff --git a/lib/app/base-chips/field-types/single_reference.subtest.js b/lib/app/base-chips/field-types/single_reference.subtest.js
--- a/lib/app/base-chips/field-types/single_reference.subtest.js
+++ b/lib/app/base-chips/field-types/single_reference.subtest.js
@@ -3,6 +3,10 @@
const axios = require("axios");
const { create_resource_as } = locreq("test_utils");
const { with_running_app } = locreq("test_utils/with-test-app.js");
+const assert_throws_async = locreq("test_utils/assert_throws_async.js");
+const A = "/api/v1/collections/A";
+const B = "/api/v1/collections/B";
+const C = "/api/v1/collections/C";
describe("single_reference", () => {
async function create_referencing_collections(app) {
@@ -28,66 +32,129 @@
}
it("should not allow a value that is not an existing id", async () =>
- with_running_app(async ({ app, base_url }) => {
+ with_running_app(async ({ app, base_url, rest_api }) => {
await create_referencing_collections(app);
- return axios
- .post(`${base_url}/api/v1/collections/A`, {
- reference_to_b: "non-existing-id",
- })
- .then(res => {
- throw "This should not succeed";
- })
- .catch(res =>
+ await assert_throws_async(
+ () =>
+ rest_api.post(A, {
+ reference_to_b: "non-existing-id",
+ }),
+ e =>
assert.equal(
- res.response.data.data.reference_to_b.message,
+ e.response.data.data.reference_to_b.message,
"Nie masz dostępu do danego zasobu z kolekcji B lub on nie istnieje."
)
- );
+ );
}));
it("should allow a value that exists in B", async () =>
- with_running_app(async ({ app, base_url }) => {
- create_referencing_collections(app);
- const b_id = (await axios.post(`${base_url}/api/v1/collections/B`, {
- number: 1,
- })).data.id;
- return axios.post(`${base_url}/api/v1/collections/A`, {
- reference_to_b: b_id,
+ with_running_app(async ({ app, base_url, rest_api }) => {
+ await create_referencing_collections(app);
+ const { id } = await rest_api.post(B, { number: 1 });
+ await rest_api.post(A, {
+ reference_to_b: id,
});
}));
it("should not allow a value that exists in B but does not meet the filter criteria", async () =>
- with_running_app(async ({ app, base_url }) => {
- create_referencing_collections(app);
- const b_id = (await axios.post(`${base_url}/api/v1/collections/B`, {
- number: 0,
- })).data.id;
-
- return axios
- .post(`${base_url}/api/v1/collections/A`, {
- filtered_reference_to_b: b_id,
- })
- .then(response => {
- throw "This should fail";
- })
- .catch(error => {
+ with_running_app(async ({ app, base_url, rest_api }) => {
+ await create_referencing_collections(app);
+ const { id } = await rest_api.post(B, { number: 0 });
+ await assert_throws_async(
+ () =>
+ rest_api.post(A, {
+ filtered_reference_to_b: id,
+ }),
+ e =>
assert.equal(
- error.response.data.data.filtered_reference_to_b
- .message,
+ e.response.data.data.filtered_reference_to_b.message,
"Nie masz dostępu do danego zasobu z kolekcji B lub on nie istnieje."
- );
- });
+ )
+ );
}));
it("should allow a value that exists in B but does not meet the filter criteria", async () =>
- with_running_app(async ({ app, base_url }) => {
- create_referencing_collections(app);
- const b_id = (await axios.post(`${base_url}/api/v1/collections/B`, {
- number: 1,
- })).data.id;
+ with_running_app(async ({ app, base_url, rest_api }) => {
+ await create_referencing_collections(app);
+ const { id } = await rest_api.post(B, { number: 1 });
+ await rest_api.post(A, { filtered_reference_to_b: id });
+ }));
+
+ it("should be filterable by referenced collection fields", async () =>
+ with_running_app(async ({ app, base_url, rest_api }) => {
+ await create_referencing_collections(app);
- return axios.post(`${base_url}/api/v1/collections/A`, {
- filtered_reference_to_b: b_id,
+ for (let number of [1, 2, 3]) {
+ const { id } = await rest_api.post(B, { number });
+ await rest_api.post(A, { reference_to_b: id });
+ }
+
+ const response = await rest_api.get(
+ `${A}?filter[reference_to_b][number]=3&format[reference_to_b]=expand`
+ );
+ assert.deepEqual(response.length, 1);
+ assert.deepEqual(response[0].body.reference_to_b.body.number, 3);
+ }));
+
+ it("should be filterable by referenced collection field of referenced collection field", async () =>
+ with_running_app(async ({ app, base_url, rest_api }) => {
+ // A => B => C
+ await app.createChip(app.Sealious.Collection, {
+ name: "A",
+ fields: [
+ {
+ name: "reference_to_b",
+ type: "single_reference",
+ params: { collection: "B" },
+ },
+ ],
});
+ await app.createChip(app.Sealious.Collection, {
+ name: "B",
+ fields: [
+ {
+ name: "reference_to_c",
+ type: "single_reference",
+ params: { collection: "C" },
+ },
+ ],
+ });
+
+ await app.createChip(app.Sealious.Collection, {
+ name: "C",
+ fields: [
+ {
+ name: "number",
+ type: "int",
+ },
+ ],
+ });
+ let c_ids = [];
+ let b_ids = [];
+ for (let number of [1, 2, 3]) {
+ const { id } = await rest_api.post(C, { number });
+ c_ids.push(id);
+ }
+ for (let c_id of c_ids) {
+ const { id } = await rest_api.post(B, {
+ reference_to_c: c_id,
+ });
+ b_ids.push(id);
+ }
+ for (let b_id of b_ids) {
+ const a = await rest_api.post(A, { reference_to_b: b_id });
+ }
+
+ const result = await rest_api
+ .get(
+ `${A}?filter[reference_to_b][reference_to_c][number]=3&format[reference_to_b]=deep-expand:2`
+ )
+ .catch(console.error);
+
+ assert.deepEqual(result.length, 1);
+ assert.deepEqual(
+ result[0].body.reference_to_b.body.reference_to_c.body.number,
+ 3
+ );
}));
});
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Nov 23, 03:20 (12 h, 40 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
548139
Default Alt Text
D288.id982.diff (6 KB)
Attached To
Mode
D288: Fix filtering via http
Attached
Detach File
Event Timeline
Log In to Comment