@yoryoboy/bi-mcp 1.13.0 → 1.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/.tsbuildinfo +1 -1
- package/dist/index.js +30 -0
- package/dist/index.js.map +2 -2
- package/dist/mcp-use.json +2 -2
- package/dist/src/services/vtex/__tests__/vtex-payments.test.js +95 -0
- package/dist/src/services/vtex/__tests__/vtex-payments.test.js.map +7 -0
- package/dist/src/services/vtex/vtex-payments-write.js +64 -0
- package/dist/src/services/vtex/vtex-payments-write.js.map +7 -0
- package/dist/src/services/vtex/vtex-payments.js +43 -0
- package/dist/src/services/vtex/vtex-payments.js.map +7 -0
- package/dist/src/tools/vtex/__tests__/commercial-condition-references.test.js +14 -0
- package/dist/src/tools/vtex/__tests__/commercial-condition-references.test.js.map +7 -0
- package/dist/src/tools/vtex/__tests__/commercial-conditions.test.js +276 -0
- package/dist/src/tools/vtex/__tests__/commercial-conditions.test.js.map +7 -0
- package/dist/src/tools/vtex/__tests__/payment-rules.test.js +253 -0
- package/dist/src/tools/vtex/__tests__/payment-rules.test.js.map +7 -0
- package/dist/src/tools/vtex/catalog-admin-products-skus.js +3 -1
- package/dist/src/tools/vtex/catalog-admin-products-skus.js.map +2 -2
- package/dist/src/tools/vtex/commercial-conditions.js +220 -0
- package/dist/src/tools/vtex/commercial-conditions.js.map +7 -0
- package/dist/src/tools/vtex/create-sku.js +3 -1
- package/dist/src/tools/vtex/create-sku.js.map +2 -2
- package/dist/src/tools/vtex/index.js +2 -0
- package/dist/src/tools/vtex/index.js.map +2 -2
- package/dist/src/tools/vtex/payment-rules.js +229 -0
- package/dist/src/tools/vtex/payment-rules.js.map +7 -0
- package/dist/tests/vtex/vtex-commercial-conditions-docs.test.js +26 -0
- package/dist/tests/vtex/vtex-commercial-conditions-docs.test.js.map +7 -0
- package/dist/tests/vtex/vtex-commercial-conditions-surface.test.js +42 -0
- package/dist/tests/vtex/vtex-commercial-conditions-surface.test.js.map +7 -0
- package/dist/tests/vtex/vtex-commercial-conditions-workflow.test.js +190 -0
- package/dist/tests/vtex/vtex-commercial-conditions-workflow.test.js.map +7 -0
- package/package.json +1 -1
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../tests/vtex/vtex-commercial-conditions-docs.test.ts"],
|
|
4
|
+
"sourcesContent": ["import { readFile } from \"node:fs/promises\";\nimport { describe, expect, it } from \"vitest\";\n\ndescribe(\"VTEX commercial conditions documentation\", () => {\n it(\"documents the new VTEX payments capability across project docs\", async () => {\n const projectStatus = await readFile(new URL(\"../../docs/PROJECT_STATUS.md\", import.meta.url), \"utf8\");\n const keyEndpoints = await readFile(\n new URL(\"../../src/services/vtex/docs/vtex-key-endpoints.md\", import.meta.url),\n \"utf8\"\n );\n const dashboardCapabilities = await readFile(\n new URL(\"../../../bi-mcp-dashboard/docs/content/CAPACIDADES_MCP.md\", import.meta.url),\n \"utf8\"\n );\n\n expect(projectStatus).toContain(\"`35` tools VTEX.\");\n expect(projectStatus).toContain(\"condiciones comerciales y reglas de pago\");\n\n expect(keyEndpoints).toContain(\"Legacy payments endpoints exposed with sandbox caveat\");\n expect(keyEndpoints).toContain(\"`vtex_commercial_conditions`\");\n expect(keyEndpoints).toContain(\"`vtex_payment_rules`\");\n\n expect(dashboardCapabilities).toContain(\n \"Gesti\u00F3n de Condiciones Comerciales y Reglas de Pago\"\n );\n expect(dashboardCapabilities).toContain(\"`vtex_commercial_conditions`\");\n expect(dashboardCapabilities).toContain(\"`vtex_payment_rules`\");\n });\n});\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,gBAAgB;AACzB,SAAS,UAAU,QAAQ,UAAU;AAErC,SAAS,4CAA4C,MAAM;AACzD,KAAG,kEAAkE,YAAY;AAC/E,UAAM,gBAAgB,MAAM,SAAS,IAAI,IAAI,gCAAgC,YAAY,GAAG,GAAG,MAAM;AACrG,UAAM,eAAe,MAAM;AAAA,MACzB,IAAI,IAAI,sDAAsD,YAAY,GAAG;AAAA,MAC7E;AAAA,IACF;AACA,UAAM,wBAAwB,MAAM;AAAA,MAClC,IAAI,IAAI,6DAA6D,YAAY,GAAG;AAAA,MACpF;AAAA,IACF;AAEA,WAAO,aAAa,EAAE,UAAU,kBAAkB;AAClD,WAAO,aAAa,EAAE,UAAU,0CAA0C;AAE1E,WAAO,YAAY,EAAE,UAAU,uDAAuD;AACtF,WAAO,YAAY,EAAE,UAAU,8BAA8B;AAC7D,WAAO,YAAY,EAAE,UAAU,sBAAsB;AAErD,WAAO,qBAAqB,EAAE;AAAA,MAC5B;AAAA,IACF;AACA,WAAO,qBAAqB,EAAE,UAAU,8BAA8B;AACtE,WAAO,qBAAqB,EAAE,UAAU,sBAAsB;AAAA,EAChE,CAAC;AACH,CAAC;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { readFile } from "node:fs/promises";
|
|
2
|
+
import { describe, expect, it } from "vitest";
|
|
3
|
+
describe("VTEX commercial conditions server surface", () => {
|
|
4
|
+
it("exports and registers both action-based payments tools", async () => {
|
|
5
|
+
const serverSource = await readFile(new URL("../../index.ts", import.meta.url), "utf8");
|
|
6
|
+
const exportsSource = await readFile(new URL("../../src/tools/vtex/index.ts", import.meta.url), "utf8");
|
|
7
|
+
expect(exportsSource).toContain('export * from "./commercial-conditions.js"');
|
|
8
|
+
expect(exportsSource).toContain('export * from "./payment-rules.js"');
|
|
9
|
+
for (const toolName of ["vtex_commercial_conditions", "vtex_payment_rules"]) {
|
|
10
|
+
const registrationStart = serverSource.indexOf(`name: "${toolName}"`);
|
|
11
|
+
expect(registrationStart, `${toolName} registration exists`).toBeGreaterThan(-1);
|
|
12
|
+
const registrationBlock = serverSource.slice(registrationStart, registrationStart + 900);
|
|
13
|
+
expect(registrationBlock).toContain("readOnlyHint: false");
|
|
14
|
+
expect(registrationBlock).toContain("destructiveHint: true");
|
|
15
|
+
expect(registrationBlock).toContain("openWorldHint: true");
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
it("keeps both tool descriptions business-safe and action-focused", async () => {
|
|
19
|
+
const serverSource = await readFile(new URL("../../index.ts", import.meta.url), "utf8");
|
|
20
|
+
const commercialConditionsStart = serverSource.indexOf('name: "vtex_commercial_conditions"');
|
|
21
|
+
const paymentRulesStart = serverSource.indexOf('name: "vtex_payment_rules"');
|
|
22
|
+
expect(commercialConditionsStart).toBeGreaterThan(-1);
|
|
23
|
+
expect(paymentRulesStart).toBeGreaterThan(-1);
|
|
24
|
+
const commercialConditionsBlock = serverSource.slice(commercialConditionsStart, commercialConditionsStart + 900);
|
|
25
|
+
const paymentRulesBlock = serverSource.slice(paymentRulesStart, paymentRulesStart + 900);
|
|
26
|
+
expect(commercialConditionsBlock).toContain(
|
|
27
|
+
"condition records used by checkout and installment strategies"
|
|
28
|
+
);
|
|
29
|
+
expect(commercialConditionsBlock).toContain("Delete operations require confirmed=true");
|
|
30
|
+
expect(commercialConditionsBlock).not.toContain("sandbox");
|
|
31
|
+
expect(commercialConditionsBlock).not.toContain("production writes");
|
|
32
|
+
expect(commercialConditionsBlock).not.toContain("legacy VTEX Payments endpoints");
|
|
33
|
+
expect(paymentRulesBlock).toContain(
|
|
34
|
+
"rules that map installments, payment systems, and optional commercial-condition restrictions"
|
|
35
|
+
);
|
|
36
|
+
expect(paymentRulesBlock).toContain("Delete operations require confirmed=true");
|
|
37
|
+
expect(paymentRulesBlock).not.toContain("sandbox");
|
|
38
|
+
expect(paymentRulesBlock).not.toContain("production writes");
|
|
39
|
+
expect(paymentRulesBlock).not.toContain("legacy VTEX Payments endpoint");
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
//# sourceMappingURL=vtex-commercial-conditions-surface.test.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../tests/vtex/vtex-commercial-conditions-surface.test.ts"],
|
|
4
|
+
"sourcesContent": ["import { readFile } from \"node:fs/promises\";\nimport { describe, expect, it } from \"vitest\";\n\ndescribe(\"VTEX commercial conditions server surface\", () => {\n it(\"exports and registers both action-based payments tools\", async () => {\n const serverSource = await readFile(new URL(\"../../index.ts\", import.meta.url), \"utf8\");\n const exportsSource = await readFile(new URL(\"../../src/tools/vtex/index.ts\", import.meta.url), \"utf8\");\n\n expect(exportsSource).toContain('export * from \"./commercial-conditions.js\"');\n expect(exportsSource).toContain('export * from \"./payment-rules.js\"');\n\n for (const toolName of [\"vtex_commercial_conditions\", \"vtex_payment_rules\"]) {\n const registrationStart = serverSource.indexOf(`name: \"${toolName}\"`);\n expect(registrationStart, `${toolName} registration exists`).toBeGreaterThan(-1);\n\n const registrationBlock = serverSource.slice(registrationStart, registrationStart + 900);\n expect(registrationBlock).toContain(\"readOnlyHint: false\");\n expect(registrationBlock).toContain(\"destructiveHint: true\");\n expect(registrationBlock).toContain(\"openWorldHint: true\");\n }\n });\n\n it(\"keeps both tool descriptions business-safe and action-focused\", async () => {\n const serverSource = await readFile(new URL(\"../../index.ts\", import.meta.url), \"utf8\");\n\n const commercialConditionsStart = serverSource.indexOf('name: \"vtex_commercial_conditions\"');\n const paymentRulesStart = serverSource.indexOf('name: \"vtex_payment_rules\"');\n\n expect(commercialConditionsStart).toBeGreaterThan(-1);\n expect(paymentRulesStart).toBeGreaterThan(-1);\n\n const commercialConditionsBlock = serverSource.slice(commercialConditionsStart, commercialConditionsStart + 900);\n const paymentRulesBlock = serverSource.slice(paymentRulesStart, paymentRulesStart + 900);\n\n expect(commercialConditionsBlock).toContain(\n \"condition records used by checkout and installment strategies\"\n );\n expect(commercialConditionsBlock).toContain(\"Delete operations require confirmed=true\");\n expect(commercialConditionsBlock).not.toContain(\"sandbox\");\n expect(commercialConditionsBlock).not.toContain(\"production writes\");\n expect(commercialConditionsBlock).not.toContain(\"legacy VTEX Payments endpoints\");\n\n expect(paymentRulesBlock).toContain(\n \"rules that map installments, payment systems, and optional commercial-condition restrictions\"\n );\n expect(paymentRulesBlock).toContain(\"Delete operations require confirmed=true\");\n expect(paymentRulesBlock).not.toContain(\"sandbox\");\n expect(paymentRulesBlock).not.toContain(\"production writes\");\n expect(paymentRulesBlock).not.toContain(\"legacy VTEX Payments endpoint\");\n });\n});\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,gBAAgB;AACzB,SAAS,UAAU,QAAQ,UAAU;AAErC,SAAS,6CAA6C,MAAM;AAC1D,KAAG,0DAA0D,YAAY;AACvE,UAAM,eAAe,MAAM,SAAS,IAAI,IAAI,kBAAkB,YAAY,GAAG,GAAG,MAAM;AACtF,UAAM,gBAAgB,MAAM,SAAS,IAAI,IAAI,iCAAiC,YAAY,GAAG,GAAG,MAAM;AAEtG,WAAO,aAAa,EAAE,UAAU,4CAA4C;AAC5E,WAAO,aAAa,EAAE,UAAU,oCAAoC;AAEpE,eAAW,YAAY,CAAC,8BAA8B,oBAAoB,GAAG;AAC3E,YAAM,oBAAoB,aAAa,QAAQ,UAAU,QAAQ,GAAG;AACpE,aAAO,mBAAmB,GAAG,QAAQ,sBAAsB,EAAE,gBAAgB,EAAE;AAE/E,YAAM,oBAAoB,aAAa,MAAM,mBAAmB,oBAAoB,GAAG;AACvF,aAAO,iBAAiB,EAAE,UAAU,qBAAqB;AACzD,aAAO,iBAAiB,EAAE,UAAU,uBAAuB;AAC3D,aAAO,iBAAiB,EAAE,UAAU,qBAAqB;AAAA,IAC3D;AAAA,EACF,CAAC;AAED,KAAG,iEAAiE,YAAY;AAC9E,UAAM,eAAe,MAAM,SAAS,IAAI,IAAI,kBAAkB,YAAY,GAAG,GAAG,MAAM;AAEtF,UAAM,4BAA4B,aAAa,QAAQ,oCAAoC;AAC3F,UAAM,oBAAoB,aAAa,QAAQ,4BAA4B;AAE3E,WAAO,yBAAyB,EAAE,gBAAgB,EAAE;AACpD,WAAO,iBAAiB,EAAE,gBAAgB,EAAE;AAE5C,UAAM,4BAA4B,aAAa,MAAM,2BAA2B,4BAA4B,GAAG;AAC/G,UAAM,oBAAoB,aAAa,MAAM,mBAAmB,oBAAoB,GAAG;AAEvF,WAAO,yBAAyB,EAAE;AAAA,MAChC;AAAA,IACF;AACA,WAAO,yBAAyB,EAAE,UAAU,0CAA0C;AACtF,WAAO,yBAAyB,EAAE,IAAI,UAAU,SAAS;AACzD,WAAO,yBAAyB,EAAE,IAAI,UAAU,mBAAmB;AACnE,WAAO,yBAAyB,EAAE,IAAI,UAAU,gCAAgC;AAEhF,WAAO,iBAAiB,EAAE;AAAA,MACxB;AAAA,IACF;AACA,WAAO,iBAAiB,EAAE,UAAU,0CAA0C;AAC9E,WAAO,iBAAiB,EAAE,IAAI,UAAU,SAAS;AACjD,WAAO,iBAAiB,EAAE,IAAI,UAAU,mBAAmB;AAC3D,WAAO,iBAAiB,EAAE,IAAI,UAAU,+BAA+B;AAAA,EACzE,CAAC;AACH,CAAC;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { beforeEach, describe, expect, it, vi } from "vitest";
|
|
3
|
+
const objectMock = vi.fn((value) => ({ kind: "object", value }));
|
|
4
|
+
const errorMock = vi.fn((message) => ({ kind: "error", message }));
|
|
5
|
+
const createCommercialConditionMock = vi.fn();
|
|
6
|
+
const getCommercialConditionMock = vi.fn();
|
|
7
|
+
const createPaymentRuleMock = vi.fn();
|
|
8
|
+
const getPaymentRuleMock = vi.fn();
|
|
9
|
+
const updateSkuBasicFieldsServiceMock = vi.fn();
|
|
10
|
+
const resolveVtexWriteProfileMock = vi.fn();
|
|
11
|
+
const buildWriteSuccessResponseMock = vi.fn((value) => ({ kind: "write", value }));
|
|
12
|
+
const handleVtexWriteErrorMock = vi.fn((_err, fallback) => ({ kind: "error", message: fallback }));
|
|
13
|
+
const requireExplicitConfirmationMock = vi.fn();
|
|
14
|
+
vi.mock("mcp-use/server", () => ({
|
|
15
|
+
object: objectMock,
|
|
16
|
+
error: errorMock
|
|
17
|
+
}));
|
|
18
|
+
vi.mock("../../src/services/vtex/vtex-payments.js", () => ({
|
|
19
|
+
getCommercialCondition: getCommercialConditionMock,
|
|
20
|
+
listCommercialConditions: vi.fn(),
|
|
21
|
+
getPaymentRule: getPaymentRuleMock,
|
|
22
|
+
listPaymentRules: vi.fn()
|
|
23
|
+
}));
|
|
24
|
+
vi.mock("../../src/services/vtex/vtex-payments-write.js", () => ({
|
|
25
|
+
createCommercialCondition: createCommercialConditionMock,
|
|
26
|
+
updateCommercialCondition: vi.fn(),
|
|
27
|
+
deleteCommercialCondition: vi.fn(),
|
|
28
|
+
createPaymentRule: createPaymentRuleMock,
|
|
29
|
+
updatePaymentRule: vi.fn(),
|
|
30
|
+
deletePaymentRule: vi.fn()
|
|
31
|
+
}));
|
|
32
|
+
vi.mock("../../src/services/vtex/vtex-catalog-write.js", () => ({
|
|
33
|
+
updateSkuBasicFields: updateSkuBasicFieldsServiceMock,
|
|
34
|
+
replaceSkuEans: vi.fn(),
|
|
35
|
+
createProduct: vi.fn(),
|
|
36
|
+
createSku: vi.fn(),
|
|
37
|
+
addSkuEan: vi.fn(),
|
|
38
|
+
getSkuImages: vi.fn(),
|
|
39
|
+
attachSkuImage: vi.fn(),
|
|
40
|
+
updateSkuImage: vi.fn()
|
|
41
|
+
}));
|
|
42
|
+
vi.mock("../../src/tools/vtex/write-helpers.js", () => ({
|
|
43
|
+
vtexProfileIdSchemaField: z.string().trim().min(1).optional().describe("profile"),
|
|
44
|
+
confirmationSchemaField: z.boolean().optional().describe("confirmed"),
|
|
45
|
+
resolveVtexWriteProfile: resolveVtexWriteProfileMock,
|
|
46
|
+
buildWriteSuccessResponse: buildWriteSuccessResponseMock,
|
|
47
|
+
handleVtexWriteError: handleVtexWriteErrorMock,
|
|
48
|
+
requireExplicitConfirmation: requireExplicitConfirmationMock
|
|
49
|
+
}));
|
|
50
|
+
const commercialConditionsModule = await import("../../src/tools/vtex/commercial-conditions.js");
|
|
51
|
+
const paymentRulesModule = await import("../../src/tools/vtex/payment-rules.js");
|
|
52
|
+
const skuModule = await import("../../src/tools/vtex/update-sku-basic-fields.js");
|
|
53
|
+
describe("VTEX commercial conditions business workflow", () => {
|
|
54
|
+
beforeEach(() => {
|
|
55
|
+
vi.clearAllMocks();
|
|
56
|
+
resolveVtexWriteProfileMock.mockResolvedValue({
|
|
57
|
+
ok: true,
|
|
58
|
+
value: { profileId: "profile-1" }
|
|
59
|
+
});
|
|
60
|
+
requireExplicitConfirmationMock.mockReturnValue(null);
|
|
61
|
+
});
|
|
62
|
+
it("supports a selective installments workflow for condition-targeted SKUs", async () => {
|
|
63
|
+
createCommercialConditionMock.mockResolvedValue({
|
|
64
|
+
id: 901,
|
|
65
|
+
Name: "9-cuotas-sin-interes",
|
|
66
|
+
IsActive: true
|
|
67
|
+
});
|
|
68
|
+
createPaymentRuleMock.mockResolvedValue({
|
|
69
|
+
id: 902,
|
|
70
|
+
commercialConditionId: 901,
|
|
71
|
+
paymentSystem: "2",
|
|
72
|
+
restrictedByCondition: true,
|
|
73
|
+
installments: [{ count: 9, interest: false }]
|
|
74
|
+
});
|
|
75
|
+
updateSkuBasicFieldsServiceMock.mockResolvedValue({
|
|
76
|
+
before: { Id: 333, CommercialConditionId: 0 },
|
|
77
|
+
after: { Id: 333, CommercialConditionId: 901 }
|
|
78
|
+
});
|
|
79
|
+
getCommercialConditionMock.mockResolvedValue({
|
|
80
|
+
id: 901,
|
|
81
|
+
name: "9-cuotas-sin-interes",
|
|
82
|
+
isActive: true
|
|
83
|
+
});
|
|
84
|
+
getPaymentRuleMock.mockResolvedValueOnce({
|
|
85
|
+
id: 100,
|
|
86
|
+
commercialConditionId: 0,
|
|
87
|
+
paymentSystem: "2",
|
|
88
|
+
restrictedByCondition: false,
|
|
89
|
+
installments: [{ count: 6, interest: false }]
|
|
90
|
+
}).mockResolvedValueOnce({
|
|
91
|
+
id: 902,
|
|
92
|
+
commercialConditionId: 901,
|
|
93
|
+
paymentSystem: "2",
|
|
94
|
+
restrictedByCondition: true,
|
|
95
|
+
installments: [{ count: 9, interest: false }]
|
|
96
|
+
});
|
|
97
|
+
const createdCondition = await commercialConditionsModule.commercialConditionsHandler({
|
|
98
|
+
action: "create",
|
|
99
|
+
profileId: "profile-1",
|
|
100
|
+
name: "9-cuotas-sin-interes",
|
|
101
|
+
isActive: true
|
|
102
|
+
});
|
|
103
|
+
const createdRule = await paymentRulesModule.paymentRulesHandler({
|
|
104
|
+
action: "create",
|
|
105
|
+
profileId: "profile-1",
|
|
106
|
+
commercialConditionId: 901,
|
|
107
|
+
paymentSystem: "2",
|
|
108
|
+
restrictedByCondition: true,
|
|
109
|
+
installments: [{ count: 9, interest: false }]
|
|
110
|
+
});
|
|
111
|
+
const assignedSku = await skuModule.updateSkuBasicFieldsHandler({
|
|
112
|
+
profileId: "profile-1",
|
|
113
|
+
skuId: "333",
|
|
114
|
+
commercialConditionId: 901
|
|
115
|
+
});
|
|
116
|
+
const defaultRule = await paymentRulesModule.paymentRulesHandler({
|
|
117
|
+
action: "get",
|
|
118
|
+
profileId: "profile-1",
|
|
119
|
+
ruleId: 100
|
|
120
|
+
});
|
|
121
|
+
const targetedRule = await paymentRulesModule.paymentRulesHandler({
|
|
122
|
+
action: "get",
|
|
123
|
+
profileId: "profile-1",
|
|
124
|
+
ruleId: 902
|
|
125
|
+
});
|
|
126
|
+
expect(createCommercialConditionMock).toHaveBeenCalledWith("profile-1", {
|
|
127
|
+
Name: "9-cuotas-sin-interes",
|
|
128
|
+
IsActive: true
|
|
129
|
+
});
|
|
130
|
+
expect(createPaymentRuleMock).toHaveBeenCalledWith("profile-1", {
|
|
131
|
+
commercialConditionId: 901,
|
|
132
|
+
paymentSystem: "2",
|
|
133
|
+
restrictedByCondition: true,
|
|
134
|
+
installments: [{ count: 9, interest: false }]
|
|
135
|
+
});
|
|
136
|
+
expect(updateSkuBasicFieldsServiceMock).toHaveBeenCalledWith("profile-1", "333", {
|
|
137
|
+
commercialConditionId: 901
|
|
138
|
+
});
|
|
139
|
+
expect(createdCondition).toMatchObject({
|
|
140
|
+
kind: "write",
|
|
141
|
+
value: {
|
|
142
|
+
operation: "commercial_conditions_create",
|
|
143
|
+
resourceId: "901"
|
|
144
|
+
}
|
|
145
|
+
});
|
|
146
|
+
expect(createdRule).toMatchObject({
|
|
147
|
+
kind: "write",
|
|
148
|
+
value: {
|
|
149
|
+
operation: "payment_rules_create",
|
|
150
|
+
resourceId: "902"
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
expect(assignedSku).toMatchObject({
|
|
154
|
+
kind: "write",
|
|
155
|
+
value: {
|
|
156
|
+
operation: "update_sku_basic_fields",
|
|
157
|
+
resourceId: "333"
|
|
158
|
+
}
|
|
159
|
+
});
|
|
160
|
+
expect(defaultRule).toEqual({
|
|
161
|
+
kind: "object",
|
|
162
|
+
value: {
|
|
163
|
+
profile_id: "profile-1",
|
|
164
|
+
rule_id: 100,
|
|
165
|
+
payment_rule: {
|
|
166
|
+
id: 100,
|
|
167
|
+
commercial_condition_id: 0,
|
|
168
|
+
payment_system: "2",
|
|
169
|
+
restricted_by_condition: false,
|
|
170
|
+
installments: [{ count: 6, interest: false }]
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
});
|
|
174
|
+
expect(targetedRule).toEqual({
|
|
175
|
+
kind: "object",
|
|
176
|
+
value: {
|
|
177
|
+
profile_id: "profile-1",
|
|
178
|
+
rule_id: 902,
|
|
179
|
+
payment_rule: {
|
|
180
|
+
id: 902,
|
|
181
|
+
commercial_condition_id: 901,
|
|
182
|
+
payment_system: "2",
|
|
183
|
+
restricted_by_condition: true,
|
|
184
|
+
installments: [{ count: 9, interest: false }]
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
});
|
|
188
|
+
});
|
|
189
|
+
});
|
|
190
|
+
//# sourceMappingURL=vtex-commercial-conditions-workflow.test.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../tests/vtex/vtex-commercial-conditions-workflow.test.ts"],
|
|
4
|
+
"sourcesContent": ["import { z } from \"zod\";\nimport { beforeEach, describe, expect, it, vi } from \"vitest\";\n\nconst objectMock = vi.fn((value) => ({ kind: \"object\", value }));\nconst errorMock = vi.fn((message) => ({ kind: \"error\", message }));\n\nconst createCommercialConditionMock = vi.fn();\nconst getCommercialConditionMock = vi.fn();\nconst createPaymentRuleMock = vi.fn();\nconst getPaymentRuleMock = vi.fn();\nconst updateSkuBasicFieldsServiceMock = vi.fn();\n\nconst resolveVtexWriteProfileMock = vi.fn();\nconst buildWriteSuccessResponseMock = vi.fn((value) => ({ kind: \"write\", value }));\nconst handleVtexWriteErrorMock = vi.fn((_err, fallback) => ({ kind: \"error\", message: fallback }));\nconst requireExplicitConfirmationMock = vi.fn();\n\nvi.mock(\"mcp-use/server\", () => ({\n object: objectMock,\n error: errorMock,\n}));\n\nvi.mock(\"../../src/services/vtex/vtex-payments.js\", () => ({\n getCommercialCondition: getCommercialConditionMock,\n listCommercialConditions: vi.fn(),\n getPaymentRule: getPaymentRuleMock,\n listPaymentRules: vi.fn(),\n}));\n\nvi.mock(\"../../src/services/vtex/vtex-payments-write.js\", () => ({\n createCommercialCondition: createCommercialConditionMock,\n updateCommercialCondition: vi.fn(),\n deleteCommercialCondition: vi.fn(),\n createPaymentRule: createPaymentRuleMock,\n updatePaymentRule: vi.fn(),\n deletePaymentRule: vi.fn(),\n}));\n\nvi.mock(\"../../src/services/vtex/vtex-catalog-write.js\", () => ({\n updateSkuBasicFields: updateSkuBasicFieldsServiceMock,\n replaceSkuEans: vi.fn(),\n createProduct: vi.fn(),\n createSku: vi.fn(),\n addSkuEan: vi.fn(),\n getSkuImages: vi.fn(),\n attachSkuImage: vi.fn(),\n updateSkuImage: vi.fn(),\n}));\n\nvi.mock(\"../../src/tools/vtex/write-helpers.js\", () => ({\n vtexProfileIdSchemaField: z.string().trim().min(1).optional().describe(\"profile\"),\n confirmationSchemaField: z.boolean().optional().describe(\"confirmed\"),\n resolveVtexWriteProfile: resolveVtexWriteProfileMock,\n buildWriteSuccessResponse: buildWriteSuccessResponseMock,\n handleVtexWriteError: handleVtexWriteErrorMock,\n requireExplicitConfirmation: requireExplicitConfirmationMock,\n}));\n\nconst commercialConditionsModule = await import(\"../../src/tools/vtex/commercial-conditions.js\");\nconst paymentRulesModule = await import(\"../../src/tools/vtex/payment-rules.js\");\nconst skuModule = await import(\"../../src/tools/vtex/update-sku-basic-fields.js\");\n\ndescribe(\"VTEX commercial conditions business workflow\", () => {\n beforeEach(() => {\n vi.clearAllMocks();\n resolveVtexWriteProfileMock.mockResolvedValue({\n ok: true,\n value: { profileId: \"profile-1\" },\n });\n requireExplicitConfirmationMock.mockReturnValue(null);\n });\n\n it(\"supports a selective installments workflow for condition-targeted SKUs\", async () => {\n createCommercialConditionMock.mockResolvedValue({\n id: 901,\n Name: \"9-cuotas-sin-interes\",\n IsActive: true,\n });\n createPaymentRuleMock.mockResolvedValue({\n id: 902,\n commercialConditionId: 901,\n paymentSystem: \"2\",\n restrictedByCondition: true,\n installments: [{ count: 9, interest: false }],\n });\n updateSkuBasicFieldsServiceMock.mockResolvedValue({\n before: { Id: 333, CommercialConditionId: 0 },\n after: { Id: 333, CommercialConditionId: 901 },\n });\n getCommercialConditionMock.mockResolvedValue({\n id: 901,\n name: \"9-cuotas-sin-interes\",\n isActive: true,\n });\n getPaymentRuleMock\n .mockResolvedValueOnce({\n id: 100,\n commercialConditionId: 0,\n paymentSystem: \"2\",\n restrictedByCondition: false,\n installments: [{ count: 6, interest: false }],\n })\n .mockResolvedValueOnce({\n id: 902,\n commercialConditionId: 901,\n paymentSystem: \"2\",\n restrictedByCondition: true,\n installments: [{ count: 9, interest: false }],\n });\n\n const createdCondition = await commercialConditionsModule.commercialConditionsHandler({\n action: \"create\",\n profileId: \"profile-1\",\n name: \"9-cuotas-sin-interes\",\n isActive: true,\n });\n\n const createdRule = await paymentRulesModule.paymentRulesHandler({\n action: \"create\",\n profileId: \"profile-1\",\n commercialConditionId: 901,\n paymentSystem: \"2\",\n restrictedByCondition: true,\n installments: [{ count: 9, interest: false }],\n });\n\n const assignedSku = await skuModule.updateSkuBasicFieldsHandler({\n profileId: \"profile-1\",\n skuId: \"333\",\n commercialConditionId: 901,\n });\n\n const defaultRule = await paymentRulesModule.paymentRulesHandler({\n action: \"get\",\n profileId: \"profile-1\",\n ruleId: 100,\n });\n\n const targetedRule = await paymentRulesModule.paymentRulesHandler({\n action: \"get\",\n profileId: \"profile-1\",\n ruleId: 902,\n });\n\n expect(createCommercialConditionMock).toHaveBeenCalledWith(\"profile-1\", {\n Name: \"9-cuotas-sin-interes\",\n IsActive: true,\n });\n expect(createPaymentRuleMock).toHaveBeenCalledWith(\"profile-1\", {\n commercialConditionId: 901,\n paymentSystem: \"2\",\n restrictedByCondition: true,\n installments: [{ count: 9, interest: false }],\n });\n expect(updateSkuBasicFieldsServiceMock).toHaveBeenCalledWith(\"profile-1\", \"333\", {\n commercialConditionId: 901,\n });\n\n expect(createdCondition).toMatchObject({\n kind: \"write\",\n value: {\n operation: \"commercial_conditions_create\",\n resourceId: \"901\",\n },\n });\n expect(createdRule).toMatchObject({\n kind: \"write\",\n value: {\n operation: \"payment_rules_create\",\n resourceId: \"902\",\n },\n });\n expect(assignedSku).toMatchObject({\n kind: \"write\",\n value: {\n operation: \"update_sku_basic_fields\",\n resourceId: \"333\",\n },\n });\n\n expect(defaultRule).toEqual({\n kind: \"object\",\n value: {\n profile_id: \"profile-1\",\n rule_id: 100,\n payment_rule: {\n id: 100,\n commercial_condition_id: 0,\n payment_system: \"2\",\n restricted_by_condition: false,\n installments: [{ count: 6, interest: false }],\n },\n },\n });\n expect(targetedRule).toEqual({\n kind: \"object\",\n value: {\n profile_id: \"profile-1\",\n rule_id: 902,\n payment_rule: {\n id: 902,\n commercial_condition_id: 901,\n payment_system: \"2\",\n restricted_by_condition: true,\n installments: [{ count: 9, interest: false }],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