Improve mock server: - add support for mocked `fetch` - add support for `active_test` - add support for x2m `in` in domains - add support for default values computed from a function - implement a more natural "next id" compute - allow initial data without ids - ensure write and x2m commands integrity - improve bad data/bad commands error messages - always warn for failing RPC, not only in debug mode - fix all existing tests that had inconsistency data Other changes done in mail (or dependents) that are not just related to tests: - remove `direct_partner` from formatter result ->`correspondent` can be computed from other keys, especially `members` - fix `livechat_visitor` convertData -> only process if there is value - add `current_partner` and `current_user_id` as `init_messaging` result -> easier to mock than session - remove usage of `need_moderation` -> that was just a search indirection to `moderation_status` - adapt `partner_id` -> `res_partner_id` key in `_notification_format` -> to be consistent with field name - add name in result of `mail_partner_format` -> sometimes display_name is not the same - remove usage of `is_moderator` -> that was just an indirection to `moderation_channel_ids` Enterprise counterpart: https://github.com/odoo/enterprise/pull/11523 task-2287171 closes odoo/odoo#55854 X-original-commit: 7ba3fecb3377a720d1eb70e7515a0c45da73836d Related: odoo/enterprise#12391 Signed-off-by: Sébastien Theys (seb) <seb@odoo.com>
48 lines
1.8 KiB
JavaScript
48 lines
1.8 KiB
JavaScript
odoo.define('iap/static/tests/helpers/mock_server.js', function (require) {
|
|
"use strict";
|
|
|
|
const MockServer = require('web.MockServer');
|
|
|
|
MockServer.include({
|
|
//--------------------------------------------------------------------------
|
|
// Private
|
|
//--------------------------------------------------------------------------
|
|
|
|
/**
|
|
* @override
|
|
*/
|
|
async _performRpc(route, args) {
|
|
if (args.model === 'iap.account' && args.method === 'get_credits_url') {
|
|
const service_name = args.args[0] || args.kwargs.service_name;
|
|
const base_url = args.args[1] || args.kwargs.base_url;
|
|
const credit = args.args[2] !== undefined ? args.args[2] : args.kwargs.credit;
|
|
const trial = args.args[3] !== undefined ? args.args[3] : args.kwargs.trial;
|
|
return this._mockIapAccountGetCreditsUrl(service_name, base_url, credit, trial);
|
|
}
|
|
return this._super(...arguments);
|
|
},
|
|
|
|
//--------------------------------------------------------------------------
|
|
// Private Mocked Routes
|
|
//--------------------------------------------------------------------------
|
|
|
|
/**
|
|
* Simulates `get_credits_url` on `iap.account`.
|
|
*
|
|
* @private
|
|
* @param {string} service_name
|
|
* @param {string} [base_url='']
|
|
* @param {number} [credit=0]
|
|
* @param {boolean} [trial=false]
|
|
* @returns {string}
|
|
*/
|
|
_mockIapAccountGetCreditsUrl(service_name, base_url = '', credit = 0, trial = false) {
|
|
// This mock could be improved, in particular by returning an URL that
|
|
// is actually mocked here and including all params, but it is not done
|
|
// due to URL not being used in any test at the time of this comment.
|
|
return base_url + '/random/url?service_name=' + service_name;
|
|
},
|
|
});
|
|
|
|
});
|