94 lines
2.7 KiB
JavaScript
94 lines
2.7 KiB
JavaScript
import { describe, expect, it } from "vitest";
|
|
import { normalizeSessionPayload } from "@/services/sessionPayload.js";
|
|
|
|
describe("session payload normalization", () => {
|
|
it("defaults optional session fields that old cached payloads can omit", () => {
|
|
const session = normalizeSessionPayload({
|
|
id: 42,
|
|
customer_number: 10042,
|
|
email: "fleet@example.test",
|
|
});
|
|
|
|
expect(session).toMatchObject({
|
|
id: 42,
|
|
customer_number: 10042,
|
|
email: "fleet@example.test",
|
|
phone: {
|
|
number: null,
|
|
country_code: null,
|
|
},
|
|
notifications: {
|
|
wash_certificate_email: null,
|
|
email_notifications_enabled: null,
|
|
sms_notifications_enabled: null,
|
|
superuser_new_customer_email_notifications_enabled: null,
|
|
},
|
|
permissions: [],
|
|
economic_customer: null,
|
|
runtime_config: {
|
|
economic: {
|
|
transaction_draft_customer_number: null,
|
|
default_distribution_department_id: null,
|
|
},
|
|
release: {},
|
|
},
|
|
});
|
|
});
|
|
|
|
it("accepts object-shaped economic customers and release runtime config", () => {
|
|
const releaseRuntime = {
|
|
channel: { slug: "internal", name: "Intern", default_channel: false },
|
|
availability: {
|
|
configured: false,
|
|
missing: ["frontend_entry"],
|
|
status: "unconfigured",
|
|
},
|
|
};
|
|
|
|
const session = normalizeSessionPayload({
|
|
permissions: ["user"],
|
|
economic_customer: {
|
|
customerNumber: 12345,
|
|
name: "Nordic Haul",
|
|
},
|
|
runtime_config: {
|
|
economic: {
|
|
transaction_draft_customer_number: "777",
|
|
default_distribution_department_id: 12,
|
|
},
|
|
release: releaseRuntime,
|
|
},
|
|
notifications: {
|
|
superuser_new_customer_email_notifications_enabled: true,
|
|
},
|
|
});
|
|
|
|
expect(session.permissions).toEqual(["user"]);
|
|
expect(session.economic_customer).toEqual({
|
|
customerNumber: 12345,
|
|
name: "Nordic Haul",
|
|
});
|
|
expect(session.runtime_config.economic.transaction_draft_customer_number).toBe("777");
|
|
expect(session.runtime_config.economic.default_distribution_department_id).toBe(12);
|
|
expect(session.runtime_config.release).toBe(releaseRuntime);
|
|
expect(session.notifications.superuser_new_customer_email_notifications_enabled).toBe(true);
|
|
});
|
|
|
|
it("uses the first object from legacy economic customer arrays", () => {
|
|
const session = normalizeSessionPayload({
|
|
economic_customer: [
|
|
null,
|
|
{
|
|
customerNumber: 12345,
|
|
name: "Nordic Haul",
|
|
},
|
|
],
|
|
});
|
|
|
|
expect(session.economic_customer).toEqual({
|
|
customerNumber: 12345,
|
|
name: "Nordic Haul",
|
|
});
|
|
});
|
|
});
|