Files
odoo_source/addons/mail/static/tests/helpers/mock_python_environment.js
T
tsm-odoo 7131f7c626 [IMP] mail, *: add support for guests/dynamic users in tests
*: bus, calendar, im_livechat, web, website_livechat.

This PR adds the possibility to set the current user during tests as
well as the mail guest. This will be used to test mail guest page and
livechat once the visitors will be treated as guests.

part of task-3332628

closes odoo/odoo#130811

Related: odoo/enterprise#45331
Signed-off-by: Matthieu Stockbauer (tsm) <tsm@odoo.com>
2023-08-09 14:36:12 +02:00

24 lines
705 B
JavaScript

/* @odoo-module */
import { pyEnvTarget } from "@bus/../tests/helpers/mock_python_environment";
import { patch } from "@web/core/utils/patch";
patch(pyEnvTarget, {
async withGuest(guestId, fn) {
const [guest] = await this.mockServer.getRecords("mail.guest", [["id", "=", guestId]]);
const originalGuest = this.cookie.get("dgid");
if (!guest) {
throw new Error(`Guest ${guestId} not found`);
}
let result;
try {
this.cookie.set("dgid", guestId);
result = await this.withUser(this.publicUserId, fn);
} finally {
this.cookie.set("dgid", originalGuest);
}
return result;
},
});