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 { ...@@ -47,7 +47,7 @@ export default {
return this.quantity || 0; return this.quantity || 0;
}, },
set(quantity) { set(quantity) {
this.updateQuantity(quantity); this.updateQuantity(quantity || 0);
}, },
}, },
isValid() { isValid() {
......
...@@ -75,7 +75,7 @@ export default { ...@@ -75,7 +75,7 @@ export default {
logError(error); logError(error);
}, },
skip() { skip() {
return !this.purchaseHasExpiration; return !this.purchaseHasExpiration || !this.quantity;
}, },
}, },
}, },
......
...@@ -32,6 +32,10 @@ describe('Order Summary', () => { ...@@ -32,6 +32,10 @@ describe('Order Summary', () => {
const findAmount = () => wrapper.findByTestId('amount'); const findAmount = () => wrapper.findByTestId('amount');
const findTitle = () => wrapper.findByTestId('title'); const findTitle = () => wrapper.findByTestId('title');
const orderPreviewHandlerMock = jest
.fn()
.mockResolvedValue({ data: { orderPreview: mockOrderPreview } });
const createMockApolloProvider = (stateData = {}, mockRequest = {}) => { const createMockApolloProvider = (stateData = {}, mockRequest = {}) => {
const mockApollo = createMockApollo([], resolvers); const mockApollo = createMockApollo([], resolvers);
const data = merge({}, mockStateData, initialStateData, stateData); const data = merge({}, mockStateData, initialStateData, stateData);
...@@ -96,12 +100,9 @@ describe('Order Summary', () => { ...@@ -96,12 +100,9 @@ describe('Order Summary', () => {
describe('when subscription has expiration date', () => { describe('when subscription has expiration date', () => {
describe('calls api that returns prorated amount', () => { describe('calls api that returns prorated amount', () => {
beforeEach(async () => { beforeEach(async () => {
const orderPreviewQueryMock = jest
.fn()
.mockResolvedValue({ data: { orderPreview: mockOrderPreview } });
const apolloProvider = createMockApolloProvider( const apolloProvider = createMockApolloProvider(
{ subscription: { quantity: 1 } }, { subscription: { quantity: 1 } },
orderPreviewQueryMock, orderPreviewHandlerMock,
); );
createComponent(apolloProvider, { purchaseHasExpiration: true }); createComponent(apolloProvider, { purchaseHasExpiration: true });
await waitForPromises(); await waitForPromises();
...@@ -182,5 +183,19 @@ describe('Order Summary', () => { ...@@ -182,5 +183,19 @@ describe('Order Summary', () => {
expect(findAmount().text()).toBe('-'); 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