From c7f3ea94b9c393cff32ed97435c15051255ab2b8 Mon Sep 17 00:00:00 2001 From: Kimmo Puputti Date: Tue, 5 Sep 2017 14:38:06 +0300 Subject: [PATCH] Clean up booking and listing creation in tests --- .../ListingCard/ListingCard.example.js | 3 +-- .../ListingCard/ListingCard.test.js | 3 +-- .../OrderDetailsPanel.test.js | 18 ++++++++--------- .../OrderDetailsPanel.test.js.snap | 2 -- .../SaleDetailsPanel/SaleDetailsPanel.test.js | 18 ++++++++--------- .../SaleDetailsPanel.test.js.snap | 2 -- .../CheckoutPage/CheckoutPage.test.js | 20 ++++++++++++++----- src/containers/InboxPage/InboxPage.test.js | 18 ++++++++--------- .../ListingPage/ListingPage.test.js | 2 +- src/containers/OrderPage/OrderPage.test.js | 9 ++++----- .../__snapshots__/OrderPage.test.js.snap | 1 - src/containers/SalePage/SalePage.test.js | 9 ++++----- .../__snapshots__/SalePage.test.js.snap | 1 - src/util/test-data.js | 16 ++++++++------- 14 files changed, 59 insertions(+), 63 deletions(-) diff --git a/src/components/ListingCard/ListingCard.example.js b/src/components/ListingCard/ListingCard.example.js index c9ce3a49..4ca3c648 100644 --- a/src/components/ListingCard/ListingCard.example.js +++ b/src/components/ListingCard/ListingCard.example.js @@ -3,8 +3,7 @@ import React from 'react'; import ListingCard from './ListingCard'; import { createUser, createListing, fakeIntl } from '../../util/test-data'; -const author = createUser('user1'); -const listing = { ...createListing('listing1'), author }; +const listing = createListing('listing1', {}, { author: createUser('user1') }); const ListingCardWrapper = props => (
diff --git a/src/components/ListingCard/ListingCard.test.js b/src/components/ListingCard/ListingCard.test.js index 7d6bd0af..d0540407 100644 --- a/src/components/ListingCard/ListingCard.test.js +++ b/src/components/ListingCard/ListingCard.test.js @@ -5,8 +5,7 @@ import { ListingCardComponent } from './ListingCard'; describe('ListingCard', () => { it('matches snapshot', () => { - const author = createUser('user1'); - const listing = { ...createListing('listing1'), author }; + const listing = createListing('listing1', {}, { author: createUser('user1') }); const tree = renderShallow(); expect(tree).toMatchSnapshot(); }); diff --git a/src/components/OrderDetailsPanel/OrderDetailsPanel.test.js b/src/components/OrderDetailsPanel/OrderDetailsPanel.test.js index 8cc98e5b..cda418bd 100644 --- a/src/components/OrderDetailsPanel/OrderDetailsPanel.test.js +++ b/src/components/OrderDetailsPanel/OrderDetailsPanel.test.js @@ -13,11 +13,10 @@ describe('OrderDetailsPanel', () => { id: 'order-tx', state: 'state/preauthorized', total: new Money(16500, 'USD'), - booking: createBooking( - 'booking1', - new Date(Date.UTC(2017, 5, 10)), - new Date(Date.UTC(2017, 5, 13)) - ), + booking: createBooking('booking1', { + start: new Date(Date.UTC(2017, 5, 10)), + end: new Date(Date.UTC(2017, 5, 13)), + }), listing: createListing('listing1'), provider: createUser('provider'), customer: createUser('customer'), @@ -31,11 +30,10 @@ describe('OrderDetailsPanel', () => { id: 'order-tx', state: 'state/preauthorized', total: new Money(16500, 'USD'), - booking: createBooking( - 'booking1', - new Date(Date.UTC(2017, 5, 10)), - new Date(Date.UTC(2017, 5, 13)) - ), + booking: createBooking('booking1', { + start: new Date(Date.UTC(2017, 5, 10)), + end: new Date(Date.UTC(2017, 5, 13)), + }), listing: createListing('listing1'), provider: createUser('provider'), customer: createUser('customer'), diff --git a/src/components/OrderDetailsPanel/__snapshots__/OrderDetailsPanel.test.js.snap b/src/components/OrderDetailsPanel/__snapshots__/OrderDetailsPanel.test.js.snap index f7139c22..6a2793b2 100644 --- a/src/components/OrderDetailsPanel/__snapshots__/OrderDetailsPanel.test.js.snap +++ b/src/components/OrderDetailsPanel/__snapshots__/OrderDetailsPanel.test.js.snap @@ -182,7 +182,6 @@ exports[`OrderDetailsPanel matches snapshot 1`] = ` }, "title": "listing1 title", }, - "author": null, "id": UUID { "uuid": "listing1", }, @@ -357,7 +356,6 @@ exports[`OrderDetailsPanel matches snapshot 1`] = ` }, "title": "listing1 title", }, - "author": null, "id": UUID { "uuid": "listing1", }, diff --git a/src/components/SaleDetailsPanel/SaleDetailsPanel.test.js b/src/components/SaleDetailsPanel/SaleDetailsPanel.test.js index 3af6c90a..004273a4 100644 --- a/src/components/SaleDetailsPanel/SaleDetailsPanel.test.js +++ b/src/components/SaleDetailsPanel/SaleDetailsPanel.test.js @@ -16,11 +16,10 @@ describe('SaleDetailsPanel', () => { state: 'state/preauthorized', total: new Money(16500, 'USD'), commission: new Money(1000, 'USD'), - booking: createBooking( - 'booking1', - new Date(Date.UTC(2017, 5, 10)), - new Date(Date.UTC(2017, 5, 13)) - ), + booking: createBooking('booking1', { + start: new Date(Date.UTC(2017, 5, 10)), + end: new Date(Date.UTC(2017, 5, 13)), + }), listing: createListing('listing1'), customer: createUser('customer1'), lastTransitionedAt: new Date(Date.UTC(2017, 5, 10)), @@ -41,11 +40,10 @@ describe('SaleDetailsPanel', () => { state: 'state/preauthorized', total: new Money(16500, 'USD'), commission: new Money(1000, 'USD'), - booking: createBooking( - 'booking1', - new Date(Date.UTC(2017, 5, 10)), - new Date(Date.UTC(2017, 5, 13)) - ), + booking: createBooking('booking1', { + start: new Date(Date.UTC(2017, 5, 10)), + end: new Date(Date.UTC(2017, 5, 13)), + }), listing: createListing('listing1'), customer: createUser('customer1'), lastTransitionedAt: new Date(Date.UTC(2017, 5, 10)), diff --git a/src/components/SaleDetailsPanel/__snapshots__/SaleDetailsPanel.test.js.snap b/src/components/SaleDetailsPanel/__snapshots__/SaleDetailsPanel.test.js.snap index 794e75b8..3af95508 100644 --- a/src/components/SaleDetailsPanel/__snapshots__/SaleDetailsPanel.test.js.snap +++ b/src/components/SaleDetailsPanel/__snapshots__/SaleDetailsPanel.test.js.snap @@ -203,7 +203,6 @@ exports[`SaleDetailsPanel matches snapshot 1`] = ` }, "title": "listing1 title", }, - "author": null, "id": UUID { "uuid": "listing1", }, @@ -337,7 +336,6 @@ exports[`SaleDetailsPanel matches snapshot 1`] = ` }, "title": "listing1 title", }, - "author": null, "id": UUID { "uuid": "listing1", }, diff --git a/src/containers/CheckoutPage/CheckoutPage.test.js b/src/containers/CheckoutPage/CheckoutPage.test.js index 0967b3a1..5cbb6652 100644 --- a/src/containers/CheckoutPage/CheckoutPage.test.js +++ b/src/containers/CheckoutPage/CheckoutPage.test.js @@ -8,7 +8,7 @@ const noop = () => null; describe('CheckoutPage', () => { it('matches snapshot', () => { - const listing = createListing('listing1', createUser('author')); + const listing = createListing('listing1', {}, { author: createUser('author') }); const props = { bookingDates: { bookingStart: new Date(Date.UTC(2017, 3, 14)), @@ -30,8 +30,13 @@ describe('CheckoutPage', () => { describe('Duck', () => { it('ActionCreator: setInitialValues(initialValues)', () => { - const author = createUser('author1'); - const listing = { ...createListing('00000000-0000-0000-0000-000000000000'), author }; + const listing = createListing( + '00000000-0000-0000-0000-000000000000', + {}, + { + author: createUser('author1'), + } + ); const bookingDates = { bookingStart: new Date(Date.UTC(2017, 3, 14)), bookingEnd: new Date(Date.UTC(2017, 3, 16)), @@ -59,8 +64,13 @@ describe('CheckoutPage', () => { }); it('should handle SET_INITAL_VALUES', () => { - const author = createUser('author1'); - const listing = { ...createListing('00000000-0000-0000-0000-000000000000'), author }; + const listing = createListing( + '00000000-0000-0000-0000-000000000000', + {}, + { + author: createUser('author1'), + } + ); const bookingDates = { bookingStart: new Date(Date.UTC(2017, 3, 14)), bookingEnd: new Date(Date.UTC(2017, 3, 16)), diff --git a/src/containers/InboxPage/InboxPage.test.js b/src/containers/InboxPage/InboxPage.test.js index 5a5faa96..d91da86d 100644 --- a/src/containers/InboxPage/InboxPage.test.js +++ b/src/containers/InboxPage/InboxPage.test.js @@ -13,16 +13,14 @@ describe('InboxPage', () => { const flattenedRoutes = flattenRoutes(routesConfiguration); const provider = createUser('provider-user-id'); const customer = createUser('customer-user-id'); - const booking1 = createBooking( - 'booking1', - new Date(Date.UTC(2017, 1, 15)), - new Date(Date.UTC(2017, 1, 16)) - ); - const booking2 = createBooking( - 'booking2', - new Date(Date.UTC(2017, 2, 15)), - new Date(Date.UTC(2017, 2, 16)) - ); + const booking1 = createBooking('booking1', { + start: new Date(Date.UTC(2017, 1, 15)), + end: new Date(Date.UTC(2017, 1, 16)), + }); + const booking2 = createBooking('booking2', { + start: new Date(Date.UTC(2017, 2, 15)), + end: new Date(Date.UTC(2017, 2, 16)), + }); const ordersProps = { location: { search: '' }, diff --git a/src/containers/ListingPage/ListingPage.test.js b/src/containers/ListingPage/ListingPage.test.js index 9c9ecc09..2aac0c18 100644 --- a/src/containers/ListingPage/ListingPage.test.js +++ b/src/containers/ListingPage/ListingPage.test.js @@ -12,7 +12,7 @@ const noop = () => null; describe('ListingPage', () => { it('matches snapshot', () => { const currentUser = createCurrentUser('user-2'); - const listing1 = createListing('listing1', createUser('user-1')); + const listing1 = createListing('listing1', {}, { author: createUser('user-1') }); const getListing = () => listing1; const props = { flattenedRoutes: [], diff --git a/src/containers/OrderPage/OrderPage.test.js b/src/containers/OrderPage/OrderPage.test.js index 1ada4123..7f6decb6 100644 --- a/src/containers/OrderPage/OrderPage.test.js +++ b/src/containers/OrderPage/OrderPage.test.js @@ -18,11 +18,10 @@ describe('OrderPage', () => { const transaction = createTransaction({ id: txId, state: 'state/preauthorized', - booking: createBooking( - 'booking1', - new Date(Date.UTC(2017, 5, 10)), - new Date(Date.UTC(2017, 5, 13)) - ), + booking: createBooking('booking1', { + start: new Date(Date.UTC(2017, 5, 10)), + end: new Date(Date.UTC(2017, 5, 13)), + }), listing: createListing('listing1'), customer: createUser('customer1'), provider: createUser('provider1'), diff --git a/src/containers/OrderPage/__snapshots__/OrderPage.test.js.snap b/src/containers/OrderPage/__snapshots__/OrderPage.test.js.snap index 3cd367a2..b505fca6 100644 --- a/src/containers/OrderPage/__snapshots__/OrderPage.test.js.snap +++ b/src/containers/OrderPage/__snapshots__/OrderPage.test.js.snap @@ -124,7 +124,6 @@ exports[`OrderPage matches snapshot 1`] = ` }, "title": "listing1 title", }, - "author": null, "id": UUID { "uuid": "listing1", }, diff --git a/src/containers/SalePage/SalePage.test.js b/src/containers/SalePage/SalePage.test.js index d555415b..0b1b5a8c 100644 --- a/src/containers/SalePage/SalePage.test.js +++ b/src/containers/SalePage/SalePage.test.js @@ -18,11 +18,10 @@ describe('SalePage', () => { const transaction = createTransaction({ id: txId, state: 'state/preauthorized', - booking: createBooking( - 'booking1', - new Date(Date.UTC(2017, 5, 10)), - new Date(Date.UTC(2017, 5, 13)) - ), + booking: createBooking('booking1', { + start: new Date(Date.UTC(2017, 5, 10)), + end: new Date(Date.UTC(2017, 5, 13)), + }), listing: createListing('listing1'), customer: createUser('customer1'), provider: createUser('provider1'), diff --git a/src/containers/SalePage/__snapshots__/SalePage.test.js.snap b/src/containers/SalePage/__snapshots__/SalePage.test.js.snap index d8e9e400..894ca5c7 100644 --- a/src/containers/SalePage/__snapshots__/SalePage.test.js.snap +++ b/src/containers/SalePage/__snapshots__/SalePage.test.js.snap @@ -128,7 +128,6 @@ exports[`SalePage matches snapshot 1`] = ` }, "title": "listing1 title", }, - "author": null, "id": UUID { "uuid": "listing1", }, diff --git a/src/util/test-data.js b/src/util/test-data.js index 9359c4c2..9a8d9903 100644 --- a/src/util/test-data.js +++ b/src/util/test-data.js @@ -6,12 +6,13 @@ import * as propTypes from '../util/propTypes'; const { UUID, LatLng, Money } = types; // Create a booking that conforms to the util/propTypes booking schema -export const createBooking = (id, startDateInUTC, endDateInUTC) => ({ +export const createBooking = (id, attributes = {}) => ({ id: new UUID(id), type: 'booking', attributes: { - start: startDateInUTC, - end: endDateInUTC, + start: new Date(Date.UTC(2017, 5, 10)), + end: new Date(Date.UTC(2017, 5, 10)), + ...attributes, }, }); @@ -66,18 +67,19 @@ export const createImage = id => ({ }); // Create a user that conforms to the util/propTypes listing schema -export const createListing = (id, author = null, price = new Money(5500, 'USD')) => ({ +export const createListing = (id, attributes = {}, includes = {}) => ({ id: new UUID(id), type: 'listing', attributes: { title: `${id} title`, - open: true, - price, description: `${id} description`, address: `${id} address`, geolocation: new LatLng(40, 60), + open: true, + price: new Money(5500, 'USD'), + ...attributes, }, - author, + ...includes, }); // Create a user that conforms to the util/propTypes listing schema