mail/static/tests/helpers/mock_python_environment.js
Данил Воробьев 6e6f15d803 initial commit
2024-05-03 09:40:35 +00: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;
},
});