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