@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.
- package/.eslintrc.js +52 -0
- package/README.md +9 -0
- package/driver/in-memory/ng-package.json +8 -0
- package/driver/in-memory/package.json +3 -0
- package/driver/in-memory/src/backend/address.service.spec.ts +199 -0
- package/driver/in-memory/src/backend/address.service.ts +123 -0
- package/driver/in-memory/src/backend/customer.service.spec.ts +119 -0
- package/driver/in-memory/src/backend/customer.service.ts +126 -0
- package/driver/in-memory/src/driver/address.service.spec.ts +153 -0
- package/driver/in-memory/src/driver/address.service.ts +49 -0
- package/driver/in-memory/src/driver/customer-driver.module.ts +38 -0
- package/driver/in-memory/src/driver/customer.service.spec.ts +131 -0
- package/driver/in-memory/src/driver/customer.service.ts +46 -0
- package/driver/in-memory/src/index.ts +1 -0
- package/driver/in-memory/src/public_api.ts +5 -0
- package/driver/magento/ng-package.json +8 -0
- package/driver/magento/package.json +3 -0
- package/driver/magento/src/address.service.spec.ts +398 -0
- package/driver/magento/src/address.service.ts +147 -0
- package/driver/magento/src/customer-driver.module.ts +41 -0
- package/driver/magento/src/customer.service.spec.ts +348 -0
- package/driver/magento/src/customer.service.ts +101 -0
- package/driver/magento/src/errors/map.ts +6 -0
- package/driver/magento/src/errors/public_api.ts +1 -0
- package/driver/magento/src/errors/transform.ts +40 -0
- package/driver/magento/src/index.ts +1 -0
- package/driver/magento/src/models/gender.enum.ts +4 -0
- package/driver/magento/src/models/public_api.ts +4 -0
- package/driver/magento/src/models/requests/address-attribute-input.type.ts +4 -0
- package/driver/magento/src/models/requests/address-input.type.ts +23 -0
- package/driver/magento/src/models/requests/address-region-input.type.ts +8 -0
- package/driver/magento/src/models/requests/customer-input.type.ts +15 -0
- package/driver/magento/src/models/requests/public_api.ts +4 -0
- package/driver/magento/src/models/responses/change-email.type.ts +7 -0
- package/driver/magento/src/models/responses/change-password.type.ts +5 -0
- package/driver/magento/src/models/responses/create-customer-address.type.ts +5 -0
- package/driver/magento/src/models/responses/customer-address.type.ts +18 -0
- package/driver/magento/src/models/responses/customer.type.ts +9 -0
- package/driver/magento/src/models/responses/delete-customer-address.type.ts +3 -0
- package/driver/magento/src/models/responses/get-customer-addresses.type.ts +5 -0
- package/driver/magento/src/models/responses/get-customer.type.ts +5 -0
- package/driver/magento/src/models/responses/public_api.ts +10 -0
- package/driver/magento/src/models/responses/update-customer-address.type.ts +5 -0
- package/driver/magento/src/models/responses/update-customer.type.ts +7 -0
- package/driver/magento/src/public_api.ts +9 -0
- package/driver/magento/src/queries/change-password.ts +14 -0
- package/driver/magento/src/queries/create-customer-address.ts +12 -0
- package/driver/magento/src/queries/delete-customer-address.ts +7 -0
- package/driver/magento/src/queries/fragments/customer-address.ts +21 -0
- package/driver/magento/src/queries/fragments/customer.ts +16 -0
- package/driver/magento/src/queries/fragments/public_api.ts +2 -0
- package/driver/magento/src/queries/get-customer-addresses.ts +16 -0
- package/driver/magento/src/queries/get-customer.ts +14 -0
- package/driver/magento/src/queries/public_api.ts +10 -0
- package/driver/magento/src/queries/update-customer-address.ts +12 -0
- package/driver/magento/src/queries/update-customer.ts +16 -0
- package/driver/magento/src/queries/update-email.ts +16 -0
- package/driver/magento/src/transforms/public_api.ts +2 -0
- package/driver/magento/src/transforms/requests/address-input.spec.ts +42 -0
- package/driver/magento/src/transforms/requests/address-input.ts +25 -0
- package/driver/magento/src/transforms/requests/customer-input.spec.ts +28 -0
- package/driver/magento/src/transforms/requests/customer-input.ts +9 -0
- package/driver/magento/src/transforms/requests/public_api.ts +2 -0
- package/driver/magento/src/transforms/responses/customer-address.spec.ts +39 -0
- package/driver/magento/src/transforms/responses/customer-address.ts +21 -0
- package/driver/magento/src/transforms/responses/customer.spec.ts +33 -0
- package/driver/magento/src/transforms/responses/customer.ts +13 -0
- package/driver/magento/src/transforms/responses/public_api.ts +2 -0
- package/driver/magento/src/validators/change-email.spec.ts +45 -0
- package/driver/magento/src/validators/change-email.ts +13 -0
- package/driver/magento/src/validators/change-password.spec.ts +45 -0
- package/driver/magento/src/validators/change-password.ts +13 -0
- package/driver/magento/src/validators/create-customer-address.spec.ts +43 -0
- package/driver/magento/src/validators/create-customer-address.ts +13 -0
- package/driver/magento/src/validators/delete-customer-address.spec.ts +38 -0
- package/driver/magento/src/validators/delete-customer-address.ts +13 -0
- package/driver/magento/src/validators/get-customer-addresses.spec.ts +43 -0
- package/driver/magento/src/validators/get-customer-addresses.ts +13 -0
- package/driver/magento/src/validators/get-customer.spec.ts +43 -0
- package/driver/magento/src/validators/get-customer.ts +13 -0
- package/driver/magento/src/validators/public_api.ts +8 -0
- package/driver/magento/src/validators/update-customer-address.spec.ts +43 -0
- package/driver/magento/src/validators/update-customer-address.ts +13 -0
- package/driver/magento/src/validators/update-customer.spec.ts +45 -0
- package/driver/magento/src/validators/update-customer.ts +13 -0
- package/driver/magento/testing/ng-package.json +8 -0
- package/driver/magento/testing/package.json +3 -0
- package/driver/magento/testing/src/factories/address.factory.spec.ts +45 -0
- package/driver/magento/testing/src/factories/address.factory.ts +35 -0
- package/driver/magento/testing/src/factories/customer.factory.spec.ts +36 -0
- package/driver/magento/testing/src/factories/customer.factory.ts +38 -0
- package/driver/magento/testing/src/factories/public_api.ts +2 -0
- package/driver/magento/testing/src/index.ts +1 -0
- package/driver/magento/testing/src/public_api.ts +1 -0
- package/driver/ng-package.json +8 -0
- package/driver/package.json +3 -0
- package/driver/src/errors/address-not-found.ts +17 -0
- package/driver/src/errors/codes.ts +11 -0
- package/driver/src/errors/default-billing-address-deletion.ts +17 -0
- package/driver/src/errors/default-shipping-address-deletion.ts +17 -0
- package/driver/src/errors/invalid-api-response.ts +17 -0
- package/driver/src/errors/map.ts +26 -0
- package/driver/src/errors/public_api.ts +18 -0
- package/driver/src/index.ts +1 -0
- package/driver/src/interfaces/address-service.interface.ts +42 -0
- package/driver/src/interfaces/customer-service.interface.ts +38 -0
- package/driver/src/public_api.ts +10 -0
- package/driver/testing/ng-package.json +8 -0
- package/driver/testing/package.json +3 -0
- package/driver/testing/src/drivers/address.service.spec.ts +61 -0
- package/driver/testing/src/drivers/address.service.ts +45 -0
- package/driver/testing/src/drivers/customer-driver.module.ts +39 -0
- package/driver/testing/src/drivers/customer.service.spec.ts +54 -0
- package/driver/testing/src/drivers/customer.service.ts +40 -0
- package/driver/testing/src/drivers/public_api.ts +3 -0
- package/driver/testing/src/index.ts +1 -0
- package/driver/testing/src/public_api.ts +1 -0
- package/karma.conf.js +11 -0
- package/ng-package.json +7 -0
- package/ng-package.prod.json +7 -0
- package/package.json +42 -0
- package/routing/ng-package.json +8 -0
- package/routing/package.json +3 -0
- package/routing/src/guards/clear-errors.guard.spec.ts +39 -0
- package/routing/src/guards/clear-errors.guard.ts +22 -0
- package/routing/src/guards/public_api.ts +1 -0
- package/routing/src/index.ts +1 -0
- package/routing/src/public_api.ts +2 -0
- package/routing/src/resolvers/customer.resolver.spec.ts +62 -0
- package/routing/src/resolvers/customer.resolver.ts +29 -0
- package/routing/src/resolvers/public_api.ts +1 -0
- package/src/index.ts +1 -0
- package/src/injection-tokens/error-matcher.token.ts +12 -0
- package/src/injection-tokens/public_api.ts +1 -0
- package/src/models/address.type.ts +16 -0
- package/src/models/customer.type.ts +29 -0
- package/src/models/public_api.ts +2 -0
- package/src/public_api.ts +2 -0
- package/state/ng-package.json +8 -0
- package/state/package.json +3 -0
- package/state/src/actions/address.actions.ts +200 -0
- package/state/src/actions/customer.actions.ts +163 -0
- package/state/src/actions/public_api.ts +2 -0
- package/state/src/customer.module.ts +22 -0
- package/state/src/effects/address.effects.spec.ts +267 -0
- package/state/src/effects/address.effects.ts +118 -0
- package/state/src/effects/customer.effects.spec.ts +210 -0
- package/state/src/effects/customer.effects.ts +105 -0
- package/state/src/facades/address/facade.spec.ts +81 -0
- package/state/src/facades/address/facade.ts +77 -0
- package/state/src/facades/address/interface.ts +17 -0
- package/state/src/facades/customer/facade.spec.ts +81 -0
- package/state/src/facades/customer/facade.ts +61 -0
- package/state/src/facades/customer/interface.ts +16 -0
- package/state/src/facades/public_api.ts +4 -0
- package/state/src/index.ts +1 -0
- package/state/src/models/address.type.ts +4 -0
- package/state/src/models/public_api.ts +1 -0
- package/state/src/public_api.ts +7 -0
- package/state/src/reducers/address/initial-state.ts +8 -0
- package/state/src/reducers/address/public_api.ts +3 -0
- package/state/src/reducers/address/reducer.spec.ts +422 -0
- package/state/src/reducers/address/reducer.ts +51 -0
- package/state/src/reducers/address/type.ts +6 -0
- package/state/src/reducers/address-entities/adapter.ts +17 -0
- package/state/src/reducers/address-entities/public_api.ts +2 -0
- package/state/src/reducers/address-entities/reducer.ts +95 -0
- package/state/src/reducers/customer/adapter.spec.ts +51 -0
- package/state/src/reducers/customer/adapter.ts +34 -0
- package/state/src/reducers/customer/initial-state.ts +11 -0
- package/state/src/reducers/customer/interface.ts +10 -0
- package/state/src/reducers/customer/public_api.ts +4 -0
- package/state/src/reducers/customer/reducer.spec.ts +396 -0
- package/state/src/reducers/customer/reducer.ts +65 -0
- package/state/src/reducers/public_api.ts +10 -0
- package/state/src/reducers/reducers.interface.ts +31 -0
- package/state/src/reducers/store-feature-key.ts +4 -0
- package/state/src/reducers/token/extra.token.spec.ts +35 -0
- package/state/src/reducers/token/extra.token.ts +42 -0
- package/state/src/reducers/token/public_api.ts +4 -0
- package/state/src/reducers/token/reducers.token.spec.ts +64 -0
- package/state/src/reducers/token/reducers.token.ts +39 -0
- package/state/src/selectors/address/selector.spec.ts +105 -0
- package/state/src/selectors/address/selector.ts +66 -0
- package/state/src/selectors/customer/selector.spec.ts +80 -0
- package/state/src/selectors/customer/selector.ts +55 -0
- package/state/src/selectors/feature.selector.ts +33 -0
- package/state/src/selectors/public_api.ts +3 -0
- package/state/testing/ng-package.json +8 -0
- package/state/testing/package.json +3 -0
- package/state/testing/src/customer-testing.module.ts +20 -0
- package/state/testing/src/factories/customer-address.factory.spec.ts +39 -0
- package/state/testing/src/factories/customer-address.factory.ts +28 -0
- package/state/testing/src/factories/public_api.ts +1 -0
- package/state/testing/src/index.ts +1 -0
- package/state/testing/src/mock-address-facade.ts +29 -0
- package/state/testing/src/mock-customer-facade.ts +22 -0
- package/state/testing/src/public_api.ts +5 -0
- package/test.ts +23 -0
- package/testing/ng-package.json +8 -0
- package/testing/package.json +3 -0
- package/testing/src/factories/customer-address.factory.spec.ts +39 -0
- package/testing/src/factories/customer-address.factory.ts +27 -0
- package/testing/src/factories/customer.factory.spec.ts +41 -0
- package/testing/src/factories/customer.factory.ts +44 -0
- package/testing/src/factories/public_api.ts +2 -0
- package/testing/src/index.ts +1 -0
- package/testing/src/public_api.ts +1 -0
- package/tsconfig.json +41 -0
- package/tsconfig.lib.json +28 -0
- package/tsconfig.lib.prod.json +9 -0
- 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,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,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,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,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,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
|
+
};
|