Skip to content

Commit

Permalink
feat(core): Implement editing & deletion of Order/Customer notes
Browse files Browse the repository at this point in the history
Relates to #310
  • Loading branch information
michaelbromley committed Jun 1, 2020
1 parent 8eea7d6 commit 90bacf5
Show file tree
Hide file tree
Showing 16 changed files with 553 additions and 38 deletions.
35 changes: 35 additions & 0 deletions packages/admin-ui/src/lib/core/src/common/generated-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1869,10 +1869,12 @@ export type Mutation = {
deleteCustomerAddress: Scalars['Boolean'];
/** Delete a CustomerGroup */
deleteCustomerGroup: DeletionResponse;
deleteCustomerNote: DeletionResponse;
/** Delete an existing Facet */
deleteFacet: DeletionResponse;
/** Delete one or more FacetValues */
deleteFacetValues: Array<DeletionResponse>;
deleteOrderNote: DeletionResponse;
/** Delete a Product */
deleteProduct: DeletionResponse;
/** Delete a ProductVariant */
Expand Down Expand Up @@ -1930,11 +1932,13 @@ export type Mutation = {
updateCustomerAddress: Address;
/** Update an existing CustomerGroup */
updateCustomerGroup: CustomerGroup;
updateCustomerNote: HistoryEntry;
/** Update an existing Facet */
updateFacet: Facet;
/** Update one or more FacetValues */
updateFacetValues: Array<FacetValue>;
updateGlobalSettings: GlobalSettings;
updateOrderNote: HistoryEntry;
/** Update an existing PaymentMethod */
updatePaymentMethod: PaymentMethod;
/** Update an existing Product */
Expand Down Expand Up @@ -2142,6 +2146,11 @@ export type MutationDeleteCustomerGroupArgs = {
};


export type MutationDeleteCustomerNoteArgs = {
id: Scalars['ID'];
};


export type MutationDeleteFacetArgs = {
id: Scalars['ID'];
force?: Maybe<Scalars['Boolean']>;
Expand All @@ -2154,6 +2163,11 @@ export type MutationDeleteFacetValuesArgs = {
};


export type MutationDeleteOrderNoteArgs = {
id: Scalars['ID'];
};


export type MutationDeleteProductArgs = {
id: Scalars['ID'];
};
Expand Down Expand Up @@ -2315,6 +2329,11 @@ export type MutationUpdateCustomerGroupArgs = {
};


export type MutationUpdateCustomerNoteArgs = {
input: UpdateCustomerNoteInput;
};


export type MutationUpdateFacetArgs = {
input: UpdateFacetInput;
};
Expand All @@ -2330,6 +2349,11 @@ export type MutationUpdateGlobalSettingsArgs = {
};


export type MutationUpdateOrderNoteArgs = {
input: UpdateOrderNoteInput;
};


export type MutationUpdatePaymentMethodArgs = {
input: UpdatePaymentMethodInput;
};
Expand Down Expand Up @@ -3627,6 +3651,11 @@ export type UpdateCustomerInput = {
customFields?: Maybe<Scalars['JSON']>;
};

export type UpdateCustomerNoteInput = {
noteId: Scalars['ID'];
note: Scalars['String'];
};

export type UpdateFacetInput = {
id: Scalars['ID'];
isPrivate?: Maybe<Scalars['Boolean']>;
Expand All @@ -3648,6 +3677,12 @@ export type UpdateGlobalSettingsInput = {
customFields?: Maybe<Scalars['JSON']>;
};

export type UpdateOrderNoteInput = {
noteId: Scalars['ID'];
note?: Maybe<Scalars['String']>;
isPublic?: Maybe<Scalars['Boolean']>;
};

export type UpdatePaymentMethodInput = {
id: Scalars['ID'];
code?: Maybe<Scalars['String']>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1853,6 +1853,8 @@ export type Mutation = {
/** Update an existing Address */
deleteCustomerAddress: Scalars['Boolean'];
addNoteToCustomer: Customer;
updateCustomerNote: HistoryEntry;
deleteCustomerNote: DeletionResponse;
/** Create a new Facet */
createFacet: Facet;
/** Update an existing Facet */
Expand All @@ -1875,6 +1877,8 @@ export type Mutation = {
refundOrder: Refund;
settleRefund: Refund;
addNoteToOrder: Order;
updateOrderNote: HistoryEntry;
deleteOrderNote: DeletionResponse;
/** Update an existing PaymentMethod */
updatePaymentMethod: PaymentMethod;
/** Create a new ProductOptionGroup */
Expand Down Expand Up @@ -2069,6 +2073,14 @@ export type MutationAddNoteToCustomerArgs = {
input: AddNoteToCustomerInput;
};

export type MutationUpdateCustomerNoteArgs = {
input: UpdateCustomerNoteInput;
};

export type MutationDeleteCustomerNoteArgs = {
id: Scalars['ID'];
};

export type MutationCreateFacetArgs = {
input: CreateFacetInput;
};
Expand Down Expand Up @@ -2132,6 +2144,14 @@ export type MutationAddNoteToOrderArgs = {
input: AddNoteToOrderInput;
};

export type MutationUpdateOrderNoteArgs = {
input: UpdateOrderNoteInput;
};

export type MutationDeleteOrderNoteArgs = {
id: Scalars['ID'];
};

export type MutationUpdatePaymentMethodArgs = {
input: UpdatePaymentMethodInput;
};
Expand Down Expand Up @@ -3463,6 +3483,11 @@ export type UpdateCustomerInput = {
customFields?: Maybe<Scalars['JSON']>;
};

export type UpdateCustomerNoteInput = {
noteId: Scalars['ID'];
note: Scalars['String'];
};

export type UpdateFacetInput = {
id: Scalars['ID'];
isPrivate?: Maybe<Scalars['Boolean']>;
Expand All @@ -3484,6 +3509,12 @@ export type UpdateGlobalSettingsInput = {
customFields?: Maybe<Scalars['JSON']>;
};

export type UpdateOrderNoteInput = {
noteId: Scalars['ID'];
note?: Maybe<Scalars['String']>;
isPublic?: Maybe<Scalars['Boolean']>;
};

export type UpdatePaymentMethodInput = {
id: Scalars['ID'];
code?: Maybe<Scalars['String']>;
Expand Down
35 changes: 35 additions & 0 deletions packages/common/src/generated-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1852,6 +1852,8 @@ export type Mutation = {
/** Update an existing Address */
deleteCustomerAddress: Scalars['Boolean'];
addNoteToCustomer: Customer;
updateCustomerNote: HistoryEntry;
deleteCustomerNote: DeletionResponse;
/** Create a new Facet */
createFacet: Facet;
/** Update an existing Facet */
Expand All @@ -1874,6 +1876,8 @@ export type Mutation = {
refundOrder: Refund;
settleRefund: Refund;
addNoteToOrder: Order;
updateOrderNote: HistoryEntry;
deleteOrderNote: DeletionResponse;
/** Update an existing PaymentMethod */
updatePaymentMethod: PaymentMethod;
/** Create a new ProductOptionGroup */
Expand Down Expand Up @@ -2098,6 +2102,16 @@ export type MutationAddNoteToCustomerArgs = {
};


export type MutationUpdateCustomerNoteArgs = {
input: UpdateCustomerNoteInput;
};


export type MutationDeleteCustomerNoteArgs = {
id: Scalars['ID'];
};


export type MutationCreateFacetArgs = {
input: CreateFacetInput;
};
Expand Down Expand Up @@ -2176,6 +2190,16 @@ export type MutationAddNoteToOrderArgs = {
};


export type MutationUpdateOrderNoteArgs = {
input: UpdateOrderNoteInput;
};


export type MutationDeleteOrderNoteArgs = {
id: Scalars['ID'];
};


export type MutationUpdatePaymentMethodArgs = {
input: UpdatePaymentMethodInput;
};
Expand Down Expand Up @@ -3579,6 +3603,11 @@ export type UpdateCustomerInput = {
customFields?: Maybe<Scalars['JSON']>;
};

export type UpdateCustomerNoteInput = {
noteId: Scalars['ID'];
note: Scalars['String'];
};

export type UpdateFacetInput = {
id: Scalars['ID'];
isPrivate?: Maybe<Scalars['Boolean']>;
Expand All @@ -3600,6 +3629,12 @@ export type UpdateGlobalSettingsInput = {
customFields?: Maybe<Scalars['JSON']>;
};

export type UpdateOrderNoteInput = {
noteId: Scalars['ID'];
note?: Maybe<Scalars['String']>;
isPublic?: Maybe<Scalars['Boolean']>;
};

export type UpdatePaymentMethodInput = {
id: Scalars['ID'];
code?: Maybe<Scalars['String']>;
Expand Down
64 changes: 64 additions & 0 deletions packages/core/e2e/customer.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
CreateCustomer,
DeleteCustomer,
DeleteCustomerAddress,
DeleteCustomerNote,
DeletionResult,
GetCustomer,
GetCustomerHistory,
Expand All @@ -31,6 +32,7 @@ import {
GetCustomerWithUser,
UpdateAddress,
UpdateCustomer,
UpdateCustomerNote,
} from './graphql/generated-e2e-admin-types';
import { AddItemToOrder } from './graphql/generated-e2e-shop-types';
import { GET_CUSTOMER, GET_CUSTOMER_HISTORY, GET_CUSTOMER_LIST } from './graphql/shared-definitions';
Expand Down Expand Up @@ -497,6 +499,8 @@ describe('Customer resolver', () => {
});

describe('customer notes', () => {
let noteId: string;

it('addNoteToCustomer', async () => {
const { addNoteToCustomer } = await adminClient.query<
AddNoteToCustomer.Mutation,
Expand Down Expand Up @@ -531,6 +535,47 @@ describe('Customer resolver', () => {
},
},
]);

noteId = customer?.history.items[0].id!;
});

it('update note', async () => {
const { updateCustomerNote } = await adminClient.query<
UpdateCustomerNote.Mutation,
UpdateCustomerNote.Variables
>(UPDATE_CUSTOMER_NOTE, {
input: {
noteId,
note: 'An updated note',
},
});

expect(updateCustomerNote.data).toEqual({
note: 'An updated note',
});
});

it('delete note', async () => {
const { customer: before } = await adminClient.query<
GetCustomerHistory.Query,
GetCustomerHistory.Variables
>(GET_CUSTOMER_HISTORY, { id: firstCustomer.id });
const historyCount = before?.history.totalItems!;

const { deleteCustomerNote } = await adminClient.query<
DeleteCustomerNote.Mutation,
DeleteCustomerNote.Variables
>(DELETE_CUSTOMER_NOTE, {
id: noteId,
});

expect(deleteCustomerNote.result).toBe(DeletionResult.DELETED);

const { customer: after } = await adminClient.query<
GetCustomerHistory.Query,
GetCustomerHistory.Variables
>(GET_CUSTOMER_HISTORY, { id: firstCustomer.id });
expect(after?.history.totalItems).toBe(historyCount - 1);
});
});
});
Expand Down Expand Up @@ -631,3 +676,22 @@ const ADD_NOTE_TO_CUSTOMER = gql`
}
${CUSTOMER_FRAGMENT}
`;

export const UPDATE_CUSTOMER_NOTE = gql`
mutation UpdateCustomerNote($input: UpdateCustomerNoteInput!) {
updateCustomerNote(input: $input) {
id
data
isPublic
}
}
`;

export const DELETE_CUSTOMER_NOTE = gql`
mutation DeleteCustomerNote($id: ID!) {
deleteCustomerNote(id: $id) {
result
message
}
}
`;
Loading

0 comments on commit 90bacf5

Please sign in to comment.