summaryrefslogtreecommitdiff
path: root/addons/mail_bot/static
diff options
context:
space:
mode:
authorSébastien Theys <seb@odoo.com>2020-08-13 16:26:35 +0000
committerSébastien Theys <seb@odoo.com>2020-08-13 16:26:35 +0000
commitc2918c139b8f1026b57a257fbb74570d7a224c98 (patch)
tree6b1a5cbf5b048dd86048119cd66f5fa382595a7b /addons/mail_bot/static
parent41527531b7b6f727e25a5a68aedb49609fbb1d3a (diff)
[IMP] web, *: improve mock server and replace most mail mockRPC
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>
Diffstat (limited to 'addons/mail_bot/static')
-rw-r--r--addons/mail_bot/static/src/components/messaging_menu/messaging_menu_tests.js39
-rw-r--r--addons/mail_bot/static/src/models/messaging_initializer/messaging_initializer_tests.js19
-rw-r--r--addons/mail_bot/static/src/widgets/notification_alert/notification_alert_tests.js14
-rw-r--r--addons/mail_bot/static/tests/helpers/mock_server.js36
4 files changed, 51 insertions, 57 deletions
diff --git a/addons/mail_bot/static/src/components/messaging_menu/messaging_menu_tests.js b/addons/mail_bot/static/src/components/messaging_menu/messaging_menu_tests.js
index 7bd03053699..98cd47a8932 100644
--- a/addons/mail_bot/static/src/components/messaging_menu/messaging_menu_tests.js
+++ b/addons/mail_bot/static/src/components/messaging_menu/messaging_menu_tests.js
@@ -2,10 +2,10 @@ odoo.define('mail_bot/static/src/components/messaging_menu/messaging_menu_tests.
"use strict";
const {
- afterEach: utilsAfterEach,
+ afterEach,
afterNextRender,
- beforeEach: utilsBeforeEach,
- start: utilsStart,
+ beforeEach,
+ start,
} = require('mail/static/src/utils/test_utils.js');
QUnit.module('mail_bot', {}, function () {
@@ -13,10 +13,10 @@ QUnit.module('components', {}, function () {
QUnit.module('messaging_menu', {}, function () {
QUnit.module('messaging_menu_tests.js', {
beforeEach() {
- utilsBeforeEach(this);
+ beforeEach(this);
this.start = async params => {
- let { widget } = await utilsStart(Object.assign({}, params, {
+ let { widget } = await start(Object.assign({}, params, {
data: this.data,
hasMessagingMenu: true,
}));
@@ -24,10 +24,7 @@ QUnit.module('messaging_menu_tests.js', {
};
},
afterEach() {
- utilsAfterEach(this);
- if (this.widget) {
- this.widget.destroy();
- }
+ afterEach(this);
},
});
@@ -42,12 +39,6 @@ QUnit.test('rendering with OdooBot has a request (default)', async function (ass
},
},
},
- async mockRPC(route, args) {
- if (args.method === 'channel_fetch_preview') {
- return [];
- }
- return this._super(...arguments);
- },
});
assert.ok(
@@ -86,12 +77,6 @@ QUnit.test('rendering without OdooBot has a request (denied)', async function (a
},
},
},
- async mockRPC(route, args) {
- if (args.method === 'channel_fetch_preview') {
- return [];
- }
- return this._super(...arguments);
- },
});
assert.containsNone(
@@ -121,12 +106,6 @@ QUnit.test('rendering without OdooBot has a request (accepted)', async function
},
},
},
- async mockRPC(route, args) {
- if (args.method === 'channel_fetch_preview') {
- return [];
- }
- return this._super(...arguments);
- },
});
assert.containsNone(
@@ -160,12 +139,6 @@ QUnit.test('respond to notification prompt (denied)', async function (assert) {
},
},
},
- async mockRPC(route, args) {
- if (args.method === 'channel_fetch_preview') {
- return [];
- }
- return this._super(...arguments);
- },
});
await afterNextRender(() =>
diff --git a/addons/mail_bot/static/src/models/messaging_initializer/messaging_initializer_tests.js b/addons/mail_bot/static/src/models/messaging_initializer/messaging_initializer_tests.js
index ac54efa2a39..4121cc5a277 100644
--- a/addons/mail_bot/static/src/models/messaging_initializer/messaging_initializer_tests.js
+++ b/addons/mail_bot/static/src/models/messaging_initializer/messaging_initializer_tests.js
@@ -1,21 +1,17 @@
odoo.define('mail_bot/static/src/models/messaging_initializer/messaging_initializer_tests.js', function (require) {
"use strict";
-const {
- afterEach: utilsAfterEach,
- beforeEach: utilsBeforeEach,
- start: utilsStart,
-} = require('mail/static/src/utils/test_utils.js');
+const { afterEach, beforeEach, start } = require('mail/static/src/utils/test_utils.js');
QUnit.module('mail_bot', {}, function () {
QUnit.module('models', {}, function () {
QUnit.module('messaging_initializer', {}, function () {
QUnit.module('messaging_initializer_tests.js', {
beforeEach() {
- utilsBeforeEach(this);
+ beforeEach(this);
this.start = async params => {
- let { env, widget } = await utilsStart(Object.assign({}, params, {
+ const { env, widget } = await start(Object.assign({}, params, {
data: this.data,
}));
this.env = env;
@@ -23,16 +19,14 @@ QUnit.module('messaging_initializer_tests.js', {
};
},
afterEach() {
- if (this.widget) {
- this.widget.destroy();
- }
- this.env = undefined;
- utilsAfterEach(this);
+ afterEach(this);
},
});
QUnit.test('OdooBot initialized after 2 minutes', async function (assert) {
+ // TODO this test should be completed in combination with
+ // implementing _mockMailChannelInitOdooBot task-2300480
assert.expect(3);
await this.start({
@@ -45,7 +39,6 @@ QUnit.test('OdooBot initialized after 2 minutes', async function (assert) {
async mockRPC(route, args) {
if (args.method === 'init_odoobot') {
assert.step('init_odoobot');
- return;
}
return this._super(...arguments);
},
diff --git a/addons/mail_bot/static/src/widgets/notification_alert/notification_alert_tests.js b/addons/mail_bot/static/src/widgets/notification_alert/notification_alert_tests.js
index 1cc11dcd15c..beeeb2a8e4e 100644
--- a/addons/mail_bot/static/src/widgets/notification_alert/notification_alert_tests.js
+++ b/addons/mail_bot/static/src/widgets/notification_alert/notification_alert_tests.js
@@ -1,11 +1,7 @@
odoo.define('mail_bot/static/src/widgets/notification_alert/notification_alert_tests.js', function (require) {
'use strict';
-const {
- afterEach: utilsAfterEach,
- beforeEach: utilsBeforeEach,
- start,
-} = require('mail/static/src/utils/test_utils.js');
+const { afterEach, beforeEach, start } = require('mail/static/src/utils/test_utils.js');
const FormView = require('web.FormView');
@@ -13,7 +9,7 @@ QUnit.module('mail_bot', {}, function () {
QUnit.module('widgets', {}, function () {
QUnit.module('notification_alert_tests.js', {
beforeEach() {
- utilsBeforeEach(this);
+ beforeEach(this);
this.start = async params => {
let { widget } = await start(Object.assign({
@@ -32,11 +28,7 @@ QUnit.module('notification_alert_tests.js', {
};
},
afterEach() {
- utilsAfterEach(this);
- if (this.widget) {
- this.widget.destroy();
- this.widget = undefined;
- }
+ afterEach(this);
},
});
diff --git a/addons/mail_bot/static/tests/helpers/mock_server.js b/addons/mail_bot/static/tests/helpers/mock_server.js
new file mode 100644
index 00000000000..63de6c990ee
--- /dev/null
+++ b/addons/mail_bot/static/tests/helpers/mock_server.js
@@ -0,0 +1,36 @@
+odoo.define('mail_bot/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 === 'mail.channel' && args.method === 'init_odoobot') {
+ return this._mockMailChannelInitOdooBot();
+ }
+ return this._super(...arguments);
+ },
+
+ //--------------------------------------------------------------------------
+ // Private Mocked Methods
+ //--------------------------------------------------------------------------
+
+ /**
+ * Simulates `init_odoobot` on `mail.channel`.
+ *
+ * @private
+ */
+ _mockMailChannelInitOdooBot() {
+ // TODO implement this mock task-2300480
+ // and improve test "OdooBot initialized after 2 minutes"
+ },
+});
+
+});