Skip to content

Commit

Permalink
feat(cart): handle create errors in Magento driver (#2536)
Browse files Browse the repository at this point in the history
  • Loading branch information
griest024 committed Aug 10, 2023
1 parent cffee10 commit 4ead116
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
28 changes: 28 additions & 0 deletions libs/cart/driver/magento/src/cart.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,34 @@ describe('@daffodil/cart/driver/magento | DaffMagentoCartService', () => {
});

describe('create | creates the cart', () => {
describe('when there are graphQL errors', () => {
it('should throw the error', done => {
service.create().pipe(
catchError((err) => {
expect(err).toEqual(jasmine.any(DaffCartNotFoundError));
done();
return of();
}),
).subscribe(result => {
fail('create should throw, not emit');
});

const op = controller.expectOne(addTypenameToDocument(createCart));

op.flush({
errors: [new GraphQLError(
'Can\'t find a cart with that ID.',
null,
null,
null,
null,
null,
{ category: 'graphql-no-such-entity' },
)],
});
});
});

it('should return an observable with the cart ID', done => {
service.create().subscribe(result => {
expect(result.id).toEqual(cartId);
Expand Down
1 change: 1 addition & 0 deletions libs/cart/driver/magento/src/cart.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ export class DaffMagentoCartService implements DaffCartServiceInterface<DaffCart
create(): Observable<{id: DaffCart['id']}> {
return this.mutationQueue.mutate<MagentoCreateCartResponse>({ mutation: createCart }).pipe(
map(result => ({ id: result.data.createEmptyCart })),
catchError(err => throwError(() => transformCartMagentoError(err))),
);
}

Expand Down

0 comments on commit 4ead116

Please sign in to comment.