[REF] mail, im_livechat: move /mail/chat_post to im_livechat

It is only used there.

In preparation of splitting discuss and mail modules.

Part of task-3265211

closes odoo/odoo#119306

Signed-off-by: Sébastien Theys (seb) <seb@odoo.com>
This commit is contained in:
Sébastien Theys
2023-04-24 18:25:59 +02:00
parent 9b11360c9b
commit 694d501a35
15 changed files with 173 additions and 202 deletions
+24
View File
@@ -212,6 +212,30 @@ class LivechatController(http.Controller):
if discuss_channel:
discuss_channel._close_livechat_session()
@http.route('/im_livechat/chat_post', type="json", auth="public", cors="*")
def im_livechat_chat_post(self, uuid, message_content):
channel = request.env["discuss.channel"].sudo().search([('uuid', '=', uuid)], limit=1)
if not channel:
return False
# find the author from the user session
if request.session.uid:
author = request.env['res.users'].sudo().browse(request.session.uid).partner_id
author_id = author.id
email_from = author.email_formatted
else: # If Public User, use catchall email from company
author_id = False
email_from = channel.anonymous_name or channel.create_uid.company_id.catchall_formatted
# post a message without adding followers to the channel. email_from=False avoid to get author from email data
body = tools.plaintext2html(message_content)
message = channel.with_context(mail_create_nosubscribe=True).message_post(
author_id=author_id,
email_from=email_from,
body=body,
message_type='comment',
subtype_xmlid='mail.mt_comment'
)
return message.id if message else False
@http.route(['/im_livechat/chat_history'], type="json", auth="public", cors="*")
def im_livechat_chat_history(self, uuid, last_id=False, limit=20):
channel = request.env["discuss.channel"].sudo().search([('uuid', '=', uuid)], limit=1)
@@ -308,7 +308,7 @@ Model({
typing: false,
});
const messageId = await this.messaging.rpc({
route: "/mail/chat_post",
route: "/im_livechat/chat_post",
params: {
uuid: this.messaging.publicLivechatGlobal.publicLivechat.uuid,
message_content: message.content,
@@ -89,7 +89,7 @@ QUnit.test("add livechat in the sidebar on visitor sending first message", async
// simulate livechat visitor sending a message
const [channel] = pyEnv["discuss.channel"].searchRead([["id", "=", channelId]]);
await afterNextRender(async () =>
env.services.rpc("/mail/chat_post", {
env.services.rpc("/im_livechat/chat_post", {
context: { mockedUserId: false },
uuid: channel.uuid,
message_content: "new message",
@@ -26,6 +26,12 @@ patch(MockServer.prototype, "im_livechat/controllers/main", {
const context = args.context;
return this._mockRouteImLivechatNotifyTyping(uuid, is_typing, context);
}
if (route === "/im_livechat/chat_post") {
const uuid = args.uuid;
const message_content = args.message_content;
const context = args.context;
return this._mockRouteImLivechatChatPost(uuid, message_content, context);
}
return this._super(...arguments);
},
/**
@@ -85,4 +91,53 @@ patch(MockServer.prototype, "im_livechat/controllers/main", {
]);
this._mockDiscussChannelMember_NotifyTyping([memberOfCurrentUser.id], is_typing);
},
/**
* Simulates the `/im_livechat/chat_post` route.
*
* @private
* @param {string} uuid
* @param {string} message_content
* @param {Object} [context={}]
* @returns {Object} one key for list of followers and one for subtypes
*/
async _mockRouteImLivechatChatPost(uuid, message_content, context = {}) {
const channel = this.getRecords("discuss.channel", [["uuid", "=", uuid]])[0];
if (!channel) {
return false;
}
let user_id;
// find the author from the user session
if ("mockedUserId" in context) {
// can be falsy to simulate not being logged in
user_id = context.mockedUserId;
} else {
user_id = this.currentUserId;
}
let author_id;
let email_from;
if (user_id) {
const author = this.getRecords("res.users", [["id", "=", user_id]])[0];
author_id = author.partner_id;
email_from = `${author.display_name} <${author.email}>`;
} else {
author_id = false;
// simpler fallback than catchall_formatted
email_from = channel.anonymous_name || "catchall@example.com";
}
// supposedly should convert plain text to html
const body = message_content;
// ideally should be posted with mail_create_nosubscribe=True
return this._mockDiscussChannelMessagePost(
channel.id,
{
author_id,
email_from,
body,
message_type: "comment",
subtype_xmlid: "mail.mt_comment",
},
context
);
},
});
@@ -29,7 +29,7 @@ QUnit.test("Notify message received out of focus", async (assert) => {
}),
},
});
await env.services.rpc("/mail/chat_post", {
await env.services.rpc("/im_livechat/chat_post", {
context: { mockedUserId: senderId },
message_content: "Hello",
uuid: channel.uuid,
@@ -466,7 +466,7 @@ QUnit.test("Message unread counter", async (assert) => {
const { env, openDiscuss } = await start();
await openDiscuss();
await afterNextRender(async () =>
env.services.rpc("/mail/chat_post", {
env.services.rpc("/im_livechat/chat_post", {
context: { mockedUserId: userId },
message_content: "hu",
uuid: pyEnv["discuss.channel"].searchRead([["id", "=", channelId]])[0].uuid,
-1
View File
@@ -1,6 +1,5 @@
# -*- coding: utf-8 -*
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from . import bus
from . import discuss
from . import mail
-37
View File
@@ -1,37 +0,0 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import SUPERUSER_ID, tools
from odoo.http import request, route
from odoo.addons.bus.controllers.main import BusController
class MailChatController(BusController):
# --------------------------
# Anonymous routes (Common Methods)
# --------------------------
@route('/mail/chat_post', type="json", auth="public", cors="*")
def mail_chat_post(self, uuid, message_content, **kwargs):
channel = request.env["discuss.channel"].sudo().search([('uuid', '=', uuid)], limit=1)
if not channel:
return False
# find the author from the user session
if request.session.uid:
author = request.env['res.users'].sudo().browse(request.session.uid).partner_id
author_id = author.id
email_from = author.email_formatted
else: # If Public User, use catchall email from company
author_id = False
email_from = channel.anonymous_name or channel.create_uid.company_id.catchall_formatted
# post a message without adding followers to the channel. email_from=False avoid to get author from email data
body = tools.plaintext2html(message_content)
message = channel.with_context(mail_create_nosubscribe=True).message_post(
author_id=author_id,
email_from=email_from,
body=body,
message_type='comment',
subtype_xmlid='mail.mt_comment'
)
return message.id if message else False
@@ -27,7 +27,7 @@ patch(Messaging.prototype, "mail/web", {
async _handleNotificationNewMessage(notif) {
await this._super(notif);
const channel = this.store.threads[createLocalId("discuss.channel", notif.payload.id)];
if (channel.correspondent !== this.store.odoobot) {
if (!this.store.isSmall && channel.correspondent !== this.store.odoobot) {
this.chatWindowService.insert({ thread: channel });
}
},
@@ -29,25 +29,22 @@ QUnit.test(
const pyEnv = await startServer();
const partnerId = pyEnv["res.partner"].create({ name: "Demo" });
const userId = pyEnv["res.users"].create({ partner_id: partnerId });
pyEnv["discuss.channel"].records = [
{
channel_member_ids: [
[0, 0, { partner_id: pyEnv.currentPartnerId }],
[0, 0, { partner_id: partnerId }],
],
channel_type: "chat",
id: partnerId,
uuid: "channel-10-uuid",
},
];
const channelId = pyEnv["discuss.channel"].create({
channel_member_ids: [
[0, 0, { partner_id: pyEnv.currentPartnerId }],
[0, 0, { partner_id: partnerId }],
],
channel_type: "chat",
});
patchUiSize({ size: SIZES.SM });
const { env } = await start();
// simulate receiving a message
env.services.rpc("/mail/chat_post", {
env.services.rpc("/mail/message/post", {
context: { mockedUserId: userId },
message_content: "hu",
uuid: "channel-10-uuid",
post_data: { body: "hu", message_type: "comment" },
thread_id: channelId,
thread_model: "discuss.channel",
});
await nextAnimationFrame();
assert.containsNone($, ".o-mail-ChatWindow");
@@ -568,7 +565,6 @@ QUnit.test(
[0, 0, { partner_id: partnerId }],
],
channel_type: "chat",
uuid: "channel-10-uuid",
});
const messageId = pyEnv["mail.message"].create({
body: "not empty",
@@ -583,10 +579,11 @@ QUnit.test(
const { env } = await start();
// simulate receiving a message
await afterNextRender(async () =>
env.services.rpc("/mail/chat_post", {
env.services.rpc("/mail/message/post", {
context: { mockedUserId: userId },
message_content: "hu",
uuid: "channel-10-uuid",
post_data: { body: "hu", message_type: "comment" },
thread_id: channelId,
thread_model: "discuss.channel",
})
);
assert.containsOnce($, ".o-mail-ChatWindow");
@@ -604,21 +601,21 @@ QUnit.test(
name: "Foreigner user",
partner_id: partnerId,
});
pyEnv["discuss.channel"].create({
const channelId = pyEnv["discuss.channel"].create({
channel_member_ids: [
[0, 0, { partner_id: pyEnv.currentPartnerId }],
[0, 0, { partner_id: partnerId }],
],
channel_type: "chat",
uuid: "channel-10-uuid",
});
const { env } = await start();
// simulate receiving a message
await afterNextRender(async () =>
env.services.rpc("/mail/chat_post", {
env.services.rpc("/mail/message/post", {
context: { mockedUserId: userId },
message_content: "hu",
uuid: "channel-10-uuid",
post_data: { body: "hu", message_type: "comment" },
thread_id: channelId,
thread_model: "discuss.channel",
})
);
assert.containsOnce($, "hr + span:contains(New messages)");
@@ -629,23 +626,23 @@ QUnit.test("chat window should open when receiving a new DM", async (assert) =>
const pyEnv = await startServer();
const partnerId = pyEnv["res.partner"].create({});
const userId = pyEnv["res.users"].create({ partner_id: partnerId });
pyEnv["discuss.channel"].create({
const channelId = pyEnv["discuss.channel"].create({
channel_member_ids: [
[0, 0, { is_pinned: false, partner_id: pyEnv.currentPartnerId }],
[0, 0, { partner_id: partnerId }],
],
channel_type: "chat",
uuid: "channel-uuid",
});
const { env } = await start();
// simulate receiving the first message on chat
await afterNextRender(() =>
env.services.rpc("/mail/chat_post", {
env.services.rpc("/mail/message/post", {
context: {
mockedUserId: userId,
},
message_content: "new message",
uuid: "channel-uuid",
post_data: { body: "new message", message_type: "comment" },
thread_id: channelId,
thread_model: "discuss.channel",
})
);
assert.containsOnce($, ".o-mail-ChatWindow");
@@ -654,21 +651,21 @@ QUnit.test("chat window should open when receiving a new DM", async (assert) =>
QUnit.test("chat window should not open when receiving a new DM from odoobot", async (assert) => {
const pyEnv = await startServer();
const userId = pyEnv["res.users"].create({ partner_id: pyEnv.odoobotId });
pyEnv["discuss.channel"].create({
const channelId = pyEnv["discuss.channel"].create({
channel_member_ids: [
[0, 0, { is_pinned: false, partner_id: pyEnv.currentPartnerId }],
[0, 0, { partner_id: pyEnv.odoobotId }],
],
channel_type: "chat",
uuid: "channel-uuid",
});
const { env } = await start();
// simulate receiving new message from odoobot
await afterNextRender(() =>
env.services.rpc("/mail/chat_post", {
env.services.rpc("/mail/message/post", {
context: { mockedUserId: userId },
message_content: "new message",
uuid: "channel-uuid",
post_data: { body: "new message", message_type: "comment" },
thread_id: channelId,
thread_model: "discuss.channel",
})
);
assert.containsNone($, ".o-mail-ChatWindow");
@@ -712,7 +709,7 @@ QUnit.test("chat window should remain folded when new message is received", asyn
name: "Foreigner user",
partner_id: partnerId,
});
pyEnv["discuss.channel"].create({
const channelId = pyEnv["discuss.channel"].create({
channel_member_ids: [
[
0,
@@ -726,15 +723,15 @@ QUnit.test("chat window should remain folded when new message is received", asyn
[0, 0, { partner_id: partnerId }],
],
channel_type: "chat",
uuid: "channel-uuid",
});
const { env } = await start();
assert.hasClass($(".o-mail-ChatWindow"), "o-folded");
env.services.rpc("/mail/chat_post", {
env.services.rpc("/mail/message/post", {
context: { mockedUserId: userId },
message_content: "New Message",
uuid: "channel-uuid",
post_data: { body: "New Message", message_type: "comment" },
thread_id: channelId,
thread_model: "discuss.channel",
});
await nextTick();
assert.hasClass($(".o-mail-ChatWindow"), "o-folded");
@@ -839,7 +836,6 @@ QUnit.test(
[0, 0, { partner_id: partnerId }],
],
channel_type: "chat",
uuid: "channel-10-uuid",
});
const messageId = pyEnv["mail.message"].create([
{
@@ -857,10 +853,11 @@ QUnit.test(
$(".o-mail-Composer-input")[0].blur();
// simulate receiving a message
await afterNextRender(() =>
env.services.rpc("/mail/chat_post", {
env.services.rpc("/mail/message/post", {
context: { mockedUserId: userId },
message_content: "hu",
uuid: "channel-10-uuid",
post_data: { body: "hu", message_type: "comment" },
thread_id: channelId,
thread_model: "discuss.channel",
})
);
assert.containsOnce($, "hr + span:contains(New messages)");
@@ -1166,13 +1166,12 @@ QUnit.test("should auto-pin chat when receiving a new DM", async (assert) => {
const pyEnv = await startServer();
const partnerId = pyEnv["res.partner"].create({ name: "Demo" });
const userId = pyEnv["res.users"].create({ partner_id: partnerId });
pyEnv["discuss.channel"].create({
const channelId = pyEnv["discuss.channel"].create({
channel_member_ids: [
[0, 0, { is_pinned: false, partner_id: pyEnv.currentPartnerId }],
[0, 0, { partner_id: partnerId }],
],
channel_type: "chat",
uuid: "channel11uuid",
});
const { env, openDiscuss } = await start();
await openDiscuss();
@@ -1180,10 +1179,11 @@ QUnit.test("should auto-pin chat when receiving a new DM", async (assert) => {
// simulate receiving the first message on channel 11
await afterNextRender(() =>
env.services.rpc("/mail/chat_post", {
env.services.rpc("/mail/message/post", {
context: { mockedUserId: userId },
message_content: "new message",
uuid: "channel11uuid",
post_data: { body: "new message", message_type: "comment" },
thread_id: channelId,
thread_model: "discuss.channel",
})
);
assert.containsOnce($, ".o-mail-DiscussCategoryItem:contains(Demo)");
@@ -1565,7 +1565,7 @@ QUnit.test("new messages separator [REQUIRE FOCUS]", async (assert) => {
name: "Foreigner user",
partner_id: partnerId,
});
const channelId = pyEnv["discuss.channel"].create({ name: "test", uuid: "randomuuid" });
const channelId = pyEnv["discuss.channel"].create({ name: "test" });
let lastMessageId;
for (let i = 1; i <= 25; i++) {
lastMessageId = pyEnv["mail.message"].create({
@@ -1589,10 +1589,11 @@ QUnit.test("new messages separator [REQUIRE FOCUS]", async (assert) => {
$(".o-mail-Composer-input")[0].blur();
// simulate receiving a message
await afterNextRender(async () =>
env.services.rpc("/mail/chat_post", {
env.services.rpc("/mail/message/post", {
context: { mockedUserId: userId },
message_content: "hu",
uuid: "randomuuid",
post_data: { body: "hu", message_type: "comment" },
thread_id: channelId,
thread_model: "discuss.channel",
})
);
assert.containsN($, ".o-mail-Message", 26);
@@ -1894,13 +1895,13 @@ QUnit.test("Message shows up even if channel data is incomplete", async (assert)
is_typing: true,
channel_id: channelId,
});
const [channel] = pyEnv["discuss.channel"].searchRead([["id", "=", channelId]]);
await afterNextRender(
async () =>
await env.services.rpc("/mail/chat_post", {
await env.services.rpc("/mail/message/post", {
context: { mockedUserId: correspondentUserId },
message_content: "hello world",
uuid: channel.uuid,
post_data: { body: "hello world", message_type: "comment" },
thread_id: channelId,
thread_model: "discuss.channel",
})
);
await click(".o-mail-DiscussCategory-chat + .o-mail-DiscussCategoryItem:contains(Albert)");
@@ -1,68 +0,0 @@
/** @odoo-module **/
import { patch } from "@web/core/utils/patch";
import { MockServer } from "@web/../tests/helpers/mock_server";
patch(MockServer.prototype, "mail/controllers/bus", {
/**
* @override
*/
async _performRPC(route, args) {
if (route === "/mail/chat_post") {
const uuid = args.uuid;
const message_content = args.message_content;
const context = args.context;
return this._mockRouteMailChatPost(uuid, message_content, context);
}
return this._super(route, args);
},
/**
* Simulates the `/mail/chat_post` route.
*
* @private
* @param {string} uuid
* @param {string} message_content
* @param {Object} [context={}]
* @returns {Object} one key for list of followers and one for subtypes
*/
async _mockRouteMailChatPost(uuid, message_content, context = {}) {
const channel = this.getRecords("discuss.channel", [["uuid", "=", uuid]])[0];
if (!channel) {
return false;
}
let user_id;
// find the author from the user session
if ("mockedUserId" in context) {
// can be falsy to simulate not being logged in
user_id = context.mockedUserId;
} else {
user_id = this.currentUserId;
}
let author_id;
let email_from;
if (user_id) {
const author = this.getRecords("res.users", [["id", "=", user_id]])[0];
author_id = author.partner_id;
email_from = `${author.display_name} <${author.email}>`;
} else {
author_id = false;
// simpler fallback than catchall_formatted
email_from = channel.anonymous_name || "catchall@example.com";
}
// supposedly should convert plain text to html
const body = message_content;
// ideally should be posted with mail_create_nosubscribe=True
return this._mockDiscussChannelMessagePost(
channel.id,
{
author_id,
email_from,
body,
message_type: "comment",
subtype_xmlid: "mail.mt_comment",
},
context
);
},
});
@@ -17,12 +17,12 @@ QUnit.test(
],
channel_type: "chat",
});
const [channel] = pyEnv["discuss.channel"].searchRead([["id", "=", channelId]]);
await afterNextRender(() =>
env.services.rpc("/mail/chat_post", {
env.services.rpc("/mail/message/post", {
context: { mockedUserId: userId },
message_content: "new message",
uuid: channel.uuid,
post_data: { body: "new message", message_type: "comment" },
thread_id: channelId,
thread_model: "discuss.channel",
})
);
assert.containsOnce($, ".o-mail-ChatWindow-header:contains(Dumbledore)");
@@ -43,11 +43,11 @@ QUnit.test(
],
channel_type: "chat",
});
const [channel] = pyEnv["discuss.channel"].searchRead([["id", "=", channelId]]);
env.services.rpc("/mail/chat_post", {
env.services.rpc("/mail/message/post", {
context: { mockedUserId: userId },
message_content: "new message",
uuid: channel.uuid,
post_data: { body: "new message", message_type: "comment" },
thread_id: channelId,
thread_model: "discuss.channel",
});
// leaving discuss.
await openFormView("res.partner", partnerId);
+27 -27
View File
@@ -239,7 +239,6 @@ QUnit.test(
const userId = pyEnv["res.users"].create({ partner_id: partnerId });
const channelId = pyEnv["discuss.channel"].create({
name: "test",
uuid: "uuid-uuid",
channel_member_ids: [
[0, 0, { partner_id: pyEnv.currentPartnerId }],
[0, 0, { partner_id: partnerId }],
@@ -260,10 +259,11 @@ QUnit.test(
});
await click(".o_menu_systray i[aria-label='Messages']");
await afterNextRender(async () =>
env.services.rpc("/mail/chat_post", {
env.services.rpc("/mail/message/post", {
context: { mockedUserId: userId },
message_content: "new message",
uuid: "uuid-uuid",
post_data: { body: "new message", message_type: "comment" },
thread_id: channelId,
thread_model: "discuss.channel",
})
);
assert.verifySteps(["rpc:channel_fetch"]);
@@ -280,10 +280,7 @@ QUnit.test(
const pyEnv = await startServer();
const partnerId = pyEnv["res.partner"].create({});
const userId = pyEnv["res.users"].create({ partner_id: partnerId });
const channelId = pyEnv["discuss.channel"].create({
name: "test",
uuid: "uuid-uuid",
});
const channelId = pyEnv["discuss.channel"].create({ name: "test" });
const deferred = makeDeferred();
const { env, openDiscuss } = await start({
async mockRPC(route, args) {
@@ -301,10 +298,11 @@ QUnit.test(
await openDiscuss(channelId);
$(".o-mail-Composer-input")[0].focus();
// simulate receiving a message
await env.services.rpc("/mail/chat_post", {
await env.services.rpc("/mail/message/post", {
context: { mockedUserId: userId },
message_content: "<p>Some new message</p>",
uuid: "uuid-uuid",
post_data: { body: "<p>Some new message</p>", message_type: "comment" },
thread_id: channelId,
thread_model: "discuss.channel",
});
await afterNextRender(() => deferred.resolve());
assert.verifySteps(["rpc:set_last_seen_message"]);
@@ -317,7 +315,7 @@ QUnit.test(
const pyEnv = await startServer();
const partnerId = pyEnv["res.partner"].create({ name: "Foreigner partner" });
const userId = pyEnv["res.users"].create({ name: "Foreigner user", partner_id: partnerId });
const channelId = pyEnv["discuss.channel"].create({ uuid: "channel-uuid" });
const channelId = pyEnv["discuss.channel"].create({});
for (let i = 0; i <= 10; i++) {
pyEnv["mail.message"].create({
body: "not empty",
@@ -332,10 +330,11 @@ QUnit.test(
// simulate receiving a message
await afterNextRender(() =>
env.services.rpc("/mail/chat_post", {
env.services.rpc("/mail/message/post", {
context: { mockedUserId: userId },
message_content: "hello",
uuid: "channel-uuid",
post_data: { body: "hello", message_type: "comment" },
thread_id: channelId,
thread_model: "discuss.channel",
})
);
assert.ok(isScrolledToBottom($(".o-mail-Thread")[0]));
@@ -348,7 +347,7 @@ QUnit.test(
const pyEnv = await startServer();
const partnerId = pyEnv["res.partner"].create({ name: "Foreigner partner" });
const userId = pyEnv["res.users"].create({ name: "Foreigner user", partner_id: partnerId });
const channelId = pyEnv["discuss.channel"].create({ uuid: "channel-uuid" });
const channelId = pyEnv["discuss.channel"].create({});
for (let i = 0; i <= 10; i++) {
pyEnv["mail.message"].create({
body: "not empty",
@@ -367,10 +366,11 @@ QUnit.test(
// simulate receiving a message
await afterNextRender(() =>
env.services.rpc("/mail/chat_post", {
env.services.rpc("/mail/message/post", {
context: { mockedUserId: userId },
message_content: "hello",
uuid: "channel-uuid",
post_data: { body: "hello", message_type: "comment" },
thread_id: channelId,
thread_model: "discuss.channel",
})
);
assert.strictEqual($(".o-mail-Thread")[0].scrollTop, 0);
@@ -474,7 +474,6 @@ QUnit.test("new messages separator on receiving new message [REQUIRE FOCUS]", as
],
channel_type: "channel",
name: "General",
uuid: "randomuuid",
});
const messageId = pyEnv["mail.message"].create({
body: "blah",
@@ -494,10 +493,11 @@ QUnit.test("new messages separator on receiving new message [REQUIRE FOCUS]", as
$(".o-mail-Composer-input")[0].blur();
// simulate receiving a message
await afterNextRender(() =>
env.services.rpc("/mail/chat_post", {
env.services.rpc("/mail/message/post", {
context: { mockedUserId: userId },
message_content: "hu",
uuid: "randomuuid",
post_data: { body: "hu", message_type: "comment" },
thread_id: channelId,
thread_model: "discuss.channel",
})
);
assert.containsN($, ".o-mail-Message", 2);
@@ -731,7 +731,6 @@ QUnit.test(
const channelId = pyEnv["discuss.channel"].create({
channel_type: "channel",
name: "General",
uuid: "channel20uuid",
});
pyEnv["mail.message"].create([
{
@@ -749,10 +748,11 @@ QUnit.test(
$(".o-mail-Composer-input")[0].blur();
// simulate receiving a message
await afterNextRender(() =>
env.services.rpc("/mail/chat_post", {
env.services.rpc("/mail/message/post", {
context: { mockedUserId: userId },
message_content: "test",
uuid: "channel20uuid",
post_data: { body: "test", message_type: "comment" },
thread_id: channelId,
thread_model: "discuss.channel",
})
);
assert.containsN($, ".o-mail-Message", 3);
+1 -1
View File
@@ -73,7 +73,7 @@ class TestLivechatCommon(tests.TransactionCase):
self.patch(type(self.env['website.visitor']), '_get_visitor_from_request', get_visitor_from_request)
def _send_message(self, channel, email_from, body, author_id=False):
# As bus is unavailable in test mode, we cannot call /mail/chat_post route to post a message.
# As bus is unavailable in test mode, we cannot call /im_livechat/chat_post route to post a message.
# Instead, we post directly the message on the given channel.
channel.with_context(mail_create_nosubscribe=True) \
.message_post(author_id=author_id, email_from=email_from, body=body,