Skip to content
This repository has been archived by the owner on Oct 31, 2024. It is now read-only.

Commit

Permalink
feat(client): customer service (#1473)
Browse files Browse the repository at this point in the history
  • Loading branch information
mkucmus authored May 7, 2021
1 parent b67bc8c commit 313e14f
Show file tree
Hide file tree
Showing 34 changed files with 290 additions and 323 deletions.
2 changes: 2 additions & 0 deletions api/composables.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,8 @@ export interface IUseUser {
// (undocumented)
salutation: Ref<Salutation | null>;
// (undocumented)
updateAddress: (params: Partial<CustomerAddress>) => Promise<boolean>;
// (undocumented)
updateEmail: (updateEmailData: CustomerUpdateEmailParam) => Promise<boolean>;
// (undocumented)
updatePassword: (updatePasswordData: CustomerUpdatePasswordParam) => Promise<boolean>;
Expand Down
28 changes: 8 additions & 20 deletions api/shopware-6-client.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export interface ContactFormData {
}

// @beta
export function createCustomerAddress(params: Partial<CustomerAddress>, contextInstance?: ShopwareApiInstance): Promise<string>;
export function createCustomerAddress(params: Partial<CustomerAddress>, contextInstance?: ShopwareApiInstance): Promise<CustomerAddress>;

// @beta (undocumented)
export function createInstance(initialConfig?: ClientSettings): ShopwareApiInstance;
Expand Down Expand Up @@ -200,12 +200,6 @@ export const getCheckoutCartLineItemEndpoint: () => string;
// @beta (undocumented)
export const getCheckoutOrderEndpoint: () => string;

// @beta (undocumented)
export const getCheckoutOrderPayEndpoint: (orderId: string) => string;

// @beta (undocumented)
export const getCheckoutPromotionCodeEndpoint: (code: string) => string;

// @beta (undocumented)
export function getCmsPage(path: string, criteria?: ShopwareSearchParams, contextInstance?: ShopwareApiInstance): Promise<PageResolverResult<CmsPage>>;

Expand Down Expand Up @@ -236,23 +230,17 @@ export const getContextShippingMethodEndpoint: () => string;
// @beta
export function getCustomer(contextInstance?: ShopwareApiInstance): Promise<Customer | null>;

// @beta (undocumented)
export const getCustomerAddAddressEndpoint: () => string;

// @beta
export function getCustomerAddress(addressId: string, contextInstance?: ShopwareApiInstance): Promise<CustomerAddress>;

// @beta (undocumented)
export const getCustomerAddressDetailsEndpoint: (addressId: string) => string;

// @beta (undocumented)
export const getCustomerAddressEndpoint: (addressId?: string | undefined) => string;

// @beta
export function getCustomerAddresses(contextInstance?: ShopwareApiInstance): Promise<CustomerAddress[]>;

// @beta (undocumented)
export const getCustomerAddressSetDefaultBillingEndpoint: (addressId: string) => string;

// @beta (undocumented)
export const getCustomerAddressSetDefaultShippingEndpoint: (addressId: string) => string;
export function getCustomerAddresses(contextInstance?: ShopwareApiInstance): Promise<EntityResult<"customer_address", CustomerAddress[]>>;

// @beta (undocumented)
export const getCustomerDefaultBillingAddressEndpoint: (addressId: string) => string;
Expand All @@ -278,9 +266,6 @@ export const getCustomerLogoutEndpoint: () => string;
// @beta
export function getCustomerOrderDetails(orderId: string, contextInstance?: ShopwareApiInstance, additionalQueryParams?: string): Promise<Order | undefined>;

// @beta (undocumented)
export const getCustomerOrderDetailsEndpoint: (orderId: string) => string;

// @beta (undocumented)
export const getCustomerOrderEndpoint: () => string;

Expand Down Expand Up @@ -540,6 +525,9 @@ export interface ShopwareApiInstance {
// @beta
export const update: (config?: ClientSettings) => void;

// @beta
export function updateCustomerAddress(params: Partial<CustomerAddress>, contextInstance?: ShopwareApiInstance): Promise<CustomerAddress>;

// @beta
export function updateEmail(params: CustomerUpdateEmailParam, contextInstance?: ShopwareApiInstance): Promise<void>;

Expand Down
1 change: 1 addition & 0 deletions docs/landing/resources/api/composables.iuseuser.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export interface IUseUser
| [register](./composables.iuseuser.register.md) | ({}: CustomerRegistrationParams) =&gt; Promise&lt;boolean&gt; | <b><i>(BETA)</i></b> |
| [resetPassword](./composables.iuseuser.resetpassword.md) | (resetPasswordData: CustomerResetPasswordParam) =&gt; Promise&lt;boolean&gt; | <b><i>(BETA)</i></b> |
| [salutation](./composables.iuseuser.salutation.md) | Ref&lt;Salutation \| null&gt; | <b><i>(BETA)</i></b> |
| [updateAddress](./composables.iuseuser.updateaddress.md) | (params: Partial&lt;CustomerAddress&gt;) =&gt; Promise&lt;boolean&gt; | <b><i>(BETA)</i></b> |
| [updateEmail](./composables.iuseuser.updateemail.md) | (updateEmailData: CustomerUpdateEmailParam) =&gt; Promise&lt;boolean&gt; | <b><i>(BETA)</i></b> |
| [updatePassword](./composables.iuseuser.updatepassword.md) | (updatePasswordData: CustomerUpdatePasswordParam) =&gt; Promise&lt;boolean&gt; | <b><i>(BETA)</i></b> |
| [updatePersonalInfo](./composables.iuseuser.updatepersonalinfo.md) | (personals: CustomerUpdateProfileParam) =&gt; Promise&lt;boolean&gt; | <b><i>(BETA)</i></b> |
Expand Down
14 changes: 14 additions & 0 deletions docs/landing/resources/api/composables.iuseuser.updateaddress.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [@shopware-pwa/composables](./composables.md) &gt; [IUseUser](./composables.iuseuser.md) &gt; [updateAddress](./composables.iuseuser.updateaddress.md)

## IUseUser.updateAddress property

> This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.
>
<b>Signature:</b>

```typescript
updateAddress: (params: Partial<CustomerAddress>) => Promise<boolean>;
```
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Create an address and respond the new address's id
<b>Signature:</b>

```typescript
export declare function createCustomerAddress(params: Partial<CustomerAddress>, contextInstance?: ShopwareApiInstance): Promise<string>;
export declare function createCustomerAddress(params: Partial<CustomerAddress>, contextInstance?: ShopwareApiInstance): Promise<CustomerAddress>;
```

## Parameters
Expand All @@ -24,7 +24,7 @@ export declare function createCustomerAddress(params: Partial<CustomerAddress>,

<b>Returns:</b>

Promise&lt;string&gt;
Promise&lt;CustomerAddress&gt;

## Exceptions

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [@shopware-pwa/shopware-6-client](./shopware-6-client.md) &gt; [getCheckoutOrderPayEndpoint](./shopware-6-client.getcheckoutorderpayendpoint.md)
[Home](./index.md) &gt; [@shopware-pwa/shopware-6-client](./shopware-6-client.md) &gt; [getCustomerAddAddressEndpoint](./shopware-6-client.getcustomeraddaddressendpoint.md)

## getCheckoutOrderPayEndpoint variable
## getCustomerAddAddressEndpoint variable

> This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.
>
Expand All @@ -11,5 +11,5 @@
<b>Signature:</b>

```typescript
getCheckoutOrderPayEndpoint: (orderId: string) => string
getCustomerAddAddressEndpoint: () => string
```

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Get all customer's addresses
<b>Signature:</b>

```typescript
export declare function getCustomerAddresses(contextInstance?: ShopwareApiInstance): Promise<CustomerAddress[]>;
export declare function getCustomerAddresses(contextInstance?: ShopwareApiInstance): Promise<EntityResult<"customer_address", CustomerAddress[]>>;
```

## Parameters
Expand All @@ -23,7 +23,7 @@ export declare function getCustomerAddresses(contextInstance?: ShopwareApiInstan

<b>Returns:</b>

Promise&lt;CustomerAddress\[\]&gt;
Promise&lt;EntityResult&lt;"customer\_address", CustomerAddress\[\]&gt;&gt;

## Exceptions

Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

8 changes: 2 additions & 6 deletions docs/landing/resources/api/shopware-6-client.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
| [setCurrentShippingMethod(newShippingMethodId, contextInstance)](./shopware-6-client.setcurrentshippingmethod.md) | <b><i>(BETA)</i></b> |
| [setDefaultCustomerBillingAddress(addressId, contextInstance)](./shopware-6-client.setdefaultcustomerbillingaddress.md) | <b><i>(BETA)</i></b> Set address as default |
| [setDefaultCustomerShippingAddress(addressId, contextInstance)](./shopware-6-client.setdefaultcustomershippingaddress.md) | <b><i>(BETA)</i></b> Set address as default |
| [updateCustomerAddress(params, contextInstance)](./shopware-6-client.updatecustomeraddress.md) | <b><i>(BETA)</i></b> Update an address for specific ID |
| [updateEmail(params, contextInstance)](./shopware-6-client.updateemail.md) | <b><i>(BETA)</i></b> Update a customer's email |
| [updatePassword(params, contextInstance)](./shopware-6-client.updatepassword.md) | <b><i>(BETA)</i></b> Update a customer's password |
| [updateProfile(params, contextInstance)](./shopware-6-client.updateprofile.md) | <b><i>(BETA)</i></b> Update a customer's profile data |
Expand Down Expand Up @@ -96,8 +97,6 @@
| [getCheckoutCartEndpoint](./shopware-6-client.getcheckoutcartendpoint.md) | <b><i>(BETA)</i></b> |
| [getCheckoutCartLineItemEndpoint](./shopware-6-client.getcheckoutcartlineitemendpoint.md) | <b><i>(BETA)</i></b> |
| [getCheckoutOrderEndpoint](./shopware-6-client.getcheckoutorderendpoint.md) | <b><i>(BETA)</i></b> |
| [getCheckoutOrderPayEndpoint](./shopware-6-client.getcheckoutorderpayendpoint.md) | <b><i>(BETA)</i></b> |
| [getCheckoutPromotionCodeEndpoint](./shopware-6-client.getcheckoutpromotioncodeendpoint.md) | <b><i>(BETA)</i></b> |
| [getContactFormEndpoint](./shopware-6-client.getcontactformendpoint.md) | <b><i>(BETA)</i></b> |
| [getContextCountryEndpoint](./shopware-6-client.getcontextcountryendpoint.md) | <b><i>(BETA)</i></b> |
| [getContextCurrencyEndpoint](./shopware-6-client.getcontextcurrencyendpoint.md) | <b><i>(BETA)</i></b> |
Expand All @@ -106,18 +105,15 @@
| [getContextPaymentMethodEndpoint](./shopware-6-client.getcontextpaymentmethodendpoint.md) | <b><i>(BETA)</i></b> |
| [getContextSalutationEndpoint](./shopware-6-client.getcontextsalutationendpoint.md) | <b><i>(BETA)</i></b> |
| [getContextShippingMethodEndpoint](./shopware-6-client.getcontextshippingmethodendpoint.md) | <b><i>(BETA)</i></b> |
| [getCustomerAddressDetailsEndpoint](./shopware-6-client.getcustomeraddressdetailsendpoint.md) | <b><i>(BETA)</i></b> |
| [getCustomerAddAddressEndpoint](./shopware-6-client.getcustomeraddaddressendpoint.md) | <b><i>(BETA)</i></b> |
| [getCustomerAddressEndpoint](./shopware-6-client.getcustomeraddressendpoint.md) | <b><i>(BETA)</i></b> |
| [getCustomerAddressSetDefaultBillingEndpoint](./shopware-6-client.getcustomeraddresssetdefaultbillingendpoint.md) | <b><i>(BETA)</i></b> |
| [getCustomerAddressSetDefaultShippingEndpoint](./shopware-6-client.getcustomeraddresssetdefaultshippingendpoint.md) | <b><i>(BETA)</i></b> |
| [getCustomerDefaultBillingAddressEndpoint](./shopware-6-client.getcustomerdefaultbillingaddressendpoint.md) | <b><i>(BETA)</i></b> |
| [getCustomerDefaultShippingAddressEndpoint](./shopware-6-client.getcustomerdefaultshippingaddressendpoint.md) | <b><i>(BETA)</i></b> |
| [getCustomerDetailsEndpoint](./shopware-6-client.getcustomerdetailsendpoint.md) | <b><i>(BETA)</i></b> |
| [getCustomerDetailsUpdateEndpoint](./shopware-6-client.getcustomerdetailsupdateendpoint.md) | <b><i>(BETA)</i></b> |
| [getCustomerEndpoint](./shopware-6-client.getcustomerendpoint.md) | <b><i>(BETA)</i></b> |
| [getCustomerLoginEndpoint](./shopware-6-client.getcustomerloginendpoint.md) | <b><i>(BETA)</i></b> |
| [getCustomerLogoutEndpoint](./shopware-6-client.getcustomerlogoutendpoint.md) | <b><i>(BETA)</i></b> |
| [getCustomerOrderDetailsEndpoint](./shopware-6-client.getcustomerorderdetailsendpoint.md) | <b><i>(BETA)</i></b> |
| [getCustomerOrderEndpoint](./shopware-6-client.getcustomerorderendpoint.md) | <b><i>(BETA)</i></b> |
| [getCustomerRegisterEndpoint](./shopware-6-client.getcustomerregisterendpoint.md) | <b><i>(BETA)</i></b> |
| [getCustomerResetPasswordEndpoint](./shopware-6-client.getcustomerresetpasswordendpoint.md) | <b><i>(BETA)</i></b> |
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [@shopware-pwa/shopware-6-client](./shopware-6-client.md) &gt; [updateCustomerAddress](./shopware-6-client.updatecustomeraddress.md)

## updateCustomerAddress() function

> This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.
>
Update an address for specific ID

<b>Signature:</b>

```typescript
export declare function updateCustomerAddress(params: Partial<CustomerAddress>, contextInstance?: ShopwareApiInstance): Promise<CustomerAddress>;
```

## Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| params | Partial&lt;CustomerAddress&gt; | |
| contextInstance | [ShopwareApiInstance](./shopware-6-client.shopwareapiinstance.md) | |

<b>Returns:</b>

Promise&lt;CustomerAddress&gt;

## Exceptions

ClientApiError

54 changes: 47 additions & 7 deletions packages/composables/__tests__/useUser.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -285,10 +285,37 @@ describe("Composables - useUser", () => {
expect(orderDetails).toBe(orderResponse);
});
});

describe("updateAddress", () => {
it("should invoke an endpoint to update an address and return true on success", async () => {
mockedApiClient.updateCustomerAddress.mockResolvedValueOnce(
"ok" as any
);
const { updateAddress } = useUser(rootContextMock);
const response = await updateAddress({
id: "some-address-id",
city: "Wrocław",
});
expect(mockedApiClient.updateCustomerAddress).toBeCalledTimes(1);
expect(response).toBe(true);
});
it("should invoke an endpoint to update an address and return false on fail", async () => {
mockedApiClient.updateCustomerAddress.mockRejectedValueOnce(
new Error("not ok")
);
const { updateAddress } = useUser(rootContextMock);
const response = await updateAddress({
id: "some-address-id",
city: "Wrocław",
});
expect(mockedApiClient.updateCustomerAddress).toBeCalledTimes(1);
expect(response).toBe(false);
});
});
describe("addAddress", () => {
it("should add address", async () => {
mockedApiClient.createCustomerAddress.mockResolvedValueOnce("ok");
mockedApiClient.createCustomerAddress.mockResolvedValueOnce(
"ok" as any
);
const { addAddress } = useUser(rootContextMock);
const response = await addAddress({ city: "Wrocław" });
expect(mockedApiClient.createCustomerAddress).toBeCalledTimes(1);
Expand Down Expand Up @@ -327,11 +354,13 @@ describe("Composables - useUser", () => {

describe("loadAddresses", () => {
it("should invoke client getCustomerAddresses method and assign given array to addresses ref", async () => {
mockedApiClient.getCustomerAddresses.mockResolvedValue([
{
id: "addressId-12345",
},
] as any);
mockedApiClient.getCustomerAddresses.mockResolvedValue({
elements: [
{
id: "addressId-12345",
},
],
} as any);
const { addresses, loadAddresses, error } = useUser(rootContextMock);
await loadAddresses();
expect(mockedApiClient.getCustomerAddresses).toBeCalledTimes(1);
Expand All @@ -343,6 +372,17 @@ describe("Composables - useUser", () => {
]);
});

it("should invoke client getCustomerAddresses method and assign undefined on falsy response", async () => {
mockedApiClient.getCustomerAddresses.mockResolvedValue(
undefined as any
);
const { addresses, loadAddresses, error } = useUser(rootContextMock);
await loadAddresses();
expect(mockedApiClient.getCustomerAddresses).toBeCalledTimes(1);
expect(error.value).toBeFalsy();
expect(addresses.value).toBeUndefined();
});

it("should invoke client getCustomerAddresses method and assign error message if client request is rejected", async () => {
mockedApiClient.getCustomerAddresses.mockRejectedValueOnce({
message: "Something went wrong...",
Expand Down
Loading

0 comments on commit 313e14f

Please sign in to comment.