Commit e8e71412 authored by Diana Zubova's avatar Diana Zubova Committed by Olena Horal-Koretska

Don't sent empty string as quantity

Skip GraphQL call on invalid input
parent b6e77ad5
......@@ -47,7 +47,7 @@ export default {
return this.quantity || 0;
},
set(quantity) {
this.updateQuantity(quantity);
this.updateQuantity(quantity || 0);
},
},
isValid() {
......
......@@ -75,7 +75,7 @@ export default {
logError(error);
},
skip() {
return !this.purchaseHasExpiration;
return !this.purchaseHasExpiration || !this.quantity;
},
},
},
......
......@@ -32,6 +32,10 @@ describe('Order Summary', () => {
const findAmount = () => wrapper.findByTestId('amount');
const findTitle = () => wrapper.findByTestId('title');
const orderPreviewHandlerMock = jest
.fn()
.mockResolvedValue({ data: { orderPreview: mockOrderPreview } });
const createMockApolloProvider = (stateData = {}, mockRequest = {}) => {
const mockApollo = createMockApollo([], resolvers);
const data = merge({}, mockStateData, initialStateData, stateData);
......@@ -96,12 +100,9 @@ describe('Order Summary', () => {
describe('when subscription has expiration date', () => {
describe('calls api that returns prorated amount', () => {
beforeEach(async () => {
const orderPreviewQueryMock = jest
.fn()
.mockResolvedValue({ data: { orderPreview: mockOrderPreview } });
const apolloProvider = createMockApolloProvider(
{ subscription: { quantity: 1 } },
orderPreviewQueryMock,
orderPreviewHandlerMock,
);
createComponent(apolloProvider, { purchaseHasExpiration: true });
await waitForPromises();
......@@ -182,5 +183,19 @@ describe('Order Summary', () => {
expect(findAmount().text()).toBe('-');
});
});
describe('when subscription quantity is 0', () => {
beforeEach(() => {
const apolloProvider = createMockApolloProvider(
{ subscription: { quantity: 0 } },
orderPreviewHandlerMock,
);
createComponent(apolloProvider, { purchaseHasExpiration: true });
});
it('doesn not call api', () => {
expect(orderPreviewHandlerMock).not.toHaveBeenCalled();
});
});
});
});
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment