[FIX] web: SampleServer: properly mock unity_web_search_read

Before this commit, many2one values were still returned as pairs
of id and display_name by unity read, whereas they should be
objects with keys id and display_name.

Part-of: odoo/odoo#133617
This commit is contained in:
Aaron Bohy
2023-08-31 09:04:58 +00:00
parent 573516e9c1
commit 660cde4298
2 changed files with 29 additions and 1 deletions
+11 -1
View File
@@ -608,9 +608,19 @@ export class SampleServer {
} else {
result = this._mockWebSearchRead({ ...params, fields });
}
// populate x2many values
// populate many2one and x2many values
for (const fieldName in params.specification) {
const field = this.data[params.model].fields[fieldName];
if (field.type === "many2one") {
for (const record of result.records) {
record[fieldName] = record[fieldName]
? {
id: record[fieldName][0],
display_name: record[fieldName][1],
}
: false;
}
}
if (field.type === "one2many" || field.type === "many2many") {
const relFields = Object.keys(params.specification[fieldName].fields || {});
if (relFields.length) {
@@ -261,6 +261,24 @@ QUnit.module(
);
});
QUnit.test("Send 'search_read' RPC: many2one fields", async function (assert) {
const server = new DeterministicSampleServer("res.users", fields["res.users"]);
const result = await server.mockRpc({
method: "unity_web_search_read",
model: "res.users",
specification: {
manager_id: {
fields: { display_name: {} },
},
},
});
assert.deepEqual(Object.keys(result.records[0]), ["id", "manager_id"]);
assert.ok(result.records[0].manager_id.id);
assert.ok(/\w+/.test(result.records[0].manager_id.display_name));
});
QUnit.test("Send 'web_read_group' RPC: no group", async function (assert) {
assert.expect(1);