@daffodil/customer 0.0.0-PLACEHOLDER

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.
Files changed (212) hide show
  1. package/.eslintrc.js +52 -0
  2. package/README.md +9 -0
  3. package/driver/in-memory/ng-package.json +8 -0
  4. package/driver/in-memory/package.json +3 -0
  5. package/driver/in-memory/src/backend/address.service.spec.ts +199 -0
  6. package/driver/in-memory/src/backend/address.service.ts +123 -0
  7. package/driver/in-memory/src/backend/customer.service.spec.ts +119 -0
  8. package/driver/in-memory/src/backend/customer.service.ts +126 -0
  9. package/driver/in-memory/src/driver/address.service.spec.ts +153 -0
  10. package/driver/in-memory/src/driver/address.service.ts +49 -0
  11. package/driver/in-memory/src/driver/customer-driver.module.ts +38 -0
  12. package/driver/in-memory/src/driver/customer.service.spec.ts +131 -0
  13. package/driver/in-memory/src/driver/customer.service.ts +46 -0
  14. package/driver/in-memory/src/index.ts +1 -0
  15. package/driver/in-memory/src/public_api.ts +5 -0
  16. package/driver/magento/ng-package.json +8 -0
  17. package/driver/magento/package.json +3 -0
  18. package/driver/magento/src/address.service.spec.ts +398 -0
  19. package/driver/magento/src/address.service.ts +147 -0
  20. package/driver/magento/src/customer-driver.module.ts +41 -0
  21. package/driver/magento/src/customer.service.spec.ts +348 -0
  22. package/driver/magento/src/customer.service.ts +101 -0
  23. package/driver/magento/src/errors/map.ts +6 -0
  24. package/driver/magento/src/errors/public_api.ts +1 -0
  25. package/driver/magento/src/errors/transform.ts +40 -0
  26. package/driver/magento/src/index.ts +1 -0
  27. package/driver/magento/src/models/gender.enum.ts +4 -0
  28. package/driver/magento/src/models/public_api.ts +4 -0
  29. package/driver/magento/src/models/requests/address-attribute-input.type.ts +4 -0
  30. package/driver/magento/src/models/requests/address-input.type.ts +23 -0
  31. package/driver/magento/src/models/requests/address-region-input.type.ts +8 -0
  32. package/driver/magento/src/models/requests/customer-input.type.ts +15 -0
  33. package/driver/magento/src/models/requests/public_api.ts +4 -0
  34. package/driver/magento/src/models/responses/change-email.type.ts +7 -0
  35. package/driver/magento/src/models/responses/change-password.type.ts +5 -0
  36. package/driver/magento/src/models/responses/create-customer-address.type.ts +5 -0
  37. package/driver/magento/src/models/responses/customer-address.type.ts +18 -0
  38. package/driver/magento/src/models/responses/customer.type.ts +9 -0
  39. package/driver/magento/src/models/responses/delete-customer-address.type.ts +3 -0
  40. package/driver/magento/src/models/responses/get-customer-addresses.type.ts +5 -0
  41. package/driver/magento/src/models/responses/get-customer.type.ts +5 -0
  42. package/driver/magento/src/models/responses/public_api.ts +10 -0
  43. package/driver/magento/src/models/responses/update-customer-address.type.ts +5 -0
  44. package/driver/magento/src/models/responses/update-customer.type.ts +7 -0
  45. package/driver/magento/src/public_api.ts +9 -0
  46. package/driver/magento/src/queries/change-password.ts +14 -0
  47. package/driver/magento/src/queries/create-customer-address.ts +12 -0
  48. package/driver/magento/src/queries/delete-customer-address.ts +7 -0
  49. package/driver/magento/src/queries/fragments/customer-address.ts +21 -0
  50. package/driver/magento/src/queries/fragments/customer.ts +16 -0
  51. package/driver/magento/src/queries/fragments/public_api.ts +2 -0
  52. package/driver/magento/src/queries/get-customer-addresses.ts +16 -0
  53. package/driver/magento/src/queries/get-customer.ts +14 -0
  54. package/driver/magento/src/queries/public_api.ts +10 -0
  55. package/driver/magento/src/queries/update-customer-address.ts +12 -0
  56. package/driver/magento/src/queries/update-customer.ts +16 -0
  57. package/driver/magento/src/queries/update-email.ts +16 -0
  58. package/driver/magento/src/transforms/public_api.ts +2 -0
  59. package/driver/magento/src/transforms/requests/address-input.spec.ts +42 -0
  60. package/driver/magento/src/transforms/requests/address-input.ts +25 -0
  61. package/driver/magento/src/transforms/requests/customer-input.spec.ts +28 -0
  62. package/driver/magento/src/transforms/requests/customer-input.ts +9 -0
  63. package/driver/magento/src/transforms/requests/public_api.ts +2 -0
  64. package/driver/magento/src/transforms/responses/customer-address.spec.ts +39 -0
  65. package/driver/magento/src/transforms/responses/customer-address.ts +21 -0
  66. package/driver/magento/src/transforms/responses/customer.spec.ts +33 -0
  67. package/driver/magento/src/transforms/responses/customer.ts +13 -0
  68. package/driver/magento/src/transforms/responses/public_api.ts +2 -0
  69. package/driver/magento/src/validators/change-email.spec.ts +45 -0
  70. package/driver/magento/src/validators/change-email.ts +13 -0
  71. package/driver/magento/src/validators/change-password.spec.ts +45 -0
  72. package/driver/magento/src/validators/change-password.ts +13 -0
  73. package/driver/magento/src/validators/create-customer-address.spec.ts +43 -0
  74. package/driver/magento/src/validators/create-customer-address.ts +13 -0
  75. package/driver/magento/src/validators/delete-customer-address.spec.ts +38 -0
  76. package/driver/magento/src/validators/delete-customer-address.ts +13 -0
  77. package/driver/magento/src/validators/get-customer-addresses.spec.ts +43 -0
  78. package/driver/magento/src/validators/get-customer-addresses.ts +13 -0
  79. package/driver/magento/src/validators/get-customer.spec.ts +43 -0
  80. package/driver/magento/src/validators/get-customer.ts +13 -0
  81. package/driver/magento/src/validators/public_api.ts +8 -0
  82. package/driver/magento/src/validators/update-customer-address.spec.ts +43 -0
  83. package/driver/magento/src/validators/update-customer-address.ts +13 -0
  84. package/driver/magento/src/validators/update-customer.spec.ts +45 -0
  85. package/driver/magento/src/validators/update-customer.ts +13 -0
  86. package/driver/magento/testing/ng-package.json +8 -0
  87. package/driver/magento/testing/package.json +3 -0
  88. package/driver/magento/testing/src/factories/address.factory.spec.ts +45 -0
  89. package/driver/magento/testing/src/factories/address.factory.ts +35 -0
  90. package/driver/magento/testing/src/factories/customer.factory.spec.ts +36 -0
  91. package/driver/magento/testing/src/factories/customer.factory.ts +38 -0
  92. package/driver/magento/testing/src/factories/public_api.ts +2 -0
  93. package/driver/magento/testing/src/index.ts +1 -0
  94. package/driver/magento/testing/src/public_api.ts +1 -0
  95. package/driver/ng-package.json +8 -0
  96. package/driver/package.json +3 -0
  97. package/driver/src/errors/address-not-found.ts +17 -0
  98. package/driver/src/errors/codes.ts +11 -0
  99. package/driver/src/errors/default-billing-address-deletion.ts +17 -0
  100. package/driver/src/errors/default-shipping-address-deletion.ts +17 -0
  101. package/driver/src/errors/invalid-api-response.ts +17 -0
  102. package/driver/src/errors/map.ts +26 -0
  103. package/driver/src/errors/public_api.ts +18 -0
  104. package/driver/src/index.ts +1 -0
  105. package/driver/src/interfaces/address-service.interface.ts +42 -0
  106. package/driver/src/interfaces/customer-service.interface.ts +38 -0
  107. package/driver/src/public_api.ts +10 -0
  108. package/driver/testing/ng-package.json +8 -0
  109. package/driver/testing/package.json +3 -0
  110. package/driver/testing/src/drivers/address.service.spec.ts +61 -0
  111. package/driver/testing/src/drivers/address.service.ts +45 -0
  112. package/driver/testing/src/drivers/customer-driver.module.ts +39 -0
  113. package/driver/testing/src/drivers/customer.service.spec.ts +54 -0
  114. package/driver/testing/src/drivers/customer.service.ts +40 -0
  115. package/driver/testing/src/drivers/public_api.ts +3 -0
  116. package/driver/testing/src/index.ts +1 -0
  117. package/driver/testing/src/public_api.ts +1 -0
  118. package/karma.conf.js +11 -0
  119. package/ng-package.json +7 -0
  120. package/ng-package.prod.json +7 -0
  121. package/package.json +42 -0
  122. package/routing/ng-package.json +8 -0
  123. package/routing/package.json +3 -0
  124. package/routing/src/guards/clear-errors.guard.spec.ts +39 -0
  125. package/routing/src/guards/clear-errors.guard.ts +22 -0
  126. package/routing/src/guards/public_api.ts +1 -0
  127. package/routing/src/index.ts +1 -0
  128. package/routing/src/public_api.ts +2 -0
  129. package/routing/src/resolvers/customer.resolver.spec.ts +62 -0
  130. package/routing/src/resolvers/customer.resolver.ts +29 -0
  131. package/routing/src/resolvers/public_api.ts +1 -0
  132. package/src/index.ts +1 -0
  133. package/src/injection-tokens/error-matcher.token.ts +12 -0
  134. package/src/injection-tokens/public_api.ts +1 -0
  135. package/src/models/address.type.ts +16 -0
  136. package/src/models/customer.type.ts +29 -0
  137. package/src/models/public_api.ts +2 -0
  138. package/src/public_api.ts +2 -0
  139. package/state/ng-package.json +8 -0
  140. package/state/package.json +3 -0
  141. package/state/src/actions/address.actions.ts +200 -0
  142. package/state/src/actions/customer.actions.ts +163 -0
  143. package/state/src/actions/public_api.ts +2 -0
  144. package/state/src/customer.module.ts +22 -0
  145. package/state/src/effects/address.effects.spec.ts +267 -0
  146. package/state/src/effects/address.effects.ts +118 -0
  147. package/state/src/effects/customer.effects.spec.ts +210 -0
  148. package/state/src/effects/customer.effects.ts +105 -0
  149. package/state/src/facades/address/facade.spec.ts +81 -0
  150. package/state/src/facades/address/facade.ts +77 -0
  151. package/state/src/facades/address/interface.ts +17 -0
  152. package/state/src/facades/customer/facade.spec.ts +81 -0
  153. package/state/src/facades/customer/facade.ts +61 -0
  154. package/state/src/facades/customer/interface.ts +16 -0
  155. package/state/src/facades/public_api.ts +4 -0
  156. package/state/src/index.ts +1 -0
  157. package/state/src/models/address.type.ts +4 -0
  158. package/state/src/models/public_api.ts +1 -0
  159. package/state/src/public_api.ts +7 -0
  160. package/state/src/reducers/address/initial-state.ts +8 -0
  161. package/state/src/reducers/address/public_api.ts +3 -0
  162. package/state/src/reducers/address/reducer.spec.ts +422 -0
  163. package/state/src/reducers/address/reducer.ts +51 -0
  164. package/state/src/reducers/address/type.ts +6 -0
  165. package/state/src/reducers/address-entities/adapter.ts +17 -0
  166. package/state/src/reducers/address-entities/public_api.ts +2 -0
  167. package/state/src/reducers/address-entities/reducer.ts +95 -0
  168. package/state/src/reducers/customer/adapter.spec.ts +51 -0
  169. package/state/src/reducers/customer/adapter.ts +34 -0
  170. package/state/src/reducers/customer/initial-state.ts +11 -0
  171. package/state/src/reducers/customer/interface.ts +10 -0
  172. package/state/src/reducers/customer/public_api.ts +4 -0
  173. package/state/src/reducers/customer/reducer.spec.ts +396 -0
  174. package/state/src/reducers/customer/reducer.ts +65 -0
  175. package/state/src/reducers/public_api.ts +10 -0
  176. package/state/src/reducers/reducers.interface.ts +31 -0
  177. package/state/src/reducers/store-feature-key.ts +4 -0
  178. package/state/src/reducers/token/extra.token.spec.ts +35 -0
  179. package/state/src/reducers/token/extra.token.ts +42 -0
  180. package/state/src/reducers/token/public_api.ts +4 -0
  181. package/state/src/reducers/token/reducers.token.spec.ts +64 -0
  182. package/state/src/reducers/token/reducers.token.ts +39 -0
  183. package/state/src/selectors/address/selector.spec.ts +105 -0
  184. package/state/src/selectors/address/selector.ts +66 -0
  185. package/state/src/selectors/customer/selector.spec.ts +80 -0
  186. package/state/src/selectors/customer/selector.ts +55 -0
  187. package/state/src/selectors/feature.selector.ts +33 -0
  188. package/state/src/selectors/public_api.ts +3 -0
  189. package/state/testing/ng-package.json +8 -0
  190. package/state/testing/package.json +3 -0
  191. package/state/testing/src/customer-testing.module.ts +20 -0
  192. package/state/testing/src/factories/customer-address.factory.spec.ts +39 -0
  193. package/state/testing/src/factories/customer-address.factory.ts +28 -0
  194. package/state/testing/src/factories/public_api.ts +1 -0
  195. package/state/testing/src/index.ts +1 -0
  196. package/state/testing/src/mock-address-facade.ts +29 -0
  197. package/state/testing/src/mock-customer-facade.ts +22 -0
  198. package/state/testing/src/public_api.ts +5 -0
  199. package/test.ts +23 -0
  200. package/testing/ng-package.json +8 -0
  201. package/testing/package.json +3 -0
  202. package/testing/src/factories/customer-address.factory.spec.ts +39 -0
  203. package/testing/src/factories/customer-address.factory.ts +27 -0
  204. package/testing/src/factories/customer.factory.spec.ts +41 -0
  205. package/testing/src/factories/customer.factory.ts +44 -0
  206. package/testing/src/factories/public_api.ts +2 -0
  207. package/testing/src/index.ts +1 -0
  208. package/testing/src/public_api.ts +1 -0
  209. package/tsconfig.json +41 -0
  210. package/tsconfig.lib.json +28 -0
  211. package/tsconfig.lib.prod.json +9 -0
  212. package/tsconfig.spec.json +17 -0
@@ -0,0 +1,14 @@
1
+ import { gql } from 'apollo-angular';
2
+
3
+ export const MAGENTO_CHANGE_PASSWORD_QUERY_NAME = 'MagentoChangePassword';
4
+
5
+ export const changePassword = gql`
6
+ mutation ${MAGENTO_CHANGE_PASSWORD_QUERY_NAME}($old: String!, $new: String!) {
7
+ changeCustomerPassword(
8
+ currentPassword: $old
9
+ newPassword: $new
10
+ ) {
11
+ email
12
+ }
13
+ }
14
+ `;
@@ -0,0 +1,12 @@
1
+ import { gql } from 'apollo-angular';
2
+
3
+ import { magentoCustomerAddressFragment } from './fragments/public_api';
4
+
5
+ export const createCustomerAddress = gql`
6
+ mutation MagentoCreateCustomerAddress($input: CustomerAddressInput!) {
7
+ createCustomerAddress(input: $input) {
8
+ ...magentoCustomerAddress
9
+ }
10
+ }
11
+ ${magentoCustomerAddressFragment}
12
+ `;
@@ -0,0 +1,7 @@
1
+ import { gql } from 'apollo-angular';
2
+
3
+ export const deleteCustomerAddress = gql`
4
+ mutation MagentoDeleteCustomerAddress($id: Int!) {
5
+ deleteCustomerAddress(id: $id)
6
+ }
7
+ `;
@@ -0,0 +1,21 @@
1
+ import { gql } from 'apollo-angular';
2
+
3
+ export const magentoCustomerAddressFragment = gql`
4
+ fragment magentoCustomerAddress on CustomerAddress {
5
+ id
6
+ city
7
+ country_code
8
+ firstname
9
+ lastname
10
+ postcode
11
+ region {
12
+ region_code
13
+ region_id
14
+ }
15
+ street
16
+ telephone
17
+ company
18
+ default_billing
19
+ default_shipping
20
+ }
21
+ `;
@@ -0,0 +1,16 @@
1
+ import { gql } from 'apollo-angular';
2
+
3
+ import { magentoCustomerAddressFragment } from './customer-address';
4
+
5
+ export const magentoCustomerFragment = gql`
6
+ fragment magentoCustomer on Customer {
7
+ email
8
+ firstname
9
+ lastname
10
+ is_subscribed
11
+ addresses {
12
+ ...magentoCustomerAddress
13
+ }
14
+ }
15
+ ${magentoCustomerAddressFragment}
16
+ `;
@@ -0,0 +1,2 @@
1
+ export { magentoCustomerFragment } from './customer';
2
+ export { magentoCustomerAddressFragment } from './customer-address';
@@ -0,0 +1,16 @@
1
+ import { gql } from 'apollo-angular';
2
+
3
+ import { magentoCustomerAddressFragment } from './fragments/public_api';
4
+
5
+ export const MAGENTO_GET_CUSTOMER_ADDRESSES_QUERY_NAME = 'MagentoGetCustomerAddresses';
6
+
7
+ export const getCustomerAddresses = gql`
8
+ query ${MAGENTO_GET_CUSTOMER_ADDRESSES_QUERY_NAME} {
9
+ customer {
10
+ addresses {
11
+ ...magentoCustomerAddress
12
+ }
13
+ }
14
+ }
15
+ ${magentoCustomerAddressFragment}
16
+ `;
@@ -0,0 +1,14 @@
1
+ import { gql } from 'apollo-angular';
2
+
3
+ import { magentoCustomerFragment } from './fragments/public_api';
4
+
5
+ export const MAGENTO_GET_CUSTOMER_QUERY_NAME = 'MagentoGetCustomer';
6
+
7
+ export const getCustomer = gql`
8
+ query ${MAGENTO_GET_CUSTOMER_QUERY_NAME} {
9
+ customer {
10
+ ...magentoCustomer
11
+ }
12
+ }
13
+ ${magentoCustomerFragment}
14
+ `;
@@ -0,0 +1,10 @@
1
+ export * from './fragments/public_api';
2
+
3
+ export * from './get-customer';
4
+ export * from './get-customer-addresses';
5
+ export * from './create-customer-address';
6
+ export * from './update-customer-address';
7
+ export * from './delete-customer-address';
8
+ export * from './update-customer';
9
+ export * from './update-email';
10
+ export * from './change-password';
@@ -0,0 +1,12 @@
1
+ import { gql } from 'apollo-angular';
2
+
3
+ import { magentoCustomerAddressFragment } from './fragments/public_api';
4
+
5
+ export const updateCustomerAddress = gql`
6
+ mutation MagentoUpdateCustomerAddress($id: Int!, $input: CustomerAddressInput!) {
7
+ updateCustomerAddress(id: $id, input: $input) {
8
+ ...magentoCustomerAddress
9
+ }
10
+ }
11
+ ${magentoCustomerAddressFragment}
12
+ `;
@@ -0,0 +1,16 @@
1
+ import { gql } from 'apollo-angular';
2
+
3
+ import { magentoCustomerFragment } from './fragments/public_api';
4
+
5
+ export const MAGENTO_UPDATE_CUSTOMER_QUERY_NAME = 'MagentoUpdateCustomer';
6
+
7
+ export const updateCustomer = gql`
8
+ mutation ${MAGENTO_UPDATE_CUSTOMER_QUERY_NAME}($customer: CustomerUpdateInput!) {
9
+ updateCustomerV2(input: $customer) {
10
+ customer {
11
+ ...magentoCustomer
12
+ }
13
+ }
14
+ }
15
+ ${magentoCustomerFragment}
16
+ `;
@@ -0,0 +1,16 @@
1
+ import { gql } from 'apollo-angular';
2
+
3
+ import { magentoCustomerFragment } from './fragments/public_api';
4
+
5
+ export const MAGENTO_UPDATE_EMAIL_QUERY_NAME = 'MagentoUpdateEmail';
6
+
7
+ export const updateEmail = gql`
8
+ mutation ${MAGENTO_UPDATE_EMAIL_QUERY_NAME}($email: String!, $password: String!) {
9
+ updateCustomerEmail(email: $email, password: $password) {
10
+ customer {
11
+ ...magentoCustomer
12
+ }
13
+ }
14
+ }
15
+ ${magentoCustomerFragment}
16
+ `;
@@ -0,0 +1,2 @@
1
+ export * from './requests/public_api';
2
+ export * from './responses/public_api';
@@ -0,0 +1,42 @@
1
+ import { TestBed } from '@angular/core/testing';
2
+
3
+ import { DaffCustomerAddress } from '@daffodil/customer';
4
+ import { MagentoCustomerAddressInput } from '@daffodil/customer/driver/magento';
5
+ import { DaffCustomerAddressFactory } from '@daffodil/customer/testing';
6
+
7
+ import { magentoCustomerAddressInputTransform } from './address-input';
8
+
9
+ describe('@daffodil/customer/driver/magento | magentoCustomerAddressInputTransform', () => {
10
+ let customerAddressFactory: DaffCustomerAddressFactory;
11
+ let mockCustomerAddress: DaffCustomerAddress;
12
+
13
+ let result: MagentoCustomerAddressInput;
14
+
15
+ beforeEach(() => {
16
+ customerAddressFactory = TestBed.inject(DaffCustomerAddressFactory);
17
+
18
+ mockCustomerAddress = customerAddressFactory.create();
19
+
20
+ result = magentoCustomerAddressInputTransform(mockCustomerAddress);
21
+ });
22
+
23
+ it('should transform fields', () => {
24
+ expect(result.firstname).toEqual(mockCustomerAddress.firstname);
25
+ expect(result.lastname).toEqual(mockCustomerAddress.lastname);
26
+ expect(result.city).toEqual(mockCustomerAddress.city);
27
+ expect(result.country_code).toEqual(mockCustomerAddress.country);
28
+ expect(result.country_id).toEqual(mockCustomerAddress.country);
29
+ expect(result.default_billing).toEqual(mockCustomerAddress.defaultBilling);
30
+ expect(result.default_shipping).toEqual(mockCustomerAddress.defaultShipping);
31
+ expect(result.middlename).toEqual(mockCustomerAddress.middlename);
32
+ expect(result.postcode).toEqual(mockCustomerAddress.postcode);
33
+ expect(result.prefix).toEqual(mockCustomerAddress.prefix);
34
+ expect(result.region.region_id).toEqual(Number(mockCustomerAddress.region));
35
+ expect(result.street).toEqual([
36
+ mockCustomerAddress.street,
37
+ mockCustomerAddress.street2,
38
+ ]);
39
+ expect(result.suffix).toEqual(mockCustomerAddress.suffix);
40
+ expect(result.telephone).toEqual(mockCustomerAddress.telephone);
41
+ });
42
+ });
@@ -0,0 +1,25 @@
1
+ import { DaffCustomerAddress } from '@daffodil/customer';
2
+
3
+ import { MagentoCustomerAddressInput } from '../../models/public_api';
4
+
5
+ export const magentoCustomerAddressInputTransform = (address: Partial<DaffCustomerAddress>): MagentoCustomerAddressInput => ({
6
+ city: address.city,
7
+ country_code: address.country,
8
+ country_id: address.country,
9
+ default_billing: address.defaultBilling,
10
+ default_shipping: address.defaultShipping,
11
+ firstname: address.firstname,
12
+ lastname: address.lastname,
13
+ middlename: address.middlename,
14
+ postcode: address.postcode,
15
+ prefix: address.prefix,
16
+ region: {
17
+ region_id: Number(address.region),
18
+ },
19
+ street: [
20
+ address.street,
21
+ ...(address.street2 ? [address.street2] : []),
22
+ ],
23
+ suffix: address.suffix,
24
+ telephone: address.telephone,
25
+ });
@@ -0,0 +1,28 @@
1
+ import { TestBed } from '@angular/core/testing';
2
+
3
+ import { DaffCustomer } from '@daffodil/customer';
4
+ import { MagentoCustomerInput } from '@daffodil/customer/driver/magento';
5
+ import { DaffCustomerFactory } from '@daffodil/customer/testing';
6
+
7
+ import { magentoCustomerInputTransform } from './customer-input';
8
+
9
+ describe('@daffodil/customer/driver/magento | magentoCustomerInputTransform', () => {
10
+ let customerFactory: DaffCustomerFactory;
11
+ let mockCustomer: DaffCustomer;
12
+
13
+ let result: MagentoCustomerInput;
14
+
15
+ beforeEach(() => {
16
+ customerFactory = TestBed.inject(DaffCustomerFactory);
17
+
18
+ mockCustomer = customerFactory.create();
19
+
20
+ result = magentoCustomerInputTransform(mockCustomer);
21
+ });
22
+
23
+ it('should transform fields', () => {
24
+ expect(result.firstname).toEqual(mockCustomer.firstName);
25
+ expect(result.lastname).toEqual(mockCustomer.lastName);
26
+ expect(result.is_subscribed).toEqual(mockCustomer.isSubscribed);
27
+ });
28
+ });
@@ -0,0 +1,9 @@
1
+ import { DaffCustomer } from '@daffodil/customer';
2
+
3
+ import { MagentoCustomerInput } from '../../models/public_api';
4
+
5
+ export const magentoCustomerInputTransform = (customer: Partial<DaffCustomer>): MagentoCustomerInput => ({
6
+ firstname: customer.firstName,
7
+ lastname: customer.lastName,
8
+ is_subscribed: customer.isSubscribed,
9
+ });
@@ -0,0 +1,2 @@
1
+ export { magentoCustomerInputTransform } from './customer-input';
2
+ export { magentoCustomerAddressInputTransform } from './address-input';
@@ -0,0 +1,39 @@
1
+ import { TestBed } from '@angular/core/testing';
2
+
3
+ import { DaffCustomerAddress } from '@daffodil/customer';
4
+ import { MagentoCustomerAddress } from '@daffodil/customer/driver/magento';
5
+ import { MagentoCustomerAddressFactory } from '@daffodil/customer/driver/magento/testing';
6
+
7
+ import { magentoCustomerAddressTransform } from './customer-address';
8
+
9
+ describe('@daffodil/customer/driver/magento | magentoCustomerAddressTransform', () => {
10
+ let addressFactory: MagentoCustomerAddressFactory;
11
+ let mockAddress: MagentoCustomerAddress;
12
+ let result: DaffCustomerAddress;
13
+
14
+ beforeEach(() => {
15
+ addressFactory = TestBed.inject(MagentoCustomerAddressFactory);
16
+
17
+ mockAddress = addressFactory.create();
18
+
19
+ result = magentoCustomerAddressTransform(mockAddress);
20
+ });
21
+
22
+ it('should transform', () => {
23
+ expect(result.id).toEqual(String(mockAddress.id));
24
+ expect(result.street).toEqual(mockAddress.street[0]);
25
+ expect(result.street2).toEqual(mockAddress.street[1]);
26
+ expect(result.city).toEqual(mockAddress.city);
27
+ expect(result.region).toEqual(String(mockAddress.region.region_id));
28
+ expect(result.region_code).toEqual(mockAddress.region.region_code);
29
+ expect(result.country).toEqual(mockAddress.country_code);
30
+ expect(result.country_id).toEqual(mockAddress.country_code);
31
+ expect(result.postcode).toEqual(mockAddress.postcode);
32
+ expect(result.firstname).toEqual(mockAddress.firstname);
33
+ expect(result.lastname).toEqual(mockAddress.lastname);
34
+ expect(result.telephone).toEqual(mockAddress.telephone);
35
+ expect(result.email).toEqual(mockAddress.email);
36
+ expect(result.defaultBilling).toEqual(mockAddress.default_billing);
37
+ expect(result.defaultShipping).toEqual(mockAddress.default_shipping);
38
+ });
39
+ });
@@ -0,0 +1,21 @@
1
+ import { DaffCustomerAddress } from '@daffodil/customer';
2
+
3
+ import { MagentoCustomerAddress } from '../../models/public_api';
4
+
5
+ export const magentoCustomerAddressTransform = (address: MagentoCustomerAddress): DaffCustomerAddress => ({
6
+ id: String(address.id),
7
+ street: address.street[0],
8
+ street2: address.street[1],
9
+ city: address.city,
10
+ region: String(address.region.region_id),
11
+ region_code: address.region.region_code,
12
+ country: address.country_code,
13
+ country_id: address.country_code,
14
+ postcode: address.postcode,
15
+ firstname: address.firstname,
16
+ lastname: address.lastname,
17
+ telephone: address.telephone,
18
+ email: address.email,
19
+ defaultBilling: address.default_billing,
20
+ defaultShipping: address.default_shipping,
21
+ });
@@ -0,0 +1,33 @@
1
+ import { TestBed } from '@angular/core/testing';
2
+
3
+ import { DaffCustomer } from '@daffodil/customer';
4
+ import { MagentoCustomer } from '@daffodil/customer/driver/magento';
5
+ import { MagentoCustomerFactory } from '@daffodil/customer/driver/magento/testing';
6
+
7
+ import { magentoCustomerTransform } from './customer';
8
+
9
+ describe('@daffodil/customer/driver/magento | magentoCustomerTransform', () => {
10
+ let customerFactory: MagentoCustomerFactory;
11
+ let mockCustomer: MagentoCustomer;
12
+ let result: DaffCustomer;
13
+
14
+ beforeEach(() => {
15
+ customerFactory = TestBed.inject(MagentoCustomerFactory);
16
+
17
+ mockCustomer = customerFactory.create();
18
+
19
+ result = magentoCustomerTransform(mockCustomer);
20
+ });
21
+
22
+ it('should transform fields', () => {
23
+ expect(result.id).toEqual(mockCustomer.email);
24
+ expect(result.email).toEqual(mockCustomer.email);
25
+ expect(result.firstName).toEqual(mockCustomer.firstname);
26
+ expect(result.lastName).toEqual(mockCustomer.lastname);
27
+ expect(result.isSubscribed).toEqual(mockCustomer.is_subscribed);
28
+ });
29
+
30
+ it('should transform addresses', () => {
31
+ expect(result.addresses).toEqual(mockCustomer.addresses.map(({ id }) => jasmine.objectContaining({ id: String(id) })));
32
+ });
33
+ });
@@ -0,0 +1,13 @@
1
+ import { DaffCustomer } from '@daffodil/customer';
2
+
3
+ import { MagentoCustomer } from '../../models/public_api';
4
+ import { magentoCustomerAddressTransform } from './customer-address';
5
+
6
+ export const magentoCustomerTransform = (customer: MagentoCustomer): DaffCustomer => ({
7
+ id: customer.email,
8
+ email: customer.email,
9
+ firstName: customer.firstname,
10
+ lastName: customer.lastname,
11
+ isSubscribed: customer.is_subscribed,
12
+ addresses: customer.addresses.map(magentoCustomerAddressTransform),
13
+ });
@@ -0,0 +1,2 @@
1
+ export { magentoCustomerTransform } from './customer';
2
+ export { magentoCustomerAddressTransform } from './customer-address';
@@ -0,0 +1,45 @@
1
+ import { TestBed } from '@angular/core/testing';
2
+ import { ApolloQueryResult } from '@apollo/client/core';
3
+
4
+ import { DaffCustomerInvalidAPIResponseError } from '@daffodil/customer/driver';
5
+ import { MagentoChangeEmailResponse } from '@daffodil/customer/driver/magento';
6
+ import { MagentoCustomerFactory } from '@daffodil/customer/driver/magento/testing';
7
+
8
+ import { validateChangeEmailResponse as validator } from './change-email';
9
+
10
+ describe('@daffodil/customer/driver/magento | validateChangeEmailResponse', () => {
11
+ let response: ApolloQueryResult<MagentoChangeEmailResponse>;
12
+ let customerFactory: MagentoCustomerFactory;
13
+
14
+ beforeEach(() => {
15
+ customerFactory = TestBed.inject(MagentoCustomerFactory);
16
+
17
+ response = {
18
+ data: {
19
+ updateCustomerEmail: {
20
+ customer: customerFactory.create(),
21
+ },
22
+ },
23
+ loading: null,
24
+ networkStatus: null,
25
+ };
26
+ });
27
+
28
+ describe('and when the response has a customer', () => {
29
+ it('should return the response and not throw an error', () => {
30
+ const result = validator(response);
31
+
32
+ expect(result).toEqual(response);
33
+ });
34
+ });
35
+
36
+ describe('and when the response does not have customer', () => {
37
+ beforeEach(() => {
38
+ response.data.updateCustomerEmail.customer = null;
39
+ });
40
+
41
+ it('should throw a DaffCustomerInvalidAPIResponseError', () => {
42
+ expect(() => validator(response)).toThrow(jasmine.any(DaffCustomerInvalidAPIResponseError));
43
+ });
44
+ });
45
+ });
@@ -0,0 +1,13 @@
1
+ import { ApolloQueryResult } from '@apollo/client/core';
2
+
3
+ import { DaffCustomerInvalidAPIResponseError } from '@daffodil/customer/driver';
4
+
5
+ import { MagentoChangeEmailResponse } from '../models/public_api';
6
+
7
+ export const validateChangeEmailResponse = (response: ApolloQueryResult<MagentoChangeEmailResponse>) => {
8
+ if (response.data.updateCustomerEmail.customer?.email) {
9
+ return response;
10
+ } else {
11
+ throw new DaffCustomerInvalidAPIResponseError('Update email response does not contain a valid customer.');
12
+ }
13
+ };
@@ -0,0 +1,45 @@
1
+ import { TestBed } from '@angular/core/testing';
2
+ import { ApolloQueryResult } from '@apollo/client/core';
3
+
4
+ import { DaffCustomerInvalidAPIResponseError } from '@daffodil/customer/driver';
5
+ import { MagentoChangePasswordResponse } from '@daffodil/customer/driver/magento';
6
+ import { MagentoCustomerFactory } from '@daffodil/customer/driver/magento/testing';
7
+
8
+ import { validateChangePasswordResponse as validator } from './change-password';
9
+
10
+ describe('@daffodil/customer/driver/magento | validateChangePasswordResponse', () => {
11
+ let response: ApolloQueryResult<MagentoChangePasswordResponse>;
12
+ let customerFactory: MagentoCustomerFactory;
13
+
14
+ beforeEach(() => {
15
+ customerFactory = TestBed.inject(MagentoCustomerFactory);
16
+
17
+ response = {
18
+ data: {
19
+ changeCustomerPassword: {
20
+ email: 'email',
21
+ },
22
+ },
23
+ loading: null,
24
+ networkStatus: null,
25
+ };
26
+ });
27
+
28
+ describe('and when the response has a customer', () => {
29
+ it('should return the response and not throw an error', () => {
30
+ const result = validator(response);
31
+
32
+ expect(result).toEqual(response);
33
+ });
34
+ });
35
+
36
+ describe('and when the response does not have customer', () => {
37
+ beforeEach(() => {
38
+ response.data.changeCustomerPassword.email = null;
39
+ });
40
+
41
+ it('should throw a DaffCustomerInvalidAPIResponseError', () => {
42
+ expect(() => validator(response)).toThrow(jasmine.any(DaffCustomerInvalidAPIResponseError));
43
+ });
44
+ });
45
+ });
@@ -0,0 +1,13 @@
1
+ import { ApolloQueryResult } from '@apollo/client/core';
2
+
3
+ import { DaffCustomerInvalidAPIResponseError } from '@daffodil/customer/driver';
4
+
5
+ import { MagentoChangePasswordResponse } from '../models/public_api';
6
+
7
+ export const validateChangePasswordResponse = (response: ApolloQueryResult<MagentoChangePasswordResponse>) => {
8
+ if (response.data.changeCustomerPassword?.email) {
9
+ return response;
10
+ } else {
11
+ throw new DaffCustomerInvalidAPIResponseError('Change password response does not contain a valid customer.');
12
+ }
13
+ };
@@ -0,0 +1,43 @@
1
+ import { TestBed } from '@angular/core/testing';
2
+ import { ApolloQueryResult } from '@apollo/client/core';
3
+
4
+ import { DaffCustomerInvalidAPIResponseError } from '@daffodil/customer/driver';
5
+ import { MagentoCreateCustomerAddressResponse } from '@daffodil/customer/driver/magento';
6
+ import { MagentoCustomerAddressFactory } from '@daffodil/customer/driver/magento/testing';
7
+
8
+ import { validateCreateCustomerAddressResponse as validator } from './create-customer-address';
9
+
10
+ describe('@daffodil/customer/driver/magento | validateCreateCustomerAddressResponse', () => {
11
+ let response: ApolloQueryResult<MagentoCreateCustomerAddressResponse>;
12
+ let customerAddressFactory: MagentoCustomerAddressFactory;
13
+
14
+ beforeEach(() => {
15
+ customerAddressFactory = TestBed.inject(MagentoCustomerAddressFactory);
16
+
17
+ response = {
18
+ data: {
19
+ createCustomerAddress: customerAddressFactory.create(),
20
+ },
21
+ loading: null,
22
+ networkStatus: null,
23
+ };
24
+ });
25
+
26
+ describe('and when the response is an address', () => {
27
+ it('should return the response and not throw an error', () => {
28
+ const result = validator(response);
29
+
30
+ expect(result).toEqual(response);
31
+ });
32
+ });
33
+
34
+ describe('and when the response is not an address', () => {
35
+ beforeEach(() => {
36
+ response.data.createCustomerAddress = null;
37
+ });
38
+
39
+ it('should throw a DaffCustomerInvalidAPIResponseError', () => {
40
+ expect(() => validator(response)).toThrow(jasmine.any(DaffCustomerInvalidAPIResponseError));
41
+ });
42
+ });
43
+ });
@@ -0,0 +1,13 @@
1
+ import { ApolloQueryResult } from '@apollo/client/core';
2
+
3
+ import { DaffCustomerInvalidAPIResponseError } from '@daffodil/customer/driver';
4
+
5
+ import { MagentoCreateCustomerAddressResponse } from '../models/public_api';
6
+
7
+ export const validateCreateCustomerAddressResponse = (response: ApolloQueryResult<MagentoCreateCustomerAddressResponse>) => {
8
+ if (response.data.createCustomerAddress?.id) {
9
+ return response;
10
+ } else {
11
+ throw new DaffCustomerInvalidAPIResponseError('Create customer address response does not contain an address.');
12
+ }
13
+ };
@@ -0,0 +1,38 @@
1
+ import { ApolloQueryResult } from '@apollo/client/core';
2
+
3
+ import { DaffCustomerInvalidAPIResponseError } from '@daffodil/customer/driver';
4
+ import { MagentoDeleteCustomerAddressResponse } from '@daffodil/customer/driver/magento';
5
+
6
+ import { validateDeleteCustomerAddressResponse as validator } from './delete-customer-address';
7
+
8
+ describe('@daffodil/customer/driver/magento | validateDeleteCustomerAddressResponse', () => {
9
+ let response: ApolloQueryResult<MagentoDeleteCustomerAddressResponse>;
10
+
11
+ beforeEach(() => {
12
+ response = {
13
+ data: {
14
+ deleteCustomerAddress: true,
15
+ },
16
+ loading: null,
17
+ networkStatus: null,
18
+ };
19
+ });
20
+
21
+ describe('and when the response is true', () => {
22
+ it('should return the response and not throw an error', () => {
23
+ const result = validator(response);
24
+
25
+ expect(result).toEqual(response);
26
+ });
27
+ });
28
+
29
+ describe('and when the response is false', () => {
30
+ beforeEach(() => {
31
+ response.data.deleteCustomerAddress = false;
32
+ });
33
+
34
+ it('should throw a DaffCustomerInvalidAPIResponseError', () => {
35
+ expect(() => validator(response)).toThrow(jasmine.any(DaffCustomerInvalidAPIResponseError));
36
+ });
37
+ });
38
+ });
@@ -0,0 +1,13 @@
1
+ import { ApolloQueryResult } from '@apollo/client/core';
2
+
3
+ import { DaffCustomerInvalidAPIResponseError } from '@daffodil/customer/driver';
4
+
5
+ import { MagentoDeleteCustomerAddressResponse } from '../models/public_api';
6
+
7
+ export const validateDeleteCustomerAddressResponse = (response: ApolloQueryResult<MagentoDeleteCustomerAddressResponse>) => {
8
+ if (response.data.deleteCustomerAddress) {
9
+ return response;
10
+ } else {
11
+ throw new DaffCustomerInvalidAPIResponseError('Delete customer address did not complete successfully.');
12
+ }
13
+ };