An RPC call using an empty array of fields has not the same behavior on the MockServer and the actual server: - the MockServer returns only the 'id' field - the actual server returns all the fields for the model This is due to the fact that an empty array evaluates to a falsy value in Python and evaluates to a thruthy value in JavaScript. This commit restores the parity between the two. closes odoo/odoo#36278 Signed-off-by: Aaron Bohy (aab) <aab@odoo.com>
56 lines
1.8 KiB
JavaScript
56 lines
1.8 KiB
JavaScript
odoo.define('web.mockserver_tests', function (require) {
|
|
"use strict";
|
|
|
|
const MockServer = require("web.MockServer");
|
|
|
|
QUnit.module("MockServer", {
|
|
beforeEach() {
|
|
this.data = {
|
|
"res.partner": {
|
|
fields: {
|
|
name: {
|
|
string: "Name",
|
|
type: "string",
|
|
},
|
|
email: {
|
|
string: "Email",
|
|
type: "string",
|
|
},
|
|
},
|
|
records: [{ id: 1, name: "Jean-Michel", email: "jean.michel@example.com" }],
|
|
},
|
|
};
|
|
},
|
|
}, function () {
|
|
QUnit.test("performRpc: search_read with an empty array of fields", async function (assert) {
|
|
assert.expect(1);
|
|
const server = new MockServer(this.data, {});
|
|
const result = await server.performRpc("", {
|
|
model: "res.partner",
|
|
method: "search_read",
|
|
args: [],
|
|
kwargs: {
|
|
fields: [],
|
|
},
|
|
});
|
|
const expectedFields = ["id", "email", "name", "display_name"];
|
|
assert.strictEqual(_.difference(expectedFields, Object.keys(result[0])).length, 0,
|
|
"should contains all the fields");
|
|
});
|
|
|
|
QUnit.test("performRpc: search_read without fields", async function (assert) {
|
|
assert.expect(1);
|
|
const server = new MockServer(this.data, {});
|
|
const result = await server.performRpc("", {
|
|
model: "res.partner",
|
|
method: "search_read",
|
|
args: [],
|
|
kwargs: {},
|
|
});
|
|
const expectedFields = ["id", "email", "name", "display_name"];
|
|
assert.strictEqual(_.difference(expectedFields, Object.keys(result[0])).length, 0,
|
|
"should contains all the fields");
|
|
});
|
|
});
|
|
});
|