mirror of
https://github.com/kingomarnajjar/flex-template-web.git
synced 2026-07-29 05:00:43 +10:00
Clean up booking and listing creation in tests
This commit is contained in:
parent
fb305e42fe
commit
c7f3ea94b9
14 changed files with 59 additions and 63 deletions
|
|
@ -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 => (
|
||||
<div style={{ maxWidth: '400px' }}>
|
||||
|
|
|
|||
|
|
@ -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(<ListingCardComponent listing={listing} intl={fakeIntl} />);
|
||||
expect(tree).toMatchSnapshot();
|
||||
});
|
||||
|
|
|
|||
|
|
@ -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'),
|
||||
|
|
|
|||
|
|
@ -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",
|
||||
},
|
||||
|
|
|
|||
|
|
@ -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)),
|
||||
|
|
|
|||
|
|
@ -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",
|
||||
},
|
||||
|
|
|
|||
|
|
@ -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)),
|
||||
|
|
|
|||
|
|
@ -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: '' },
|
||||
|
|
|
|||
|
|
@ -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: [],
|
||||
|
|
|
|||
|
|
@ -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'),
|
||||
|
|
|
|||
|
|
@ -124,7 +124,6 @@ exports[`OrderPage matches snapshot 1`] = `
|
|||
},
|
||||
"title": "listing1 title",
|
||||
},
|
||||
"author": null,
|
||||
"id": UUID {
|
||||
"uuid": "listing1",
|
||||
},
|
||||
|
|
|
|||
|
|
@ -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'),
|
||||
|
|
|
|||
|
|
@ -128,7 +128,6 @@ exports[`SalePage matches snapshot 1`] = `
|
|||
},
|
||||
"title": "listing1 title",
|
||||
},
|
||||
"author": null,
|
||||
"id": UUID {
|
||||
"uuid": "listing1",
|
||||
},
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue