Merge pull request #1050 from sharetribe/use-booking-displayStart-displayEnd

Use displayStart and dislayEnd (Booking entity)
This commit is contained in:
Vesa Luusua 2019-03-25 17:49:07 +02:00 committed by GitHub
commit f7d5341988
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 183 additions and 22 deletions

View file

@ -14,6 +14,9 @@ way to update this template, but currently, we follow a pattern:
## Upcoming version 2019-XX-XX
- [add] Booking: use attributes `displayStart` and `displayEnd`, instead of reading booking period
directly from `start` and `end` attributes.
[#1050](https://github.com/sharetribe/flex-template-web/pull/1050)
- [fix] A listing title that contained only stripped-off characters caused bugs in slug / pathName
generation. [#1048](https://github.com/sharetribe/flex-template-web/pull/1048)
- [change] Removed Node-engine setup from package.json. Fixed version was causing problems for quite

View file

@ -40,9 +40,13 @@ const BookingPeriod = props => {
const LineItemBookingPeriod = props => {
const { transaction, booking, unitType } = props;
const { start: startDate, end: endDateRaw } = booking.attributes;
const localStartDate = dateFromAPIToLocalNoon(startDate);
const localEndDateRaw = dateFromAPIToLocalNoon(endDateRaw);
// Attributes: displayStart and displayEnd can be used to differentiate shown time range
// from actual start and end times used for availability reservation. It can help in situations
// where there are preparation time needed between bookings.
// Read more: https://www.sharetribe.com/api-reference/#bookings
const { start, end, displayStart, displayEnd } = booking.attributes;
const localStartDate = dateFromAPIToLocalNoon(displayStart || start);
const localEndDateRaw = dateFromAPIToLocalNoon(displayEnd || end);
const isNightly = unitType === LINE_ITEM_NIGHT;
const isDaily = unitType === LINE_ITEM_DAY;

View file

@ -31,12 +31,17 @@ const { Money } = sdkTypes;
describe('TransactionPanel - Sale', () => {
const providerId = 'provider';
const customerId = 'customer';
const start = new Date(Date.UTC(2017, 5, 10));
const end = new Date(Date.UTC(2017, 5, 13));
const baseTxAttrs = {
total: new Money(16500, 'USD'),
commission: new Money(1000, 'USD'),
booking: createBooking('booking1', {
start: new Date(Date.UTC(2017, 5, 10)),
end: new Date(Date.UTC(2017, 5, 13)),
start,
end,
displayStart: start,
displayEnd: end,
}),
listing: createListing('listing1'),
customer: createUser(customerId),
@ -187,14 +192,19 @@ describe('TransactionPanel - Sale', () => {
expect(tree).toMatchSnapshot();
});
it('renders correct total price', () => {
const start = new Date(Date.UTC(2017, 5, 10));
const end = new Date(Date.UTC(2017, 5, 13));
const transaction = createTransaction({
id: 'sale-tx',
lastTransition: TRANSITION_REQUEST,
total: new Money(16500, 'USD'),
commission: new Money(1000, 'USD'),
booking: createBooking('booking1', {
start: new Date(Date.UTC(2017, 5, 10)),
end: new Date(Date.UTC(2017, 5, 13)),
start,
end,
displayStart: start,
displayEnd: end,
}),
listing: createListing('listing1'),
customer: createUser('customer1'),
@ -219,11 +229,15 @@ describe('TransactionPanel - Sale', () => {
describe('TransactionPanel - Order', () => {
const providerId = 'provider';
const customerId = 'customer';
const start = new Date(Date.UTC(2017, 5, 10));
const end = new Date(Date.UTC(2017, 5, 13));
const baseTxAttrs = {
total: new Money(16500, 'USD'),
booking: createBooking('booking1', {
start: new Date(Date.UTC(2017, 5, 10)),
end: new Date(Date.UTC(2017, 5, 13)),
start,
end,
displayStart: start,
displayEnd: end,
}),
listing: createListing('listing1'),
provider: createUser(providerId),
@ -375,13 +389,17 @@ describe('TransactionPanel - Order', () => {
expect(tree).toMatchSnapshot();
});
it('renders correct total price', () => {
const start = new Date(Date.UTC(2017, 5, 10));
const end = new Date(Date.UTC(2017, 5, 13));
const tx = createTransaction({
id: 'order-tx',
lastTransition: TRANSITION_REQUEST,
total: new Money(16500, 'USD'),
booking: createBooking('booking1', {
start: new Date(Date.UTC(2017, 5, 10)),
end: new Date(Date.UTC(2017, 5, 13)),
start,
end,
displayStart: start,
displayEnd: end,
}),
listing: createListing('listing1'),
provider: createUser(providerId),

View file

@ -181,6 +181,8 @@ exports[`TransactionPanel - Order accepted matches snapshot 1`] = `
},
"booking": Object {
"attributes": Object {
"displayEnd": 2017-06-13T00:00:00.000Z,
"displayStart": 2017-06-10T00:00:00.000Z,
"end": 2017-06-13T00:00:00.000Z,
"start": 2017-06-10T00:00:00.000Z,
},
@ -311,6 +313,8 @@ exports[`TransactionPanel - Order accepted matches snapshot 1`] = `
},
"booking": Object {
"attributes": Object {
"displayEnd": 2017-06-13T00:00:00.000Z,
"displayStart": 2017-06-10T00:00:00.000Z,
"end": 2017-06-13T00:00:00.000Z,
"start": 2017-06-10T00:00:00.000Z,
},
@ -570,6 +574,8 @@ exports[`TransactionPanel - Order accepted matches snapshot 1`] = `
},
"booking": Object {
"attributes": Object {
"displayEnd": 2017-06-13T00:00:00.000Z,
"displayStart": 2017-06-10T00:00:00.000Z,
"end": 2017-06-13T00:00:00.000Z,
"start": 2017-06-10T00:00:00.000Z,
},
@ -867,6 +873,8 @@ exports[`TransactionPanel - Order autodeclined matches snapshot 1`] = `
},
"booking": Object {
"attributes": Object {
"displayEnd": 2017-06-13T00:00:00.000Z,
"displayStart": 2017-06-10T00:00:00.000Z,
"end": 2017-06-13T00:00:00.000Z,
"start": 2017-06-10T00:00:00.000Z,
},
@ -997,6 +1005,8 @@ exports[`TransactionPanel - Order autodeclined matches snapshot 1`] = `
},
"booking": Object {
"attributes": Object {
"displayEnd": 2017-06-13T00:00:00.000Z,
"displayStart": 2017-06-10T00:00:00.000Z,
"end": 2017-06-13T00:00:00.000Z,
"start": 2017-06-10T00:00:00.000Z,
},
@ -1255,6 +1265,8 @@ exports[`TransactionPanel - Order autodeclined matches snapshot 1`] = `
},
"booking": Object {
"attributes": Object {
"displayEnd": 2017-06-13T00:00:00.000Z,
"displayStart": 2017-06-10T00:00:00.000Z,
"end": 2017-06-13T00:00:00.000Z,
"start": 2017-06-10T00:00:00.000Z,
},
@ -1553,6 +1565,8 @@ exports[`TransactionPanel - Order canceled matches snapshot 1`] = `
},
"booking": Object {
"attributes": Object {
"displayEnd": 2017-06-13T00:00:00.000Z,
"displayStart": 2017-06-10T00:00:00.000Z,
"end": 2017-06-13T00:00:00.000Z,
"start": 2017-06-10T00:00:00.000Z,
},
@ -1683,6 +1697,8 @@ exports[`TransactionPanel - Order canceled matches snapshot 1`] = `
},
"booking": Object {
"attributes": Object {
"displayEnd": 2017-06-13T00:00:00.000Z,
"displayStart": 2017-06-10T00:00:00.000Z,
"end": 2017-06-13T00:00:00.000Z,
"start": 2017-06-10T00:00:00.000Z,
},
@ -1942,6 +1958,8 @@ exports[`TransactionPanel - Order canceled matches snapshot 1`] = `
},
"booking": Object {
"attributes": Object {
"displayEnd": 2017-06-13T00:00:00.000Z,
"displayStart": 2017-06-10T00:00:00.000Z,
"end": 2017-06-13T00:00:00.000Z,
"start": 2017-06-10T00:00:00.000Z,
},
@ -2239,6 +2257,8 @@ exports[`TransactionPanel - Order declined matches snapshot 1`] = `
},
"booking": Object {
"attributes": Object {
"displayEnd": 2017-06-13T00:00:00.000Z,
"displayStart": 2017-06-10T00:00:00.000Z,
"end": 2017-06-13T00:00:00.000Z,
"start": 2017-06-10T00:00:00.000Z,
},
@ -2369,6 +2389,8 @@ exports[`TransactionPanel - Order declined matches snapshot 1`] = `
},
"booking": Object {
"attributes": Object {
"displayEnd": 2017-06-13T00:00:00.000Z,
"displayStart": 2017-06-10T00:00:00.000Z,
"end": 2017-06-13T00:00:00.000Z,
"start": 2017-06-10T00:00:00.000Z,
},
@ -2627,6 +2649,8 @@ exports[`TransactionPanel - Order declined matches snapshot 1`] = `
},
"booking": Object {
"attributes": Object {
"displayEnd": 2017-06-13T00:00:00.000Z,
"displayStart": 2017-06-10T00:00:00.000Z,
"end": 2017-06-13T00:00:00.000Z,
"start": 2017-06-10T00:00:00.000Z,
},
@ -2930,6 +2954,8 @@ exports[`TransactionPanel - Order delivered matches snapshot 1`] = `
},
"booking": Object {
"attributes": Object {
"displayEnd": 2017-06-13T00:00:00.000Z,
"displayStart": 2017-06-10T00:00:00.000Z,
"end": 2017-06-13T00:00:00.000Z,
"start": 2017-06-10T00:00:00.000Z,
},
@ -3065,6 +3091,8 @@ exports[`TransactionPanel - Order delivered matches snapshot 1`] = `
},
"booking": Object {
"attributes": Object {
"displayEnd": 2017-06-13T00:00:00.000Z,
"displayStart": 2017-06-10T00:00:00.000Z,
"end": 2017-06-13T00:00:00.000Z,
"start": 2017-06-10T00:00:00.000Z,
},
@ -3329,6 +3357,8 @@ exports[`TransactionPanel - Order delivered matches snapshot 1`] = `
},
"booking": Object {
"attributes": Object {
"displayEnd": 2017-06-13T00:00:00.000Z,
"displayStart": 2017-06-10T00:00:00.000Z,
"end": 2017-06-13T00:00:00.000Z,
"start": 2017-06-10T00:00:00.000Z,
},
@ -3626,6 +3656,8 @@ exports[`TransactionPanel - Order enquired matches snapshot 1`] = `
},
"booking": Object {
"attributes": Object {
"displayEnd": 2017-06-13T00:00:00.000Z,
"displayStart": 2017-06-10T00:00:00.000Z,
"end": 2017-06-13T00:00:00.000Z,
"start": 2017-06-10T00:00:00.000Z,
},
@ -3756,6 +3788,8 @@ exports[`TransactionPanel - Order enquired matches snapshot 1`] = `
},
"booking": Object {
"attributes": Object {
"displayEnd": 2017-06-13T00:00:00.000Z,
"displayStart": 2017-06-10T00:00:00.000Z,
"end": 2017-06-13T00:00:00.000Z,
"start": 2017-06-10T00:00:00.000Z,
},
@ -4013,6 +4047,8 @@ exports[`TransactionPanel - Order enquired matches snapshot 1`] = `
},
"booking": Object {
"attributes": Object {
"displayEnd": 2017-06-13T00:00:00.000Z,
"displayStart": 2017-06-10T00:00:00.000Z,
"end": 2017-06-13T00:00:00.000Z,
"start": 2017-06-10T00:00:00.000Z,
},
@ -4310,6 +4346,8 @@ exports[`TransactionPanel - Order preauthorized matches snapshot 1`] = `
},
"booking": Object {
"attributes": Object {
"displayEnd": 2017-06-13T00:00:00.000Z,
"displayStart": 2017-06-10T00:00:00.000Z,
"end": 2017-06-13T00:00:00.000Z,
"start": 2017-06-10T00:00:00.000Z,
},
@ -4440,6 +4478,8 @@ exports[`TransactionPanel - Order preauthorized matches snapshot 1`] = `
},
"booking": Object {
"attributes": Object {
"displayEnd": 2017-06-13T00:00:00.000Z,
"displayStart": 2017-06-10T00:00:00.000Z,
"end": 2017-06-13T00:00:00.000Z,
"start": 2017-06-10T00:00:00.000Z,
},
@ -4698,6 +4738,8 @@ exports[`TransactionPanel - Order preauthorized matches snapshot 1`] = `
},
"booking": Object {
"attributes": Object {
"displayEnd": 2017-06-13T00:00:00.000Z,
"displayStart": 2017-06-10T00:00:00.000Z,
"end": 2017-06-13T00:00:00.000Z,
"start": 2017-06-10T00:00:00.000Z,
},
@ -4996,6 +5038,8 @@ exports[`TransactionPanel - Sale accepted matches snapshot 1`] = `
},
"booking": Object {
"attributes": Object {
"displayEnd": 2017-06-13T00:00:00.000Z,
"displayStart": 2017-06-10T00:00:00.000Z,
"end": 2017-06-13T00:00:00.000Z,
"start": 2017-06-10T00:00:00.000Z,
},
@ -5126,6 +5170,8 @@ exports[`TransactionPanel - Sale accepted matches snapshot 1`] = `
},
"booking": Object {
"attributes": Object {
"displayEnd": 2017-06-13T00:00:00.000Z,
"displayStart": 2017-06-10T00:00:00.000Z,
"end": 2017-06-13T00:00:00.000Z,
"start": 2017-06-10T00:00:00.000Z,
},
@ -5385,6 +5431,8 @@ exports[`TransactionPanel - Sale accepted matches snapshot 1`] = `
},
"booking": Object {
"attributes": Object {
"displayEnd": 2017-06-13T00:00:00.000Z,
"displayStart": 2017-06-10T00:00:00.000Z,
"end": 2017-06-13T00:00:00.000Z,
"start": 2017-06-10T00:00:00.000Z,
},
@ -5682,6 +5730,8 @@ exports[`TransactionPanel - Sale autodeclined matches snapshot 1`] = `
},
"booking": Object {
"attributes": Object {
"displayEnd": 2017-06-13T00:00:00.000Z,
"displayStart": 2017-06-10T00:00:00.000Z,
"end": 2017-06-13T00:00:00.000Z,
"start": 2017-06-10T00:00:00.000Z,
},
@ -5812,6 +5862,8 @@ exports[`TransactionPanel - Sale autodeclined matches snapshot 1`] = `
},
"booking": Object {
"attributes": Object {
"displayEnd": 2017-06-13T00:00:00.000Z,
"displayStart": 2017-06-10T00:00:00.000Z,
"end": 2017-06-13T00:00:00.000Z,
"start": 2017-06-10T00:00:00.000Z,
},
@ -6070,6 +6122,8 @@ exports[`TransactionPanel - Sale autodeclined matches snapshot 1`] = `
},
"booking": Object {
"attributes": Object {
"displayEnd": 2017-06-13T00:00:00.000Z,
"displayStart": 2017-06-10T00:00:00.000Z,
"end": 2017-06-13T00:00:00.000Z,
"start": 2017-06-10T00:00:00.000Z,
},
@ -6368,6 +6422,8 @@ exports[`TransactionPanel - Sale canceled matches snapshot 1`] = `
},
"booking": Object {
"attributes": Object {
"displayEnd": 2017-06-13T00:00:00.000Z,
"displayStart": 2017-06-10T00:00:00.000Z,
"end": 2017-06-13T00:00:00.000Z,
"start": 2017-06-10T00:00:00.000Z,
},
@ -6498,6 +6554,8 @@ exports[`TransactionPanel - Sale canceled matches snapshot 1`] = `
},
"booking": Object {
"attributes": Object {
"displayEnd": 2017-06-13T00:00:00.000Z,
"displayStart": 2017-06-10T00:00:00.000Z,
"end": 2017-06-13T00:00:00.000Z,
"start": 2017-06-10T00:00:00.000Z,
},
@ -6757,6 +6815,8 @@ exports[`TransactionPanel - Sale canceled matches snapshot 1`] = `
},
"booking": Object {
"attributes": Object {
"displayEnd": 2017-06-13T00:00:00.000Z,
"displayStart": 2017-06-10T00:00:00.000Z,
"end": 2017-06-13T00:00:00.000Z,
"start": 2017-06-10T00:00:00.000Z,
},
@ -7054,6 +7114,8 @@ exports[`TransactionPanel - Sale declined matches snapshot 1`] = `
},
"booking": Object {
"attributes": Object {
"displayEnd": 2017-06-13T00:00:00.000Z,
"displayStart": 2017-06-10T00:00:00.000Z,
"end": 2017-06-13T00:00:00.000Z,
"start": 2017-06-10T00:00:00.000Z,
},
@ -7184,6 +7246,8 @@ exports[`TransactionPanel - Sale declined matches snapshot 1`] = `
},
"booking": Object {
"attributes": Object {
"displayEnd": 2017-06-13T00:00:00.000Z,
"displayStart": 2017-06-10T00:00:00.000Z,
"end": 2017-06-13T00:00:00.000Z,
"start": 2017-06-10T00:00:00.000Z,
},
@ -7442,6 +7506,8 @@ exports[`TransactionPanel - Sale declined matches snapshot 1`] = `
},
"booking": Object {
"attributes": Object {
"displayEnd": 2017-06-13T00:00:00.000Z,
"displayStart": 2017-06-10T00:00:00.000Z,
"end": 2017-06-13T00:00:00.000Z,
"start": 2017-06-10T00:00:00.000Z,
},
@ -7745,6 +7811,8 @@ exports[`TransactionPanel - Sale delivered matches snapshot 1`] = `
},
"booking": Object {
"attributes": Object {
"displayEnd": 2017-06-13T00:00:00.000Z,
"displayStart": 2017-06-10T00:00:00.000Z,
"end": 2017-06-13T00:00:00.000Z,
"start": 2017-06-10T00:00:00.000Z,
},
@ -7880,6 +7948,8 @@ exports[`TransactionPanel - Sale delivered matches snapshot 1`] = `
},
"booking": Object {
"attributes": Object {
"displayEnd": 2017-06-13T00:00:00.000Z,
"displayStart": 2017-06-10T00:00:00.000Z,
"end": 2017-06-13T00:00:00.000Z,
"start": 2017-06-10T00:00:00.000Z,
},
@ -8144,6 +8214,8 @@ exports[`TransactionPanel - Sale delivered matches snapshot 1`] = `
},
"booking": Object {
"attributes": Object {
"displayEnd": 2017-06-13T00:00:00.000Z,
"displayStart": 2017-06-10T00:00:00.000Z,
"end": 2017-06-13T00:00:00.000Z,
"start": 2017-06-10T00:00:00.000Z,
},
@ -8441,6 +8513,8 @@ exports[`TransactionPanel - Sale enquired matches snapshot 1`] = `
},
"booking": Object {
"attributes": Object {
"displayEnd": 2017-06-13T00:00:00.000Z,
"displayStart": 2017-06-10T00:00:00.000Z,
"end": 2017-06-13T00:00:00.000Z,
"start": 2017-06-10T00:00:00.000Z,
},
@ -8571,6 +8645,8 @@ exports[`TransactionPanel - Sale enquired matches snapshot 1`] = `
},
"booking": Object {
"attributes": Object {
"displayEnd": 2017-06-13T00:00:00.000Z,
"displayStart": 2017-06-10T00:00:00.000Z,
"end": 2017-06-13T00:00:00.000Z,
"start": 2017-06-10T00:00:00.000Z,
},
@ -8828,6 +8904,8 @@ exports[`TransactionPanel - Sale enquired matches snapshot 1`] = `
},
"booking": Object {
"attributes": Object {
"displayEnd": 2017-06-13T00:00:00.000Z,
"displayStart": 2017-06-10T00:00:00.000Z,
"end": 2017-06-13T00:00:00.000Z,
"start": 2017-06-10T00:00:00.000Z,
},
@ -9125,6 +9203,8 @@ exports[`TransactionPanel - Sale preauthorized matches snapshot 1`] = `
},
"booking": Object {
"attributes": Object {
"displayEnd": 2017-06-13T00:00:00.000Z,
"displayStart": 2017-06-10T00:00:00.000Z,
"end": 2017-06-13T00:00:00.000Z,
"start": 2017-06-10T00:00:00.000Z,
},
@ -9255,6 +9335,8 @@ exports[`TransactionPanel - Sale preauthorized matches snapshot 1`] = `
},
"booking": Object {
"attributes": Object {
"displayEnd": 2017-06-13T00:00:00.000Z,
"displayStart": 2017-06-10T00:00:00.000Z,
"end": 2017-06-13T00:00:00.000Z,
"start": 2017-06-10T00:00:00.000Z,
},
@ -9513,6 +9595,8 @@ exports[`TransactionPanel - Sale preauthorized matches snapshot 1`] = `
},
"booking": Object {
"attributes": Object {
"displayEnd": 2017-06-13T00:00:00.000Z,
"displayStart": 2017-06-10T00:00:00.000Z,
"end": 2017-06-13T00:00:00.000Z,
"start": 2017-06-10T00:00:00.000Z,
},

View file

@ -136,9 +136,13 @@ export const txState = (intl, tx, type) => {
};
const bookingData = (unitType, tx, isOrder, intl) => {
const { start, end } = tx.booking.attributes;
const startDate = dateFromAPIToLocalNoon(start);
const endDateRaw = dateFromAPIToLocalNoon(end);
// Attributes: displayStart and displayEnd can be used to differentiate shown time range
// from actual start and end times used for availability reservation. It can help in situations
// where there are preparation time needed between bookings.
// Read more: https://www.sharetribe.com/api-reference/#bookings
const { start, end, displayStart, displayEnd } = tx.booking.attributes;
const startDate = dateFromAPIToLocalNoon(displayStart || start);
const endDateRaw = dateFromAPIToLocalNoon(displayEnd || end);
const isDaily = unitType === LINE_ITEM_DAY;
const isUnits = unitType === LINE_ITEM_UNITS;
const isSingleDay = isDaily && daysBetween(startDate, endDateRaw) === 1;

View file

@ -22,13 +22,24 @@ describe('InboxPage', () => {
const currentUserProvider = createCurrentUser('provider-user-id');
const currentUserCustomer = createCurrentUser('customer-user-id');
const startBooking1 = new Date(Date.UTC(2017, 1, 15));
const endBooking1 = new Date(Date.UTC(2017, 1, 16));
const booking1 = createBooking('booking1', {
start: new Date(Date.UTC(2017, 1, 15)),
end: new Date(Date.UTC(2017, 1, 16)),
start: startBooking1,
end: endBooking1,
displayStart: startBooking1,
displayEnd: endBooking1,
});
const startBooking2 = new Date(Date.UTC(2017, 2, 15));
const endBooking2 = new Date(Date.UTC(2017, 2, 16));
const booking2 = createBooking('booking2', {
start: new Date(Date.UTC(2017, 2, 15)),
end: new Date(Date.UTC(2017, 2, 16)),
start: startBooking2,
end: endBooking2,
displayStart: startBooking2,
displayEnd: endBooking2,
});
const ordersProps = {

View file

@ -163,6 +163,8 @@ exports[`InboxPage matches snapshot 1`] = `
},
"booking": Object {
"attributes": Object {
"displayEnd": 2017-02-16T00:00:00.000Z,
"displayStart": 2017-02-15T00:00:00.000Z,
"end": 2017-02-16T00:00:00.000Z,
"start": 2017-02-15T00:00:00.000Z,
},
@ -299,6 +301,8 @@ exports[`InboxPage matches snapshot 1`] = `
},
"booking": Object {
"attributes": Object {
"displayEnd": 2017-03-16T00:00:00.000Z,
"displayStart": 2017-03-15T00:00:00.000Z,
"end": 2017-03-16T00:00:00.000Z,
"start": 2017-03-15T00:00:00.000Z,
},
@ -581,6 +585,8 @@ exports[`InboxPage matches snapshot 3`] = `
},
"booking": Object {
"attributes": Object {
"displayEnd": 2017-02-16T00:00:00.000Z,
"displayStart": 2017-02-15T00:00:00.000Z,
"end": 2017-02-16T00:00:00.000Z,
"start": 2017-02-15T00:00:00.000Z,
},
@ -717,6 +723,8 @@ exports[`InboxPage matches snapshot 3`] = `
},
"booking": Object {
"attributes": Object {
"displayEnd": 2017-03-16T00:00:00.000Z,
"displayStart": 2017-03-15T00:00:00.000Z,
"end": 2017-03-16T00:00:00.000Z,
"start": 2017-03-15T00:00:00.000Z,
},

View file

@ -16,12 +16,16 @@ const noop = () => null;
describe('TransactionPage - Sale', () => {
it('matches snapshot', () => {
const txId = 'tx-sale-1';
const start = new Date(Date.UTC(2017, 5, 10));
const end = new Date(Date.UTC(2017, 5, 13));
const transaction = createTransaction({
id: txId,
lastTransition: TRANSITION_REQUEST,
booking: createBooking('booking1', {
start: new Date(Date.UTC(2017, 5, 10)),
end: new Date(Date.UTC(2017, 5, 13)),
start,
end,
displayStart: start,
displayEnd: end,
}),
listing: createListing('listing1'),
customer: createUser('customer1'),
@ -68,12 +72,17 @@ describe('TransactionPage - Sale', () => {
describe('TransactionPage - Order', () => {
it('matches snapshot', () => {
const txId = 'tx-order-1';
const start = new Date(Date.UTC(2017, 5, 10));
const end = new Date(Date.UTC(2017, 5, 13));
const transaction = createTransaction({
id: txId,
lastTransition: TRANSITION_REQUEST,
booking: createBooking('booking1', {
start: new Date(Date.UTC(2017, 5, 10)),
end: new Date(Date.UTC(2017, 5, 13)),
start,
end,
displayStart: start,
displayEnd: end,
}),
listing: createListing('listing1'),
customer: createUser('customer1'),

View file

@ -125,6 +125,8 @@ exports[`TransactionPage - Order matches snapshot 1`] = `
},
"booking": Object {
"attributes": Object {
"displayEnd": 2017-06-13T00:00:00.000Z,
"displayStart": 2017-06-10T00:00:00.000Z,
"end": 2017-06-13T00:00:00.000Z,
"start": 2017-06-10T00:00:00.000Z,
},
@ -327,6 +329,8 @@ exports[`TransactionPage - Sale matches snapshot 1`] = `
},
"booking": Object {
"attributes": Object {
"displayEnd": 2017-06-13T00:00:00.000Z,
"displayStart": 2017-06-10T00:00:00.000Z,
"end": 2017-06-13T00:00:00.000Z,
"start": 2017-06-10T00:00:00.000Z,
},

View file

@ -18,7 +18,9 @@ export const createBooking = (id, attributes = {}) => ({
type: 'booking',
attributes: {
start: new Date(Date.UTC(2017, 5, 10)),
displayStart: new Date(Date.UTC(2017, 5, 10)),
end: new Date(Date.UTC(2017, 5, 10)),
displayEnd: new Date(Date.UTC(2017, 5, 10)),
...attributes,
},
});

View file

@ -207,6 +207,17 @@ propTypes.ownListing = shape({
images: arrayOf(propTypes.image),
});
export const BOOKING_STATE_PENDING = 'pending';
export const BOOKING_STATE_ACCEPTED = 'accepted';
export const BOOKING_STATE_DECLINED = 'declined';
export const BOOKING_STATE_CANCELLED = 'cancelled';
export const BOOKING_STATES = [
BOOKING_STATE_PENDING,
BOOKING_STATE_ACCEPTED,
BOOKING_STATE_DECLINED,
BOOKING_STATE_CANCELLED,
];
// Denormalised booking object
propTypes.booking = shape({
id: propTypes.uuid.isRequired,
@ -214,6 +225,9 @@ propTypes.booking = shape({
attributes: shape({
end: instanceOf(Date).isRequired,
start: instanceOf(Date).isRequired,
displayStart: instanceOf(Date),
displayEnd: instanceOf(Date),
state: oneOf(BOOKING_STATES),
}),
});