Odoo18-Base/addons/mail/static/tests/legacy/helpers/mock_python_environment.js
2025-01-06 10:57:38 +07:00

32 lines
994 B
JavaScript

/** @odoo-module alias=@mail/../tests/helpers/mock_python_environment default=false */
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;
},
get currentGuest() {
const dgid = this.cookie.get("dgid");
if (!dgid) {
return undefined;
}
return this.mockServer.getRecords("mail.guest", [["id", "=", dgid]])[0];
},
});