merchi_sdk_ts 0.0.1-a
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/.babelrc +13 -0
- package/.eslintrc.cjs +43 -0
- package/LICENSE +21 -0
- package/README.md +2 -0
- package/dist/constants/auto_assign_production_on_actions.js +7 -0
- package/dist/constants/call_to_actions.js +15 -0
- package/dist/constants/call_to_actions.test.js +4 -0
- package/dist/constants/discount_types.js +4 -0
- package/dist/constants/discount_types.test.js +4 -0
- package/dist/constants/domain_types.js +13 -0
- package/dist/constants/domain_types.test.js +4 -0
- package/dist/constants/errors.js +32 -0
- package/dist/constants/event_types.js +6 -0
- package/dist/constants/event_types.test.js +4 -0
- package/dist/constants/field_types.js +14 -0
- package/dist/constants/field_types.test.js +4 -0
- package/dist/constants/input_types.js +14 -0
- package/dist/constants/input_types.test.js +4 -0
- package/dist/constants/inventory_status.test.js +4 -0
- package/dist/constants/inventory_statuses.js +7 -0
- package/dist/constants/invoice_types.js +6 -0
- package/dist/constants/invoice_types.test.js +4 -0
- package/dist/constants/item_types.js +6 -0
- package/dist/constants/item_types.test.js +4 -0
- package/dist/constants/job/drafting_status.js +8 -0
- package/dist/constants/job/drafting_status.test.js +4 -0
- package/dist/constants/job/payment_status.js +8 -0
- package/dist/constants/job/payment_status.test.js +4 -0
- package/dist/constants/job/production_status.js +13 -0
- package/dist/constants/job/production_status.test.js +4 -0
- package/dist/constants/job/shipment_status.js +12 -0
- package/dist/constants/job/shipment_status.test.js +4 -0
- package/dist/constants/job/supply_chain_request_status.js +7 -0
- package/dist/constants/job/supply_chain_request_status.test.js +4 -0
- package/dist/constants/job_priorities.js +7 -0
- package/dist/constants/job_priorities.test.js +4 -0
- package/dist/constants/job_status.js +50 -0
- package/dist/constants/job_status.test.js +4 -0
- package/dist/constants/job_types.js +16 -0
- package/dist/constants/job_types.test.js +4 -0
- package/dist/constants/notification_sections.js +14 -0
- package/dist/constants/notification_sections.test.js +4 -0
- package/dist/constants/notification_types.js +98 -0
- package/dist/constants/notification_types.test.js +4 -0
- package/dist/constants/notification_urgencies.js +7 -0
- package/dist/constants/notification_urgencies.test.js +4 -0
- package/dist/constants/payment_types.js +11 -0
- package/dist/constants/payment_types.test.js +4 -0
- package/dist/constants/platform.js +5 -0
- package/dist/constants/platform.test.js +8 -0
- package/dist/constants/product_types.js +26 -0
- package/dist/constants/product_types.test.js +4 -0
- package/dist/constants/rights.js +6 -0
- package/dist/constants/rights.test.js +4 -0
- package/dist/constants/robots_meta_directives.js +1 -0
- package/dist/constants/robots_meta_directives.test.js +4 -0
- package/dist/constants/roles.js +25 -0
- package/dist/constants/roles.test.js +4 -0
- package/dist/constants/shipment_companies.js +19 -0
- package/dist/constants/shipment_companies.test.js +4 -0
- package/dist/constants/shipment_services.js +4 -0
- package/dist/constants/shipment_services.test.js +4 -0
- package/dist/constants/system_roles.js +4 -0
- package/dist/constants/system_roles.test.js +4 -0
- package/dist/constants/theme_foundations.js +7 -0
- package/dist/constants/theme_foundations.test.js +4 -0
- package/dist/constants/theme_status.js +6 -0
- package/dist/constants/theme_status.test.js +4 -0
- package/dist/constants/user_types.js +18 -0
- package/dist/constants/user_types.test.js +4 -0
- package/dist/constants/white_label_accessibilities.js +6 -0
- package/dist/constants/white_label_accessibilities.test.js +4 -0
- package/dist/cookie.js +16 -0
- package/dist/cookie.test.js +12 -0
- package/dist/entities/address.js +166 -0
- package/dist/entities/address.test.js +6 -0
- package/dist/entities/assignment.js +185 -0
- package/dist/entities/assignment.test.js +38 -0
- package/dist/entities/automatic_payment_relationship.js +77 -0
- package/dist/entities/automatic_payment_relationship.test.js +6 -0
- package/dist/entities/backup.js +44 -0
- package/dist/entities/backup.test.js +6 -0
- package/dist/entities/bank.js +116 -0
- package/dist/entities/bank.test.js +6 -0
- package/dist/entities/cart.js +203 -0
- package/dist/entities/cart.test.js +52 -0
- package/dist/entities/cart_item.js +153 -0
- package/dist/entities/cart_item.test.js +34 -0
- package/dist/entities/cart_shipment_group.js +62 -0
- package/dist/entities/cart_shipment_quote.js +85 -0
- package/dist/entities/category.js +92 -0
- package/dist/entities/category.test.js +52 -0
- package/dist/entities/company.js +648 -0
- package/dist/entities/company.test.js +6 -0
- package/dist/entities/company_invitation.js +82 -0
- package/dist/entities/company_invitation.test.js +6 -0
- package/dist/entities/component.js +209 -0
- package/dist/entities/component.test.js +12 -0
- package/dist/entities/component_tag.js +50 -0
- package/dist/entities/component_tag.test.js +6 -0
- package/dist/entities/component_version.js +80 -0
- package/dist/entities/component_version.test.js +6 -0
- package/dist/entities/country_tax.js +110 -0
- package/dist/entities/country_tax.test.js +11 -0
- package/dist/entities/discount.js +77 -0
- package/dist/entities/discount.test.js +20 -0
- package/dist/entities/discount_group.js +74 -0
- package/dist/entities/discount_group.test.js +6 -0
- package/dist/entities/domain.js +535 -0
- package/dist/entities/domain.test.js +75 -0
- package/dist/entities/domain_invitation.js +90 -0
- package/dist/entities/domain_invitation.test.js +6 -0
- package/dist/entities/domain_tag.js +100 -0
- package/dist/entities/domain_tag.test.js +6 -0
- package/dist/entities/draft.js +180 -0
- package/dist/entities/draft.test.js +39 -0
- package/dist/entities/draft_comment.js +132 -0
- package/dist/entities/draft_comment.test.js +6 -0
- package/dist/entities/draft_template.js +105 -0
- package/dist/entities/draft_template.test.js +6 -0
- package/dist/entities/email_address.js +68 -0
- package/dist/entities/email_address.test.js +6 -0
- package/dist/entities/email_counter.js +56 -0
- package/dist/entities/email_counter.test.js +6 -0
- package/dist/entities/enrolled_domain.js +85 -0
- package/dist/entities/enrolled_domain.test.js +6 -0
- package/dist/entities/exchange_rate.js +62 -0
- package/dist/entities/exchange_rate.test.js +6 -0
- package/dist/entities/file.js +383 -0
- package/dist/entities/file.test.js +38 -0
- package/dist/entities/internal_tag.js +120 -0
- package/dist/entities/internal_tag.test.js +6 -0
- package/dist/entities/inventory.js +120 -0
- package/dist/entities/inventory.test.js +26 -0
- package/dist/entities/inventory_unit_variation.js +64 -0
- package/dist/entities/inventory_unit_variation.test.js +6 -0
- package/dist/entities/invoice.js +420 -0
- package/dist/entities/invoice.test.js +39 -0
- package/dist/entities/item.js +102 -0
- package/dist/entities/item.test.js +17 -0
- package/dist/entities/job.js +744 -0
- package/dist/entities/job.test.js +103 -0
- package/dist/entities/job_comment.js +120 -0
- package/dist/entities/job_comment.test.js +6 -0
- package/dist/entities/matching_inventory.js +77 -0
- package/dist/entities/menu.js +78 -0
- package/dist/entities/menu.test.js +6 -0
- package/dist/entities/menu_item.js +76 -0
- package/dist/entities/menu_item.test.js +6 -0
- package/dist/entities/notification.js +234 -0
- package/dist/entities/notification.test.js +6 -0
- package/dist/entities/page.js +84 -0
- package/dist/entities/page.test.js +6 -0
- package/dist/entities/payment.js +141 -0
- package/dist/entities/payment.test.js +18 -0
- package/dist/entities/payment_device.js +87 -0
- package/dist/entities/payment_device.test.js +6 -0
- package/dist/entities/phone_number.js +98 -0
- package/dist/entities/phone_number.test.js +6 -0
- package/dist/entities/product.js +806 -0
- package/dist/entities/product.test.js +811 -0
- package/dist/entities/production_comment.js +120 -0
- package/dist/entities/production_comment.test.js +6 -0
- package/dist/entities/quote.js +208 -0
- package/dist/entities/quote.test.js +107 -0
- package/dist/entities/quote_item.js +121 -0
- package/dist/entities/quote_item.test.js +56 -0
- package/dist/entities/seo_domain_page.js +82 -0
- package/dist/entities/seo_domain_page.test.js +6 -0
- package/dist/entities/session.js +77 -0
- package/dist/entities/session.test.js +6 -0
- package/dist/entities/shipment.js +401 -0
- package/dist/entities/shipment.test.js +28 -0
- package/dist/entities/shipment_item.js +49 -0
- package/dist/entities/shipment_item.test.js +6 -0
- package/dist/entities/shipment_item_fulfillment.js +48 -0
- package/dist/entities/shipment_item_fulfillment.test.js +6 -0
- package/dist/entities/shipment_method.js +146 -0
- package/dist/entities/shipment_method.test.js +6 -0
- package/dist/entities/shipment_method_variation.js +104 -0
- package/dist/entities/shipment_method_variation.test.js +6 -0
- package/dist/entities/short_url.js +95 -0
- package/dist/entities/short_url.test.js +6 -0
- package/dist/entities/subscription_plan.js +172 -0
- package/dist/entities/subscription_plan.test.js +6 -0
- package/dist/entities/supply_domain.js +73 -0
- package/dist/entities/supply_domain.test.js +6 -0
- package/dist/entities/system_role.js +50 -0
- package/dist/entities/system_role.test.js +6 -0
- package/dist/entities/theme.js +614 -0
- package/dist/entities/theme.test.js +39 -0
- package/dist/entities/theme_css_setting.js +67 -0
- package/dist/entities/theme_css_setting.test.js +6 -0
- package/dist/entities/user.js +749 -0
- package/dist/entities/user.test.js +157 -0
- package/dist/entities/user_company.js +78 -0
- package/dist/entities/user_company.test.js +6 -0
- package/dist/entities/variation.js +147 -0
- package/dist/entities/variation.test.js +6 -0
- package/dist/entities/variation_field.js +313 -0
- package/dist/entities/variation_field.test.js +69 -0
- package/dist/entities/variation_fields_option.js +190 -0
- package/dist/entities/variation_fields_option.test.js +47 -0
- package/dist/entities/variation_option.js +129 -0
- package/dist/entities/variation_option.test.js +6 -0
- package/dist/entities/variations_group.js +111 -0
- package/dist/entities/variations_group.test.js +6 -0
- package/dist/entity.js +888 -0
- package/dist/merchi.js +259 -0
- package/dist/merchi.test.js +35 -0
- package/dist/request.js +132 -0
- package/dist/request.test.js +46 -0
- package/dist/test_util.js +19 -0
- package/dist/toasts.js +27 -0
- package/dist/toasts.test.js +46 -0
- package/dist/util/float.js +24 -0
- package/dist/util/query_string.js +11 -0
- package/dist/util/query_string.test.js +6 -0
- package/dist/util/validation.js +3 -0
- package/dist/util/validation.test.js +12 -0
- package/dist/uuid.js +8 -0
- package/dist/uuid.test.js +13 -0
- package/jest.config.js +17 -0
- package/package.json +44 -0
- package/src/constants/auto_assign_production_on_actions.ts +6 -0
- package/src/constants/call_to_actions.test.ts +5 -0
- package/src/constants/call_to_actions.ts +14 -0
- package/src/constants/discount_types.test.ts +5 -0
- package/src/constants/discount_types.ts +3 -0
- package/src/constants/domain_types.test.ts +5 -0
- package/src/constants/domain_types.ts +12 -0
- package/src/constants/errors.ts +32 -0
- package/src/constants/event_types.test.ts +5 -0
- package/src/constants/event_types.ts +5 -0
- package/src/constants/field_types.test.ts +5 -0
- package/src/constants/field_types.ts +13 -0
- package/src/constants/input_types.test.ts +5 -0
- package/src/constants/input_types.ts +13 -0
- package/src/constants/inventory_status.test.ts +5 -0
- package/src/constants/inventory_statuses.ts +6 -0
- package/src/constants/invoice_types.test.ts +5 -0
- package/src/constants/invoice_types.ts +5 -0
- package/src/constants/item_types.test.ts +5 -0
- package/src/constants/item_types.ts +5 -0
- package/src/constants/job/drafting_status.test.ts +5 -0
- package/src/constants/job/drafting_status.ts +7 -0
- package/src/constants/job/payment_status.test.ts +5 -0
- package/src/constants/job/payment_status.ts +7 -0
- package/src/constants/job/production_status.test.ts +5 -0
- package/src/constants/job/production_status.ts +12 -0
- package/src/constants/job/shipment_status.test.ts +5 -0
- package/src/constants/job/shipment_status.ts +11 -0
- package/src/constants/job/supply_chain_request_status.test.ts +5 -0
- package/src/constants/job/supply_chain_request_status.ts +6 -0
- package/src/constants/job_priorities.test.ts +5 -0
- package/src/constants/job_priorities.ts +6 -0
- package/src/constants/job_status.test.ts +5 -0
- package/src/constants/job_status.ts +49 -0
- package/src/constants/job_types.test.ts +5 -0
- package/src/constants/job_types.ts +15 -0
- package/src/constants/notification_sections.test.ts +5 -0
- package/src/constants/notification_sections.ts +13 -0
- package/src/constants/notification_types.test.ts +5 -0
- package/src/constants/notification_types.ts +97 -0
- package/src/constants/notification_urgencies.test.ts +5 -0
- package/src/constants/notification_urgencies.ts +7 -0
- package/src/constants/payment_types.test.ts +5 -0
- package/src/constants/payment_types.ts +10 -0
- package/src/constants/platform.test.ts +15 -0
- package/src/constants/platform.ts +6 -0
- package/src/constants/product_types.test.ts +6 -0
- package/src/constants/product_types.ts +25 -0
- package/src/constants/rights.test.ts +5 -0
- package/src/constants/rights.ts +5 -0
- package/src/constants/robots_meta_directives.test.ts +5 -0
- package/src/constants/robots_meta_directives.ts +11 -0
- package/src/constants/roles.test.ts +5 -0
- package/src/constants/roles.ts +38 -0
- package/src/constants/shipment_companies.test.ts +5 -0
- package/src/constants/shipment_companies.ts +18 -0
- package/src/constants/shipment_services.test.ts +5 -0
- package/src/constants/shipment_services.ts +3 -0
- package/src/constants/system_roles.test.ts +5 -0
- package/src/constants/system_roles.ts +3 -0
- package/src/constants/theme_foundations.test.ts +5 -0
- package/src/constants/theme_foundations.ts +6 -0
- package/src/constants/theme_status.test.ts +5 -0
- package/src/constants/theme_status.ts +5 -0
- package/src/constants/user_types.test.ts +5 -0
- package/src/constants/user_types.ts +17 -0
- package/src/constants/white_label_accessibilities.test.ts +5 -0
- package/src/constants/white_label_accessibilities.ts +6 -0
- package/src/cookie.test.ts +11 -0
- package/src/cookie.ts +16 -0
- package/src/entities/address.test.ts +7 -0
- package/src/entities/address.ts +65 -0
- package/src/entities/assignment.test.ts +39 -0
- package/src/entities/assignment.ts +92 -0
- package/src/entities/automatic_payment_relationship.test.ts +8 -0
- package/src/entities/automatic_payment_relationship.ts +26 -0
- package/src/entities/backup.test.ts +7 -0
- package/src/entities/backup.ts +14 -0
- package/src/entities/bank.test.ts +7 -0
- package/src/entities/bank.ts +45 -0
- package/src/entities/cart.test.ts +50 -0
- package/src/entities/cart.ts +89 -0
- package/src/entities/cart_item.test.ts +33 -0
- package/src/entities/cart_item.ts +77 -0
- package/src/entities/cart_shipment_group.ts +21 -0
- package/src/entities/cart_shipment_quote.ts +33 -0
- package/src/entities/category.test.ts +57 -0
- package/src/entities/category.ts +37 -0
- package/src/entities/company.test.ts +7 -0
- package/src/entities/company.ts +275 -0
- package/src/entities/company_invitation.test.ts +7 -0
- package/src/entities/company_invitation.ts +33 -0
- package/src/entities/component.test.ts +14 -0
- package/src/entities/component.ts +92 -0
- package/src/entities/component_tag.test.ts +7 -0
- package/src/entities/component_tag.ts +17 -0
- package/src/entities/component_version.test.ts +7 -0
- package/src/entities/component_version.ts +30 -0
- package/src/entities/country_tax.test.ts +13 -0
- package/src/entities/country_tax.ts +46 -0
- package/src/entities/discount.test.ts +18 -0
- package/src/entities/discount.ts +34 -0
- package/src/entities/discount_group.test.ts +7 -0
- package/src/entities/discount_group.ts +28 -0
- package/src/entities/domain.test.ts +79 -0
- package/src/entities/domain.ts +246 -0
- package/src/entities/domain_invitation.test.ts +7 -0
- package/src/entities/domain_invitation.ts +36 -0
- package/src/entities/domain_tag.test.ts +7 -0
- package/src/entities/domain_tag.ts +42 -0
- package/src/entities/draft.test.ts +43 -0
- package/src/entities/draft.ts +88 -0
- package/src/entities/draft_comment.test.ts +7 -0
- package/src/entities/draft_comment.ts +54 -0
- package/src/entities/draft_template.test.ts +7 -0
- package/src/entities/draft_template.ts +40 -0
- package/src/entities/email_address.test.ts +7 -0
- package/src/entities/email_address.ts +24 -0
- package/src/entities/email_counter.test.ts +7 -0
- package/src/entities/email_counter.ts +20 -0
- package/src/entities/enrolled_domain.test.ts +7 -0
- package/src/entities/enrolled_domain.ts +40 -0
- package/src/entities/exchange_rate.test.ts +7 -0
- package/src/entities/exchange_rate.ts +22 -0
- package/src/entities/file.test.ts +43 -0
- package/src/entities/file.ts +172 -0
- package/src/entities/internal_tag.test.ts +7 -0
- package/src/entities/internal_tag.ts +51 -0
- package/src/entities/inventory.test.ts +28 -0
- package/src/entities/inventory.ts +56 -0
- package/src/entities/inventory_unit_variation.test.ts +7 -0
- package/src/entities/inventory_unit_variation.ts +29 -0
- package/src/entities/invoice.test.ts +43 -0
- package/src/entities/invoice.ts +179 -0
- package/src/entities/item.test.ts +19 -0
- package/src/entities/item.ts +44 -0
- package/src/entities/job.test.ts +95 -0
- package/src/entities/job.ts +349 -0
- package/src/entities/job_comment.test.ts +7 -0
- package/src/entities/job_comment.ts +50 -0
- package/src/entities/matching_inventory.ts +29 -0
- package/src/entities/menu.test.ts +7 -0
- package/src/entities/menu.ts +30 -0
- package/src/entities/menu_item.test.ts +7 -0
- package/src/entities/menu_item.ts +29 -0
- package/src/entities/notification.test.ts +7 -0
- package/src/entities/notification.ts +99 -0
- package/src/entities/page.test.ts +7 -0
- package/src/entities/page.ts +32 -0
- package/src/entities/payment.test.ts +19 -0
- package/src/entities/payment.ts +65 -0
- package/src/entities/payment_device.test.ts +7 -0
- package/src/entities/payment_device.ts +30 -0
- package/src/entities/phone_number.test.ts +7 -0
- package/src/entities/phone_number.ts +36 -0
- package/src/entities/product.test.ts +750 -0
- package/src/entities/product.ts +427 -0
- package/src/entities/production_comment.test.ts +7 -0
- package/src/entities/production_comment.ts +50 -0
- package/src/entities/quote.test.ts +98 -0
- package/src/entities/quote.ts +140 -0
- package/src/entities/quote_item.test.ts +50 -0
- package/src/entities/quote_item.ts +71 -0
- package/src/entities/seo_domain_page.test.ts +7 -0
- package/src/entities/seo_domain_page.ts +33 -0
- package/src/entities/session.test.ts +7 -0
- package/src/entities/session.ts +28 -0
- package/src/entities/shipment.test.ts +24 -0
- package/src/entities/shipment.ts +185 -0
- package/src/entities/shipment_item.test.ts +7 -0
- package/src/entities/shipment_item.ts +15 -0
- package/src/entities/shipment_item_fulfillment.test.ts +8 -0
- package/src/entities/shipment_item_fulfillment.ts +15 -0
- package/src/entities/shipment_method.test.ts +7 -0
- package/src/entities/shipment_method.ts +61 -0
- package/src/entities/shipment_method_variation.test.ts +7 -0
- package/src/entities/shipment_method_variation.ts +39 -0
- package/src/entities/short_url.test.ts +7 -0
- package/src/entities/short_url.ts +36 -0
- package/src/entities/subscription_plan.test.ts +7 -0
- package/src/entities/subscription_plan.ts +73 -0
- package/src/entities/supply_domain.test.ts +7 -0
- package/src/entities/supply_domain.ts +27 -0
- package/src/entities/system_role.test.ts +7 -0
- package/src/entities/system_role.ts +17 -0
- package/src/entities/theme.test.ts +38 -0
- package/src/entities/theme.ts +267 -0
- package/src/entities/theme_css_setting.test.ts +7 -0
- package/src/entities/theme_css_setting.ts +23 -0
- package/src/entities/user.test.ts +154 -0
- package/src/entities/user.ts +394 -0
- package/src/entities/user_company.test.ts +7 -0
- package/src/entities/user_company.ts +27 -0
- package/src/entities/variation.test.ts +7 -0
- package/src/entities/variation.ts +61 -0
- package/src/entities/variation_field.test.ts +76 -0
- package/src/entities/variation_field.ts +169 -0
- package/src/entities/variation_fields_option.test.ts +46 -0
- package/src/entities/variation_fields_option.ts +95 -0
- package/src/entities/variation_option.test.ts +7 -0
- package/src/entities/variation_option.ts +52 -0
- package/src/entities/variations_group.test.ts +7 -0
- package/src/entities/variations_group.ts +41 -0
- package/src/entity.ts +1002 -0
- package/src/merchi.test.ts +25 -0
- package/src/merchi.ts +379 -0
- package/src/request.test.ts +43 -0
- package/src/request.ts +124 -0
- package/src/test_util.ts +18 -0
- package/src/toasts.test.ts +38 -0
- package/src/toasts.ts +34 -0
- package/src/util/float.ts +12 -0
- package/src/util/query_string.test.ts +7 -0
- package/src/util/query_string.ts +11 -0
- package/src/util/validation.test.ts +16 -0
- package/src/util/validation.ts +2 -0
- package/src/uuid.test.ts +15 -0
- package/src/uuid.ts +8 -0
- package/tsconfig.json +23 -0
- package/webpack.config.cjs +27 -0
|
@@ -0,0 +1,811 @@
|
|
|
1
|
+
import { Merchi } from '../merchi';
|
|
2
|
+
import { setup, mockFetch } from '../test_util';
|
|
3
|
+
import { Role } from '../constants/roles';
|
|
4
|
+
import { NotificationSection } from '../constants/notification_sections';
|
|
5
|
+
import { NotificationType } from '../constants/notification_types';
|
|
6
|
+
import { SerialiseMethod } from '../entity';
|
|
7
|
+
setup();
|
|
8
|
+
test('can make product', function () {
|
|
9
|
+
var merchi = new Merchi();
|
|
10
|
+
var product = new merchi.Product();
|
|
11
|
+
expect(product).toBeTruthy();
|
|
12
|
+
});
|
|
13
|
+
test('can get and set id', function () {
|
|
14
|
+
var merchi = new Merchi();
|
|
15
|
+
var product = new merchi.Product();
|
|
16
|
+
product.id = 2;
|
|
17
|
+
expect(product.id).toBe(2);
|
|
18
|
+
});
|
|
19
|
+
test('can get and set name', function () {
|
|
20
|
+
var merchi = new Merchi();
|
|
21
|
+
var product = new merchi.Product();
|
|
22
|
+
product.name = 'example';
|
|
23
|
+
expect(product.name).toBe('example');
|
|
24
|
+
});
|
|
25
|
+
test('can get and set featureImage', function () {
|
|
26
|
+
var merchi = new Merchi();
|
|
27
|
+
var product = new merchi.Product();
|
|
28
|
+
var file = new merchi.MerchiFile();
|
|
29
|
+
product.featureImage = file;
|
|
30
|
+
expect(product.featureImage).toBe(file);
|
|
31
|
+
});
|
|
32
|
+
test('can get and set domain', function () {
|
|
33
|
+
var merchi = new Merchi();
|
|
34
|
+
var product = new merchi.Product();
|
|
35
|
+
var domain = new merchi.Domain();
|
|
36
|
+
product.domain = domain;
|
|
37
|
+
expect(product.domain).toBe(domain);
|
|
38
|
+
product.domain = undefined;
|
|
39
|
+
expect(product.domain).toBe(undefined);
|
|
40
|
+
});
|
|
41
|
+
test('can fetch product from server', function () {
|
|
42
|
+
var merchi = new Merchi();
|
|
43
|
+
var testName = 'S7qHUfV_dr5l';
|
|
44
|
+
mockFetch(true, {
|
|
45
|
+
'product': {
|
|
46
|
+
'name': testName
|
|
47
|
+
}
|
|
48
|
+
}, 200);
|
|
49
|
+
return merchi.Product.get(1).then(function (product) {
|
|
50
|
+
return expect(product.name).toBe(testName);
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
test('can fetch with explicit session token', function () {
|
|
54
|
+
var testToken = 'YrDwzmh8&QGtAfg9quh(4QfSlE^RPXWl';
|
|
55
|
+
var merchi = new Merchi(testToken);
|
|
56
|
+
var testName = 'S7qHUfV_dr5l';
|
|
57
|
+
mockFetch(true, {
|
|
58
|
+
'product': {
|
|
59
|
+
'name': testName
|
|
60
|
+
}
|
|
61
|
+
}, 200);
|
|
62
|
+
return merchi.Product.get(1).then(function (product) {
|
|
63
|
+
return expect(product.name).toBe(testName);
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
test('can specify options in request', function () {
|
|
67
|
+
var merchi = new Merchi();
|
|
68
|
+
var testName = 'S7qHUfV_dr5l';
|
|
69
|
+
var fetch = mockFetch(true, {
|
|
70
|
+
'product': {
|
|
71
|
+
'name': testName
|
|
72
|
+
}
|
|
73
|
+
}, 200);
|
|
74
|
+
var options = {
|
|
75
|
+
includeArchived: true,
|
|
76
|
+
withRights: true
|
|
77
|
+
};
|
|
78
|
+
var invocation = merchi.Product.get(1, options).then(function (product) {
|
|
79
|
+
return expect(product.name).toBe(testName);
|
|
80
|
+
});
|
|
81
|
+
var correct = [['include_archived', 'true']];
|
|
82
|
+
expect(fetch.mock.calls[0][1]['query']).toEqual(correct);
|
|
83
|
+
return invocation;
|
|
84
|
+
});
|
|
85
|
+
test('can specify options in create request', function () {
|
|
86
|
+
var merchi = new Merchi();
|
|
87
|
+
var testName = 'S7qHUfV_dr5l';
|
|
88
|
+
var fetch = mockFetch(true, {
|
|
89
|
+
'product': {
|
|
90
|
+
'name': testName
|
|
91
|
+
}
|
|
92
|
+
}, 200);
|
|
93
|
+
var options = {
|
|
94
|
+
embed: {},
|
|
95
|
+
withRights: true
|
|
96
|
+
};
|
|
97
|
+
var product = new merchi.Product();
|
|
98
|
+
var invocation = product.create(options).then(function (product) {
|
|
99
|
+
return expect(product.name).toBe(testName);
|
|
100
|
+
});
|
|
101
|
+
var correct = [['embed', '{}']];
|
|
102
|
+
expect(fetch.mock.calls[0][1]['query']).toEqual(correct);
|
|
103
|
+
return invocation;
|
|
104
|
+
});
|
|
105
|
+
test('can specify options in save request', function () {
|
|
106
|
+
var merchi = new Merchi();
|
|
107
|
+
var testName = 'S7qHUfV_dr5l';
|
|
108
|
+
var fetch = mockFetch(true, {
|
|
109
|
+
'product': {
|
|
110
|
+
'name': testName
|
|
111
|
+
}
|
|
112
|
+
}, 200);
|
|
113
|
+
var options = {
|
|
114
|
+
embed: {},
|
|
115
|
+
withRights: true
|
|
116
|
+
};
|
|
117
|
+
var product = new merchi.Product();
|
|
118
|
+
var invocation = product.save(options).then(function (product) {
|
|
119
|
+
return expect(product.name).toBe(testName);
|
|
120
|
+
});
|
|
121
|
+
var correct = [['embed', '{}']];
|
|
122
|
+
expect(fetch.mock.calls[0][1]['query']).toEqual(correct);
|
|
123
|
+
return invocation;
|
|
124
|
+
});
|
|
125
|
+
test('can specify options in delete request', function () {
|
|
126
|
+
var merchi = new Merchi();
|
|
127
|
+
var testName = 'S7qHUfV_dr5l';
|
|
128
|
+
var fetch = mockFetch(true, {
|
|
129
|
+
'product': {
|
|
130
|
+
'name': testName
|
|
131
|
+
}
|
|
132
|
+
}, 200);
|
|
133
|
+
var options = {
|
|
134
|
+
withRights: true
|
|
135
|
+
};
|
|
136
|
+
var product = new merchi.Product();
|
|
137
|
+
var invocation = product["delete"](options);
|
|
138
|
+
var correct = [];
|
|
139
|
+
expect(fetch.mock.calls[0][1]['query']).toEqual(correct);
|
|
140
|
+
return invocation;
|
|
141
|
+
});
|
|
142
|
+
test('can specify embed options in recover request', function () {
|
|
143
|
+
var merchi = new Merchi();
|
|
144
|
+
var testName = 'S7qHUfV_dr5l';
|
|
145
|
+
var fetch = mockFetch(true, {
|
|
146
|
+
'product': {
|
|
147
|
+
'name': testName
|
|
148
|
+
}
|
|
149
|
+
}, 200);
|
|
150
|
+
var options = {
|
|
151
|
+
embed: {}
|
|
152
|
+
};
|
|
153
|
+
var product = new merchi.Product();
|
|
154
|
+
var invocation = product.recover(options);
|
|
155
|
+
var correct = [['embed', '{}'], ['skip_rights', 'y']];
|
|
156
|
+
expect(fetch.mock.calls[0][1]['query']).toEqual(correct);
|
|
157
|
+
return invocation;
|
|
158
|
+
});
|
|
159
|
+
test('can specify skip_rights options in recover request', function () {
|
|
160
|
+
var merchi = new Merchi();
|
|
161
|
+
var testName = 'S7qHUfV_dr5l';
|
|
162
|
+
var fetch = mockFetch(true, {
|
|
163
|
+
'product': {
|
|
164
|
+
'name': testName
|
|
165
|
+
}
|
|
166
|
+
}, 200);
|
|
167
|
+
var options = {
|
|
168
|
+
withRights: true
|
|
169
|
+
};
|
|
170
|
+
var product = new merchi.Product();
|
|
171
|
+
var invocation = product.recover(options);
|
|
172
|
+
var correct = [];
|
|
173
|
+
expect(fetch.mock.calls[0][1]['query']).toEqual(correct);
|
|
174
|
+
return invocation;
|
|
175
|
+
});
|
|
176
|
+
test('can fetch product with category and domain', function () {
|
|
177
|
+
var merchi = new Merchi();
|
|
178
|
+
var testName = 'S7qHUfV_dr5l';
|
|
179
|
+
var categoryName = 'l3VfG#S+';
|
|
180
|
+
var categoryData = {
|
|
181
|
+
'name': categoryName
|
|
182
|
+
};
|
|
183
|
+
var domainData = {
|
|
184
|
+
'domain': 'example.com'
|
|
185
|
+
};
|
|
186
|
+
mockFetch(true, {
|
|
187
|
+
'product': {
|
|
188
|
+
'name': testName,
|
|
189
|
+
'categories': [categoryData],
|
|
190
|
+
'domain': domainData
|
|
191
|
+
}
|
|
192
|
+
}, 200);
|
|
193
|
+
var r = merchi.Product.get(1, {
|
|
194
|
+
'embed': {
|
|
195
|
+
'categories': {},
|
|
196
|
+
'domain': {}
|
|
197
|
+
}
|
|
198
|
+
});
|
|
199
|
+
return r.then(function (product) {
|
|
200
|
+
expect(product.name).toBe(testName);
|
|
201
|
+
expect(product.categories[0].name).toBe(categoryName);
|
|
202
|
+
var serialised = Array.from(product.toFormData().entries());
|
|
203
|
+
// although product has a name, that name is from the server, and therefore
|
|
204
|
+
// does not need to be serialised back to the server.
|
|
205
|
+
expect(serialised).toEqual([]);
|
|
206
|
+
// if we manually set the name, it's a different matter:
|
|
207
|
+
var manualName = 'caUHebUMlRvu2';
|
|
208
|
+
product.name = manualName;
|
|
209
|
+
var newSerialised = Array.from(product.toFormData().entries());
|
|
210
|
+
var correct = [['name', manualName]];
|
|
211
|
+
expect(newSerialised).toEqual(correct);
|
|
212
|
+
});
|
|
213
|
+
});
|
|
214
|
+
test('product with empty categories will not have count payload', function () {
|
|
215
|
+
var merchi = new Merchi();
|
|
216
|
+
var testName = 'S7qHUfV_dr5l';
|
|
217
|
+
mockFetch(true, {
|
|
218
|
+
'product': {
|
|
219
|
+
'name': testName,
|
|
220
|
+
'categories': []
|
|
221
|
+
}
|
|
222
|
+
}, 200);
|
|
223
|
+
var r = merchi.Product.get(1, {
|
|
224
|
+
'embed': {
|
|
225
|
+
'categories': {}
|
|
226
|
+
}
|
|
227
|
+
});
|
|
228
|
+
return r.then(function (product) {
|
|
229
|
+
var serialised = Array.from(product.toFormData().entries());
|
|
230
|
+
expect(serialised.length).toEqual(0);
|
|
231
|
+
});
|
|
232
|
+
});
|
|
233
|
+
test('product with zero categories erase will show in patch payload', function () {
|
|
234
|
+
var merchi = new Merchi();
|
|
235
|
+
var testName = 'S7qHUfV_dr5l';
|
|
236
|
+
var categoryName = 'l3VfG#S+';
|
|
237
|
+
var categoryData = {
|
|
238
|
+
'name': categoryName
|
|
239
|
+
};
|
|
240
|
+
mockFetch(true, {
|
|
241
|
+
'product': {
|
|
242
|
+
'name': testName,
|
|
243
|
+
'categories': [categoryData]
|
|
244
|
+
}
|
|
245
|
+
}, 200);
|
|
246
|
+
var r = merchi.Product.get(1, {
|
|
247
|
+
'embed': {
|
|
248
|
+
'categories': {}
|
|
249
|
+
}
|
|
250
|
+
});
|
|
251
|
+
return r.then(function (product) {
|
|
252
|
+
product.categories = [];
|
|
253
|
+
var serialised = Array.from(product.toFormData().entries());
|
|
254
|
+
var correct = [['categories-count', '0']];
|
|
255
|
+
expect(serialised).toEqual(correct);
|
|
256
|
+
});
|
|
257
|
+
});
|
|
258
|
+
test('can fetch product with category and explcit session', function () {
|
|
259
|
+
var testToken = 'YrDwzmh8&QGtAfg9quh(4QfSlE^RPXWl';
|
|
260
|
+
var merchi = new Merchi(testToken);
|
|
261
|
+
var testName = 'S7qHUfV_dr5l';
|
|
262
|
+
var categoryName = 'l3VfG#S+';
|
|
263
|
+
var categoryData = {
|
|
264
|
+
'name': categoryName
|
|
265
|
+
};
|
|
266
|
+
mockFetch(true, {
|
|
267
|
+
'product': {
|
|
268
|
+
'name': testName,
|
|
269
|
+
'categories': [categoryData]
|
|
270
|
+
}
|
|
271
|
+
}, 200);
|
|
272
|
+
var r = merchi.Product.get(1, {
|
|
273
|
+
'embed': {
|
|
274
|
+
'categories': {}
|
|
275
|
+
}
|
|
276
|
+
});
|
|
277
|
+
return r.then(function (product) {
|
|
278
|
+
expect(product.name).toBe(testName);
|
|
279
|
+
expect(product.categories[0].name).toBe(categoryName);
|
|
280
|
+
});
|
|
281
|
+
});
|
|
282
|
+
test('handle nonsense from server', function () {
|
|
283
|
+
var merchi = new Merchi();
|
|
284
|
+
// non existent property just ignored. no crash, no update
|
|
285
|
+
mockFetch(true, {
|
|
286
|
+
'product': {
|
|
287
|
+
'no such property!!!': 'unused'
|
|
288
|
+
}
|
|
289
|
+
}, 200);
|
|
290
|
+
merchi.Product.get(1);
|
|
291
|
+
});
|
|
292
|
+
test('can list products from server', function () {
|
|
293
|
+
var merchi = new Merchi();
|
|
294
|
+
mockFetch(true, {
|
|
295
|
+
'products': [{
|
|
296
|
+
'product': {
|
|
297
|
+
'name': 'p1'
|
|
298
|
+
}
|
|
299
|
+
}, {
|
|
300
|
+
'product': {
|
|
301
|
+
'name': 'p2'
|
|
302
|
+
}
|
|
303
|
+
}],
|
|
304
|
+
'available': 2,
|
|
305
|
+
'count': 2
|
|
306
|
+
}, 200);
|
|
307
|
+
return merchi.Product.list().then(function (_ref) {
|
|
308
|
+
var d = _ref.items,
|
|
309
|
+
md = _ref.metadata;
|
|
310
|
+
expect(d.length).toBe(2);
|
|
311
|
+
expect(d[0].name).toBe('p1');
|
|
312
|
+
expect(d[1].name).toBe('p2');
|
|
313
|
+
expect(md.available).toBe(2);
|
|
314
|
+
expect(d[0].categories).toBe(undefined);
|
|
315
|
+
});
|
|
316
|
+
});
|
|
317
|
+
test('can list products with serialise method with only id', function () {
|
|
318
|
+
var merchi = new Merchi();
|
|
319
|
+
var options = {
|
|
320
|
+
serialiseMethod: SerialiseMethod.ONLY_ID
|
|
321
|
+
};
|
|
322
|
+
var correct = [['serialise_method', 'only_id'], ['skip_rights', 'y']];
|
|
323
|
+
var fetch = mockFetch(true, {
|
|
324
|
+
'products': [{
|
|
325
|
+
'product': {
|
|
326
|
+
'id': 1
|
|
327
|
+
}
|
|
328
|
+
}, {
|
|
329
|
+
'product': {
|
|
330
|
+
'id': 2
|
|
331
|
+
}
|
|
332
|
+
}],
|
|
333
|
+
'available': 2,
|
|
334
|
+
'count': 2
|
|
335
|
+
}, 200);
|
|
336
|
+
merchi.Product.list(options);
|
|
337
|
+
expect(fetch.mock.calls[0][1]['query']).toEqual(correct);
|
|
338
|
+
});
|
|
339
|
+
test('can list products with options set', function () {
|
|
340
|
+
var merchi = new Merchi();
|
|
341
|
+
var options = {
|
|
342
|
+
as: 'a',
|
|
343
|
+
asRole: 2,
|
|
344
|
+
businessDomainsOnly: true,
|
|
345
|
+
categoryId: 2,
|
|
346
|
+
clientId: 349,
|
|
347
|
+
clientCompanyId: 124,
|
|
348
|
+
clientOnly: false,
|
|
349
|
+
companyCustomerId: 99,
|
|
350
|
+
companyId: 91,
|
|
351
|
+
companySupplierId: 100,
|
|
352
|
+
componentId: 37,
|
|
353
|
+
dateFrom: new Date(0),
|
|
354
|
+
dateTo: new Date(1),
|
|
355
|
+
doesNotHaveAdminDomain: false,
|
|
356
|
+
domainRoles: [Role.ADMIN],
|
|
357
|
+
domainTypes: [0, 1],
|
|
358
|
+
embed: {},
|
|
359
|
+
entityTypes: [0, 1],
|
|
360
|
+
exclude: [8],
|
|
361
|
+
excludeComponents: ['DomainInfo', 'DomainSettings'],
|
|
362
|
+
excludeDomains: [0, 1],
|
|
363
|
+
groupBuyForJobId: 88,
|
|
364
|
+
groupBuyOnly: false,
|
|
365
|
+
inbound: false,
|
|
366
|
+
includeOnly: [1],
|
|
367
|
+
inDomain: 2,
|
|
368
|
+
inDomainName: 'example.com',
|
|
369
|
+
inDomainRoles: [2],
|
|
370
|
+
isMaster: false,
|
|
371
|
+
isOrder: true,
|
|
372
|
+
isPrivate: false,
|
|
373
|
+
jobNotifiable: 1,
|
|
374
|
+
limit: 20,
|
|
375
|
+
managedDomainsOnly: true,
|
|
376
|
+
managedOnly: false,
|
|
377
|
+
managerId: 355,
|
|
378
|
+
masterProduct: 1,
|
|
379
|
+
memberOnly: false,
|
|
380
|
+
merchiOnly: false,
|
|
381
|
+
notificationJob: 27,
|
|
382
|
+
notificationRecipient: 87,
|
|
383
|
+
notificationType: NotificationType.DRAFT_SENT,
|
|
384
|
+
offset: 0,
|
|
385
|
+
orClientId: 123,
|
|
386
|
+
orClientCompanyId: 321,
|
|
387
|
+
order: 'asc',
|
|
388
|
+
originalOf: 1,
|
|
389
|
+
platformCategoryId: 3,
|
|
390
|
+
productTypes: [0, 1],
|
|
391
|
+
publicOnly: false,
|
|
392
|
+
q: 'example',
|
|
393
|
+
receiverId: 86,
|
|
394
|
+
relatedAssignment: 1,
|
|
395
|
+
relatedComponent: 1,
|
|
396
|
+
relatedDraft: 1,
|
|
397
|
+
relatedJob: 3,
|
|
398
|
+
relatedProduct: 45,
|
|
399
|
+
relatedUser: 55,
|
|
400
|
+
savedByUser: 24,
|
|
401
|
+
section: NotificationSection.JOB_INFO,
|
|
402
|
+
senderRole: Role.MANAGER,
|
|
403
|
+
shopifyOnly: false,
|
|
404
|
+
sort: 'name',
|
|
405
|
+
state: 'yes',
|
|
406
|
+
supplierResellOnly: false,
|
|
407
|
+
tab: 'job',
|
|
408
|
+
tags: [2, 3, 5],
|
|
409
|
+
tagsInternal: [2, 3, 5],
|
|
410
|
+
tagNames: ['a'],
|
|
411
|
+
teamOnly: false,
|
|
412
|
+
withRights: false
|
|
413
|
+
};
|
|
414
|
+
var fetch = mockFetch(true, {
|
|
415
|
+
'products': [{
|
|
416
|
+
'product': {
|
|
417
|
+
'name': 'p1'
|
|
418
|
+
}
|
|
419
|
+
}, {
|
|
420
|
+
'product': {
|
|
421
|
+
'name': 'p2'
|
|
422
|
+
}
|
|
423
|
+
}],
|
|
424
|
+
'available': 2,
|
|
425
|
+
'count': 2
|
|
426
|
+
}, 200);
|
|
427
|
+
var invocation = merchi.Product.list(options);
|
|
428
|
+
var correct = [['as', 'a'], ['as_role', '2'], ['business_domains_only', 'true'], ['category_id', '2'], ['client_company_id', '124'], ['client_id', '349'], ['client_only', 'false'], ['company_customer_id', '99'], ['company_id', '91'], ['company_supplier_id', '100'], ['component_id', '37'], ['date_from', '0'], ['date_to', '0'], ['does_not_have_admin_domain', 'false'], ['domain_roles', '1'], ['domain_types', '0,1'], ['embed', '{}'], ['entity_types', '0,1'], ['exclude', '8'], ['exclude_components', 'DomainInfo,DomainSettings'], ['exclude_domains', '0,1'], ['group_buy_for_job_id', '88'], ['group_buy_only', 'false'], ['in_domain', '2'], ['in_domain_name', 'example.com'], ['in_domain_roles', '[2]'], ['inbound', 'false'], ['include_only', '1'], ['is_master', 'false'], ['is_order', 'true'], ['is_private', 'false'], ['job_notifiable', '1'], ['limit', '20'], ['managed_domains_only', 'true'], ['managed_only', 'false'], ['manager_id', '355'], ['master_product', '1'], ['member_only', 'false'], ['merchi_only', 'false'], ['notification_job', '27'], ['notification_recipient', '87'], ['notification_type', '1'], ['offset', '0'], ['or_client_company_id', '321'], ['or_client_id', '123'], ['order', 'asc'], ['original_of', '1'], ['platform_category_id', '3'], ['product_types', '0,1'], ['public_only', 'false'], ['q', 'example'], ['receiver_id', '86'], ['related_assignment', '1'], ['related_component', '1'], ['related_draft', '1'], ['related_job', '3'], ['related_product', '45'], ['related_user', '55'], ['saved_by_user', '24'], ['section', '2'], ['sender_role', '6'], ['skip_rights', 'y'], ['shopify_only', 'false'], ['sort', 'name'], ['state', 'yes'], ['supplier_resell_only', 'false'], ['tab', 'job'], ['tags', '2,3,5'], ['tags_internal', '2,3,5'], ['tag_names', 'a'], ['team_only', 'false']];
|
|
429
|
+
expect(fetch.mock.calls[0][1]['query'].sort(function (a, b) {
|
|
430
|
+
return a[0].localeCompare(b[0]);
|
|
431
|
+
})).toEqual(correct.sort(function (a, b) {
|
|
432
|
+
return a[0].localeCompare(b[0]);
|
|
433
|
+
}));
|
|
434
|
+
return invocation;
|
|
435
|
+
});
|
|
436
|
+
test('can list products from server with explicit session token', function () {
|
|
437
|
+
var testToken = 'YrDwzmh8&QGtAfg9quh(4QfSlE^RPXWl';
|
|
438
|
+
var merchi = new Merchi(testToken);
|
|
439
|
+
mockFetch(true, {
|
|
440
|
+
'products': [{
|
|
441
|
+
'product': {
|
|
442
|
+
'name': 'p1'
|
|
443
|
+
}
|
|
444
|
+
}, {
|
|
445
|
+
'product': {
|
|
446
|
+
'name': 'p2'
|
|
447
|
+
}
|
|
448
|
+
}],
|
|
449
|
+
'available': 2,
|
|
450
|
+
'count': 2
|
|
451
|
+
}, 200);
|
|
452
|
+
var options = {
|
|
453
|
+
order: 'desc'
|
|
454
|
+
};
|
|
455
|
+
return merchi.Product.list(options).then(function (_ref2) {
|
|
456
|
+
var d = _ref2.items,
|
|
457
|
+
md = _ref2.metadata;
|
|
458
|
+
expect(d.length).toBe(2);
|
|
459
|
+
expect(d[0].name).toBe('p1');
|
|
460
|
+
expect(d[1].name).toBe('p2');
|
|
461
|
+
expect(md.available).toBe(2);
|
|
462
|
+
expect(d[0].categories).toBe(undefined);
|
|
463
|
+
});
|
|
464
|
+
});
|
|
465
|
+
test('can list products from server with category', function () {
|
|
466
|
+
var merchi = new Merchi();
|
|
467
|
+
var categoriesData = [{
|
|
468
|
+
'name': 'c1'
|
|
469
|
+
}];
|
|
470
|
+
mockFetch(true, {
|
|
471
|
+
'products': [{
|
|
472
|
+
'product': {
|
|
473
|
+
'name': 'p1',
|
|
474
|
+
'categories': categoriesData
|
|
475
|
+
}
|
|
476
|
+
}, {
|
|
477
|
+
'product': {
|
|
478
|
+
'name': 'p2',
|
|
479
|
+
'categories': categoriesData
|
|
480
|
+
}
|
|
481
|
+
}],
|
|
482
|
+
'available': 2,
|
|
483
|
+
'count': 2
|
|
484
|
+
}, 200);
|
|
485
|
+
var r = merchi.Product.list({
|
|
486
|
+
'embed': {
|
|
487
|
+
'categories': {}
|
|
488
|
+
}
|
|
489
|
+
});
|
|
490
|
+
return r.then(function (_ref3) {
|
|
491
|
+
var d = _ref3.items,
|
|
492
|
+
md = _ref3.metadata;
|
|
493
|
+
expect(d.length).toBe(2);
|
|
494
|
+
expect(d[0].name).toBe('p1');
|
|
495
|
+
expect(d[1].name).toBe('p2');
|
|
496
|
+
expect(md.available).toBe(2);
|
|
497
|
+
expect(d[0].categories[0].name).toBe('c1');
|
|
498
|
+
});
|
|
499
|
+
});
|
|
500
|
+
test('can save product', function () {
|
|
501
|
+
var merchi = new Merchi();
|
|
502
|
+
var c1 = new merchi.Category();
|
|
503
|
+
var p = new merchi.Product();
|
|
504
|
+
var c2 = new merchi.Category();
|
|
505
|
+
var d = new merchi.Domain();
|
|
506
|
+
p.categories = [c2];
|
|
507
|
+
p.domain = d;
|
|
508
|
+
c1.products = [p];
|
|
509
|
+
c1.save();
|
|
510
|
+
d.domain = '3onrb6o4';
|
|
511
|
+
p.name = 'pHyz7ZucK#';
|
|
512
|
+
c2.name = '8&OaUsDgJ$ev3FYZ3';
|
|
513
|
+
p.save();
|
|
514
|
+
var fetch = mockFetch(true, {}, 200);
|
|
515
|
+
c1.save();
|
|
516
|
+
var correct = [['products-0-name', 'pHyz7ZucK#'], ['products-0-categories-0-name', '8&OaUsDgJ$ev3FYZ3'], ['products-0-categories-count', '1'], ['products-0-domain-0-domain', '3onrb6o4'], ['products-0-domain-count', '1'], ['products-count', '1']];
|
|
517
|
+
expect(Array.from(fetch.mock.calls[0][1]['body'].entries())).toEqual(correct);
|
|
518
|
+
});
|
|
519
|
+
test('can serialise product to form data understood by backend', function () {
|
|
520
|
+
var merchi = new Merchi();
|
|
521
|
+
var c1 = new merchi.Category();
|
|
522
|
+
var p = new merchi.Product();
|
|
523
|
+
var c2 = new merchi.Category();
|
|
524
|
+
var d = new merchi.Domain();
|
|
525
|
+
p.categories = [c2];
|
|
526
|
+
p.domain = d;
|
|
527
|
+
c1.products = [p];
|
|
528
|
+
c1.save();
|
|
529
|
+
d.domain = '3onrb6o4';
|
|
530
|
+
p.name = 'pHyz7ZucK#';
|
|
531
|
+
c2.name = '8&OaUsDgJ$ev3FYZ3';
|
|
532
|
+
var correct = [['name', 'pHyz7ZucK#'], ['categories-0-name', '8&OaUsDgJ$ev3FYZ3'], ['categories-count', '1'], ['domain-0-domain', '3onrb6o4'], ['domain-count', '1']];
|
|
533
|
+
expect(Array.from(p.toFormData().entries())).toEqual(correct);
|
|
534
|
+
});
|
|
535
|
+
test('undefined data will not be serialised', function () {
|
|
536
|
+
var merchi = new Merchi();
|
|
537
|
+
var p = new merchi.Product();
|
|
538
|
+
p.name = 'aaa';
|
|
539
|
+
p.fromJson({
|
|
540
|
+
name: undefined
|
|
541
|
+
});
|
|
542
|
+
expect(p.name).toEqual('aaa');
|
|
543
|
+
});
|
|
544
|
+
test('can convert product data json format', function () {
|
|
545
|
+
var merchi = new Merchi();
|
|
546
|
+
var p = new merchi.Product();
|
|
547
|
+
var d = new merchi.Domain();
|
|
548
|
+
var c1 = new merchi.Category();
|
|
549
|
+
c1.name = 'category 1';
|
|
550
|
+
var c2 = new merchi.Category();
|
|
551
|
+
c2.name = 'category 2';
|
|
552
|
+
p.name = 'product name';
|
|
553
|
+
d.domain = 'domain name';
|
|
554
|
+
p.domain = d;
|
|
555
|
+
p.categories = [c1, c2];
|
|
556
|
+
var correct = {
|
|
557
|
+
name: p.name,
|
|
558
|
+
domain: {
|
|
559
|
+
domain: d.domain
|
|
560
|
+
},
|
|
561
|
+
categories: [{
|
|
562
|
+
name: c1.name
|
|
563
|
+
}, {
|
|
564
|
+
name: c2.name
|
|
565
|
+
}]
|
|
566
|
+
};
|
|
567
|
+
expect(p.toJson()).toEqual(correct);
|
|
568
|
+
});
|
|
569
|
+
test('can clean dirty on purpose', function () {
|
|
570
|
+
var merchi = new Merchi();
|
|
571
|
+
var p = new merchi.Product();
|
|
572
|
+
var d = new merchi.Domain();
|
|
573
|
+
var c1 = new merchi.Category();
|
|
574
|
+
c1.name = 'category 1';
|
|
575
|
+
var c2 = new merchi.Category();
|
|
576
|
+
c2.name = 'category 2';
|
|
577
|
+
p.name = 'product name';
|
|
578
|
+
d.domain = 'domain name';
|
|
579
|
+
p.domain = d;
|
|
580
|
+
p.categories = [c1, c2];
|
|
581
|
+
p.featureImage = null;
|
|
582
|
+
p.id = 1;
|
|
583
|
+
var correct = [['id', '1']];
|
|
584
|
+
p.cleanDirty();
|
|
585
|
+
expect(Array.from(p.toFormData().entries())).toEqual(correct);
|
|
586
|
+
});
|
|
587
|
+
test('none relationship will be in data json', function () {
|
|
588
|
+
var merchi = new Merchi();
|
|
589
|
+
var p = new merchi.Product();
|
|
590
|
+
p.featureImage = null;
|
|
591
|
+
var correct = {
|
|
592
|
+
featureImage: null
|
|
593
|
+
};
|
|
594
|
+
expect(p.toJson()).toEqual(correct);
|
|
595
|
+
});
|
|
596
|
+
test('json serialisable in both directions', function () {
|
|
597
|
+
var json = {
|
|
598
|
+
name: 'product name',
|
|
599
|
+
categories: [{
|
|
600
|
+
name: 'c1'
|
|
601
|
+
}, {
|
|
602
|
+
name: 'c2'
|
|
603
|
+
}]
|
|
604
|
+
};
|
|
605
|
+
var merchi = new Merchi();
|
|
606
|
+
var p = new merchi.Product();
|
|
607
|
+
p.fromJson(json);
|
|
608
|
+
expect(p.toJson()).toEqual(json);
|
|
609
|
+
});
|
|
610
|
+
test('use from json to merge json into entity', function () {
|
|
611
|
+
var json = {
|
|
612
|
+
name: 'product name',
|
|
613
|
+
domain: {
|
|
614
|
+
domain: 'domain 1'
|
|
615
|
+
},
|
|
616
|
+
categories: [{
|
|
617
|
+
name: 'c1'
|
|
618
|
+
}, {
|
|
619
|
+
name: 'c2'
|
|
620
|
+
}]
|
|
621
|
+
};
|
|
622
|
+
var merchi = new Merchi();
|
|
623
|
+
var p = new merchi.Product();
|
|
624
|
+
p.fromJson(json);
|
|
625
|
+
var updatedJson = {
|
|
626
|
+
name: 'product new name',
|
|
627
|
+
domain: {
|
|
628
|
+
domain: 'domain 2'
|
|
629
|
+
},
|
|
630
|
+
categories: [{
|
|
631
|
+
name: 'a1'
|
|
632
|
+
}, {
|
|
633
|
+
name: 'c2'
|
|
634
|
+
}]
|
|
635
|
+
};
|
|
636
|
+
p.fromJson(updatedJson);
|
|
637
|
+
expect(p.name).toEqual('product new name');
|
|
638
|
+
if (p.domain !== undefined) {
|
|
639
|
+
expect(p.domain.domain).toEqual('domain 2');
|
|
640
|
+
} else {
|
|
641
|
+
expect(true).toBe(false);
|
|
642
|
+
}
|
|
643
|
+
if (p.categories !== undefined) {
|
|
644
|
+
expect(p.categories[0].name).toEqual('a1');
|
|
645
|
+
expect(p.categories[1].name).toEqual('c2');
|
|
646
|
+
} else {
|
|
647
|
+
expect(true).toBe(false);
|
|
648
|
+
}
|
|
649
|
+
});
|
|
650
|
+
test('use from json have options to ignore array type if it is wrong', function () {
|
|
651
|
+
var json = {
|
|
652
|
+
categories: '[Object]' // wrong array type
|
|
653
|
+
};
|
|
654
|
+
var merchi = new Merchi();
|
|
655
|
+
var p = new merchi.Product();
|
|
656
|
+
p.fromJson(json, {
|
|
657
|
+
arrayValueStrict: false
|
|
658
|
+
});
|
|
659
|
+
// categories will be ignored
|
|
660
|
+
expect(p.categories).toBe(undefined);
|
|
661
|
+
});
|
|
662
|
+
test('primary key always serialised', function () {
|
|
663
|
+
var merchi = new Merchi();
|
|
664
|
+
var testId = 42;
|
|
665
|
+
mockFetch(true, {
|
|
666
|
+
'product': {
|
|
667
|
+
'id': testId
|
|
668
|
+
}
|
|
669
|
+
}, 200);
|
|
670
|
+
return merchi.Product.get(1).then(function (product) {
|
|
671
|
+
var backData = Array.from(product.toFormData().entries());
|
|
672
|
+
var correct = [['id', '42']];
|
|
673
|
+
expect(backData).toEqual(correct);
|
|
674
|
+
});
|
|
675
|
+
});
|
|
676
|
+
test('orderable attribute request', function () {
|
|
677
|
+
var merchi = new Merchi();
|
|
678
|
+
var product = new merchi.Product();
|
|
679
|
+
var f = new merchi.MerchiFile();
|
|
680
|
+
f.id = 24;
|
|
681
|
+
product.id = 42;
|
|
682
|
+
product.images = [f];
|
|
683
|
+
product.updateOrder('images');
|
|
684
|
+
var correct = [['id', '42'], ['images-0-id', '24'], ['images-count', '1'], ['images-*updateOrder', 'true']];
|
|
685
|
+
var got = Array.from(product.toFormData().entries());
|
|
686
|
+
expect(got).toEqual(correct);
|
|
687
|
+
});
|
|
688
|
+
test('duplicate', function () {
|
|
689
|
+
var merchi = new Merchi();
|
|
690
|
+
var product = new merchi.Product();
|
|
691
|
+
var testName = 'qkc6fYD8HkR';
|
|
692
|
+
mockFetch(true, {
|
|
693
|
+
'product': {
|
|
694
|
+
'name': testName
|
|
695
|
+
}
|
|
696
|
+
}, 200);
|
|
697
|
+
return product.duplicate().then(function (clone) {
|
|
698
|
+
expect(clone.name).toEqual(testName);
|
|
699
|
+
});
|
|
700
|
+
});
|
|
701
|
+
test('primaryImage', function () {
|
|
702
|
+
var merchi = new Merchi();
|
|
703
|
+
var product = new merchi.Product();
|
|
704
|
+
var i1 = new merchi.MerchiFile();
|
|
705
|
+
var i2 = new merchi.MerchiFile();
|
|
706
|
+
expect(product.primaryImage).toThrow();
|
|
707
|
+
product.featureImage = i1;
|
|
708
|
+
expect(product.primaryImage).toThrow();
|
|
709
|
+
product.images = [i2];
|
|
710
|
+
expect(product.primaryImage()).toBe(i1);
|
|
711
|
+
product.featureImage = null;
|
|
712
|
+
expect(product.primaryImage()).toBe(i2);
|
|
713
|
+
product.images = [];
|
|
714
|
+
expect(product.primaryImage()).toBe(null);
|
|
715
|
+
});
|
|
716
|
+
test('hasGroupVariationFields', function () {
|
|
717
|
+
var merchi = new Merchi();
|
|
718
|
+
var product = new merchi.Product();
|
|
719
|
+
expect(product.hasGroupVariationFields).toThrow();
|
|
720
|
+
product.groupVariationFields = [];
|
|
721
|
+
expect(product.hasGroupVariationFields()).toBe(false);
|
|
722
|
+
product.groupVariationFields = [new merchi.VariationField()];
|
|
723
|
+
expect(product.hasGroupVariationFields()).toBe(true);
|
|
724
|
+
});
|
|
725
|
+
test('hasIndependentVariationFields', function () {
|
|
726
|
+
var merchi = new Merchi();
|
|
727
|
+
var product = new merchi.Product();
|
|
728
|
+
expect(product.hasIndependentVariationFields).toThrow();
|
|
729
|
+
product.independentVariationFields = [];
|
|
730
|
+
expect(product.hasIndependentVariationFields()).toBe(false);
|
|
731
|
+
product.independentVariationFields = [new merchi.VariationField()];
|
|
732
|
+
expect(product.hasIndependentVariationFields()).toBe(true);
|
|
733
|
+
});
|
|
734
|
+
test('allVariationFields', function () {
|
|
735
|
+
var merchi = new Merchi();
|
|
736
|
+
var product = new merchi.Product();
|
|
737
|
+
var vf1 = new merchi.VariationField();
|
|
738
|
+
var vf2 = new merchi.VariationField();
|
|
739
|
+
expect(product.allVariationFields).toThrow();
|
|
740
|
+
product.groupVariationFields = [vf1];
|
|
741
|
+
expect(product.allVariationFields).toThrow();
|
|
742
|
+
product.independentVariationFields = [vf2];
|
|
743
|
+
expect(product.allVariationFields()).toEqual([vf1, vf2]);
|
|
744
|
+
});
|
|
745
|
+
test('removeVariationField', function () {
|
|
746
|
+
var merchi = new Merchi();
|
|
747
|
+
var product = new merchi.Product();
|
|
748
|
+
var vf = new merchi.VariationField();
|
|
749
|
+
expect(function () {
|
|
750
|
+
return product.removeVariationField(vf);
|
|
751
|
+
}).toThrow();
|
|
752
|
+
vf.independent = false;
|
|
753
|
+
expect(function () {
|
|
754
|
+
return product.removeVariationField(vf);
|
|
755
|
+
}).toThrow();
|
|
756
|
+
product.independentVariationFields = [];
|
|
757
|
+
expect(function () {
|
|
758
|
+
return product.removeVariationField(vf);
|
|
759
|
+
}).toThrow();
|
|
760
|
+
product.groupVariationFields = [vf];
|
|
761
|
+
expect(function () {
|
|
762
|
+
return product.removeVariationField(vf);
|
|
763
|
+
}).toThrow();
|
|
764
|
+
vf.id = 1;
|
|
765
|
+
expect(product.removeVariationField(vf).length).toEqual(1);
|
|
766
|
+
expect(product.groupVariationFields.length).toEqual(0);
|
|
767
|
+
vf.independent = true;
|
|
768
|
+
product.independentVariationFields = [vf];
|
|
769
|
+
expect(product.removeVariationField(vf).length).toEqual(1);
|
|
770
|
+
expect(product.independentVariationFields.length).toEqual(0);
|
|
771
|
+
});
|
|
772
|
+
test('buildEmptyVariations', function () {
|
|
773
|
+
var merchi = new Merchi();
|
|
774
|
+
var product = new merchi.Product();
|
|
775
|
+
expect(product.buildEmptyVariations).toThrow();
|
|
776
|
+
product.independentVariationFields = [];
|
|
777
|
+
expect(product.buildEmptyVariations()).toEqual([]);
|
|
778
|
+
product.independentVariationFields = [new merchi.VariationField()];
|
|
779
|
+
product.independentVariationFields[0].defaultValue = '';
|
|
780
|
+
product.independentVariationFields[0].fieldType = 11;
|
|
781
|
+
product.independentVariationFields[0].variationCost = 2;
|
|
782
|
+
product.independentVariationFields[0].options = [];
|
|
783
|
+
expect(product.buildEmptyVariations().length).toEqual(1);
|
|
784
|
+
});
|
|
785
|
+
test('buildEmptyVariationGroup', function () {
|
|
786
|
+
var merchi = new Merchi();
|
|
787
|
+
var product = new merchi.Product();
|
|
788
|
+
expect(product.buildEmptyVariationGroup).toThrow();
|
|
789
|
+
product.groupVariationFields = [new merchi.VariationField()];
|
|
790
|
+
product.groupVariationFields[0].defaultValue = '';
|
|
791
|
+
product.groupVariationFields[0].fieldType = 11;
|
|
792
|
+
product.groupVariationFields[0].variationCost = 2;
|
|
793
|
+
product.groupVariationFields[0].options = [];
|
|
794
|
+
expect(product.buildEmptyVariationGroup().groupCost).toEqual(0);
|
|
795
|
+
});
|
|
796
|
+
test('delete single subentitiy', function () {
|
|
797
|
+
var merchi = new Merchi();
|
|
798
|
+
var p = new merchi.Product();
|
|
799
|
+
p.id = 42;
|
|
800
|
+
p.propertiesMap.get('featureImage').currentValue = null;
|
|
801
|
+
p.propertiesMap.get('featureImage').dirty = false;
|
|
802
|
+
var correct = [['id', '42'], ['featureImage-0-id', '-1'], ['featureImage-count', '1']];
|
|
803
|
+
var serialised1 = Array.from(p.toFormData({
|
|
804
|
+
excludeOld: false
|
|
805
|
+
}).entries());
|
|
806
|
+
expect(serialised1).toEqual(correct);
|
|
807
|
+
p.toFormData();
|
|
808
|
+
p.featureImage = null; // specifies that p.featureImage should be deleted
|
|
809
|
+
var serialised2 = Array.from(p.toFormData().entries());
|
|
810
|
+
expect(serialised2).toEqual(correct);
|
|
811
|
+
});
|