@labdigital/commercetools-mock 2.53.1 → 2.54.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/index.js +52 -2
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/lib/predicateParser.test.ts +39 -0
- package/src/lib/predicateParser.ts +2 -0
- package/src/repositories/business-unit.ts +157 -2
- package/src/services/business-units.test.ts +586 -15
- package/src/testing/business-unit.ts +48 -0
- package/src/testing/type.ts +20 -0
package/dist/index.js
CHANGED
|
@@ -1747,9 +1747,14 @@ var BusinessUnitUpdateHandler = class extends AbstractUpdateHandler {
|
|
|
1747
1747
|
resource.stores.push(newStore);
|
|
1748
1748
|
}
|
|
1749
1749
|
}
|
|
1750
|
-
changeAddress(context, resource, { address }) {
|
|
1750
|
+
changeAddress(context, resource, { addressId, address }) {
|
|
1751
|
+
const existingAddressIndex = resource.addresses.findIndex((addr) => addr.id === addressId);
|
|
1752
|
+
if (existingAddressIndex === -1) throw new Error(`Address with id ${addressId} not found`);
|
|
1751
1753
|
const newAddress = createAddress(address, context.projectKey, this._storage);
|
|
1752
|
-
if (newAddress) resource.addresses
|
|
1754
|
+
if (newAddress) resource.addresses[existingAddressIndex] = {
|
|
1755
|
+
...newAddress,
|
|
1756
|
+
id: addressId
|
|
1757
|
+
};
|
|
1753
1758
|
}
|
|
1754
1759
|
changeApprovalRuleMode(context, resource, { approvalRuleMode }) {
|
|
1755
1760
|
resource.approvalRuleMode = approvalRuleMode;
|
|
@@ -1770,6 +1775,15 @@ var BusinessUnitUpdateHandler = class extends AbstractUpdateHandler {
|
|
|
1770
1775
|
const newAssociates = associates.map((a) => createAssociate(a, context.projectKey, this._storage)).filter((a) => a !== void 0);
|
|
1771
1776
|
resource.associates = newAssociates || void 0;
|
|
1772
1777
|
}
|
|
1778
|
+
removeAssociate(context, resource, { customer }) {
|
|
1779
|
+
resource.associates = resource.associates.filter((associate) => associate.customer.id !== customer.id);
|
|
1780
|
+
}
|
|
1781
|
+
changeAssociate(context, resource, { associate }) {
|
|
1782
|
+
const existingAssociateIndex = resource.associates.findIndex((a) => a.customer.id === associate.customer.id);
|
|
1783
|
+
if (existingAssociateIndex === -1) throw new Error(`Associate with customer id ${associate.customer.id} not found`);
|
|
1784
|
+
const newAssociate = createAssociate(associate, context.projectKey, this._storage);
|
|
1785
|
+
if (newAssociate) resource.associates[existingAssociateIndex] = newAssociate;
|
|
1786
|
+
}
|
|
1773
1787
|
setContactEmail(context, resource, { contactEmail }) {
|
|
1774
1788
|
resource.contactEmail = contactEmail;
|
|
1775
1789
|
}
|
|
@@ -1790,6 +1804,40 @@ var BusinessUnitUpdateHandler = class extends AbstractUpdateHandler {
|
|
|
1790
1804
|
if (!resource.shippingAddressIds) resource.shippingAddressIds = [];
|
|
1791
1805
|
if (addressId) resource.shippingAddressIds.push(addressId);
|
|
1792
1806
|
}
|
|
1807
|
+
removeShippingAddressId(context, resource, { addressId }) {
|
|
1808
|
+
if (resource.shippingAddressIds) resource.shippingAddressIds = resource.shippingAddressIds.filter((id) => id !== addressId);
|
|
1809
|
+
if (resource.defaultShippingAddressId === addressId) resource.defaultShippingAddressId = void 0;
|
|
1810
|
+
}
|
|
1811
|
+
addBillingAddressId(context, resource, { addressId }) {
|
|
1812
|
+
if (!resource.billingAddressIds) resource.billingAddressIds = [];
|
|
1813
|
+
if (addressId) resource.billingAddressIds.push(addressId);
|
|
1814
|
+
}
|
|
1815
|
+
removeBillingAddressId(context, resource, { addressId }) {
|
|
1816
|
+
if (resource.billingAddressIds) resource.billingAddressIds = resource.billingAddressIds.filter((id) => id !== addressId);
|
|
1817
|
+
if (resource.defaultBillingAddressId === addressId) resource.defaultBillingAddressId = void 0;
|
|
1818
|
+
}
|
|
1819
|
+
setDefaultBillingAddress(context, resource, { addressId }) {
|
|
1820
|
+
resource.defaultBillingAddressId = addressId;
|
|
1821
|
+
}
|
|
1822
|
+
setCustomField(context, resource, { name, value }) {
|
|
1823
|
+
if (!resource.custom) throw new Error("Resource has no custom type");
|
|
1824
|
+
resource.custom.fields[name] = value;
|
|
1825
|
+
}
|
|
1826
|
+
setAddressCustomField(context, resource, { addressId, name, value }) {
|
|
1827
|
+
const address = resource.addresses.find((addr) => addr.id === addressId);
|
|
1828
|
+
if (!address) throw new Error(`Address with id ${addressId} not found`);
|
|
1829
|
+
if (!address.custom) throw new Error("Address has no custom type set. Use setAddressCustomType first.");
|
|
1830
|
+
address.custom.fields[name] = value;
|
|
1831
|
+
}
|
|
1832
|
+
setAddressCustomType(context, resource, { addressId, type, fields }) {
|
|
1833
|
+
const address = resource.addresses.find((addr) => addr.id === addressId);
|
|
1834
|
+
if (!address) throw new Error(`Address with id ${addressId} not found`);
|
|
1835
|
+
if (!type) address.custom = void 0;
|
|
1836
|
+
else address.custom = createCustomFields({
|
|
1837
|
+
type,
|
|
1838
|
+
fields
|
|
1839
|
+
}, context.projectKey, this._storage);
|
|
1840
|
+
}
|
|
1793
1841
|
removeAddress(context, resource, { addressId }) {
|
|
1794
1842
|
resource.addresses = resource.addresses.filter((addr) => addr.id !== addressId);
|
|
1795
1843
|
if (resource.shippingAddressIds) resource.shippingAddressIds = resource.shippingAddressIds.filter((id) => id !== addressId);
|
|
@@ -4741,6 +4789,7 @@ const generateMatchFunc = (predicate) => {
|
|
|
4741
4789
|
}
|
|
4742
4790
|
}).led("IN", 20, ({ left, bp }) => {
|
|
4743
4791
|
const expr = parser.parse({ terminals: [bp - 1] });
|
|
4792
|
+
lexer.expect(")");
|
|
4744
4793
|
return (obj, vars) => {
|
|
4745
4794
|
let symbols = expr;
|
|
4746
4795
|
if (!Array.isArray(symbols)) symbols = [expr];
|
|
@@ -4762,6 +4811,7 @@ const generateMatchFunc = (predicate) => {
|
|
|
4762
4811
|
if (type.match !== "circle") throw new PredicateError(`Invalid input '${type.match}', expected circle`);
|
|
4763
4812
|
lexer.expect("(");
|
|
4764
4813
|
const expr = parser.parse({ terminals: [")"] });
|
|
4814
|
+
lexer.expect(")");
|
|
4765
4815
|
return (obj, vars) => {
|
|
4766
4816
|
const value = resolveValue(obj, left);
|
|
4767
4817
|
if (!value) return false;
|