From 0c7b8ca355a75cdea9a077884fe3033314daae1e Mon Sep 17 00:00:00 2001 From: Kimmo Puputti Date: Thu, 28 Sep 2017 16:31:06 +0300 Subject: [PATCH 01/14] Use transaction lastTransition instead of state --- .../BookingBreakdown.example.js | 3 - .../BookingBreakdown/BookingBreakdown.js | 4 +- .../BookingBreakdown/BookingBreakdown.test.js | 1 - .../OrderDetailsPanel/OrderDetailsPanel.js | 77 ++++++++----------- .../OrderDetailsPanel.test.js | 5 +- .../OrderDetailsPanel.test.js.snap | 2 - .../SaleDetailsPanel/SaleDetailsPanel.js | 51 +++++++----- .../SaleDetailsPanel/SaleDetailsPanel.test.js | 5 +- .../SaleDetailsPanel.test.js.snap | 2 - .../BookingDatesForm/BookingDatesForm.js | 1 - .../BookingDatesForm/BookingDatesForm.test.js | 1 - src/containers/InboxPage/InboxPage.js | 11 +-- src/containers/InboxPage/InboxPage.test.js | 9 ++- .../__snapshots__/InboxPage.test.js.snap | 4 - src/containers/OrderPage/OrderPage.test.js | 3 +- .../__snapshots__/OrderPage.test.js.snap | 1 - src/containers/SalePage/SalePage.test.js | 3 +- .../__snapshots__/SalePage.test.js.snap | 1 - src/ducks/user.duck.js | 4 +- src/util/propTypes.js | 13 ---- src/util/test-data.js | 2 - 21 files changed, 88 insertions(+), 115 deletions(-) diff --git a/src/components/BookingBreakdown/BookingBreakdown.example.js b/src/components/BookingBreakdown/BookingBreakdown.example.js index 2491feef..2e714deb 100644 --- a/src/components/BookingBreakdown/BookingBreakdown.example.js +++ b/src/components/BookingBreakdown/BookingBreakdown.example.js @@ -22,7 +22,6 @@ const exampleTransaction = params => { createdAt: created, lastTransitionedAt: created, lastTransition: propTypes.TX_TRANSITION_PREAUTHORIZE, - state: propTypes.TX_STATE_PREAUTHORIZED, // payinTotal, payoutTotal, and lineItems required in params ...params, @@ -165,7 +164,6 @@ export const ProviderSaleRejected = { props: { userRole: 'provider', transaction: exampleTransaction({ - state: propTypes.TX_STATE_REJECTED, lastTransition: propTypes.TX_TRANSITION_REJECT, payinTotal: new Money(4500, 'USD'), payoutTotal: new Money(2500, 'USD'), @@ -195,7 +193,6 @@ export const ProviderSaleDelivered = { props: { userRole: 'provider', transaction: exampleTransaction({ - state: propTypes.TX_STATE_DELIVERED, lastTransition: propTypes.TX_TRANSITION_MARK_DELIVERED, payinTotal: new Money(4500, 'USD'), payoutTotal: new Money(2500, 'USD'), diff --git a/src/components/BookingBreakdown/BookingBreakdown.js b/src/components/BookingBreakdown/BookingBreakdown.js index 9a83bb90..73aa1ecd 100644 --- a/src/components/BookingBreakdown/BookingBreakdown.js +++ b/src/components/BookingBreakdown/BookingBreakdown.js @@ -111,9 +111,9 @@ export const BookingBreakdownComponent = props => { } let providerTotalMessageId = 'BookingBreakdown.providerTotalDefault'; - if (transaction.attributes.state === propTypes.TX_STATE_DELIVERED) { + if (transaction.attributes.lastTransition === propTypes.TX_TRANSITION_MARK_DELIVERED) { providerTotalMessageId = 'BookingBreakdown.providerTotalDelivered'; - } else if (transaction.attributes.state === propTypes.TX_STATE_REJECTED) { + } else if (transaction.attributes.lastTransition === propTypes.TX_TRANSITION_REJECT) { providerTotalMessageId = 'BookingBreakdown.providerTotalRejected'; } diff --git a/src/components/BookingBreakdown/BookingBreakdown.test.js b/src/components/BookingBreakdown/BookingBreakdown.test.js index 0985e574..8c0f4aca 100644 --- a/src/components/BookingBreakdown/BookingBreakdown.test.js +++ b/src/components/BookingBreakdown/BookingBreakdown.test.js @@ -25,7 +25,6 @@ const exampleTransaction = params => { createdAt: created, lastTransitionedAt: created, lastTransition: propTypes.TX_TRANSITION_PREAUTHORIZE, - state: propTypes.TX_STATE_PREAUTHORIZED, // payinTotal, payoutTotal, and lineItems required in params ...params, diff --git a/src/components/OrderDetailsPanel/OrderDetailsPanel.js b/src/components/OrderDetailsPanel/OrderDetailsPanel.js index 129afb1d..ed77c31d 100644 --- a/src/components/OrderDetailsPanel/OrderDetailsPanel.js +++ b/src/components/OrderDetailsPanel/OrderDetailsPanel.js @@ -21,13 +21,9 @@ const breakdown = transaction => { : null; }; -const orderTitle = (orderState, listingLink, customerName, lastTransition) => { - const rejectedTranslationId = lastTransition === propTypes.TX_TRANSITION_AUTO_REJECT - ? 'OrderDetailsPanel.orderAutoRejectedTitle' - : 'OrderDetailsPanel.orderRejectedTitle'; - - switch (orderState) { - case propTypes.TX_STATE_PREAUTHORIZED: +const orderTitle = (lastTransition, listingLink, customerName) => { + switch (lastTransition) { + case propTypes.TX_TRANSITION_PREAUTHORIZE: return ( @@ -42,7 +38,7 @@ const orderTitle = (orderState, listingLink, customerName, lastTransition) => { /> ); - case propTypes.TX_STATE_ACCEPTED: + case propTypes.TX_TRANSITION_ACCEPT: return ( @@ -51,9 +47,15 @@ const orderTitle = (orderState, listingLink, customerName, lastTransition) => { ); - case propTypes.TX_STATE_REJECTED: - return ; - case propTypes.TX_STATE_DELIVERED: + case propTypes.TX_TRANSITION_REJECT: + return ( + + ); + case propTypes.TX_TRANSITION_AUTO_REJECT: + return ( + + ); + case propTypes.TX_TRANSITION_MARK_DELIVERED: return ( ); @@ -62,43 +64,42 @@ const orderTitle = (orderState, listingLink, customerName, lastTransition) => { } }; -const orderMessage = ( - orderState, - listingTitle, - providerName, - lastTransitionedAt, - lastTransition -) => { +const orderMessage = (lastTransition, listingTitle, providerName, lastTransitionedAt) => { const transitionDate = ( ); - - const rejectedTranslationId = lastTransition === propTypes.TX_TRANSITION_AUTO_REJECT - ? 'OrderDetailsPanel.orderAutoRejectedStatus' - : 'OrderDetailsPanel.orderRejectedStatus'; - - switch (orderState) { - case propTypes.TX_STATE_PREAUTHORIZED: + switch (lastTransition) { + case propTypes.TX_TRANSITION_PREAUTHORIZE: return ( ); - case propTypes.TX_STATE_ACCEPTED: + case propTypes.TX_TRANSITION_ACCEPT: return ( ); - case propTypes.TX_STATE_REJECTED: + case propTypes.TX_TRANSITION_REJECT: return ( - + ); - case propTypes.TX_STATE_DELIVERED: + case propTypes.TX_TRANSITION_AUTO_REJECT: + return ( + + ); + case propTypes.TX_TRANSITION_MARK_DELIVERED: return ( { const authorDisplayName = userDisplayName(currentProvider, bannedUserDisplayName); const customerDisplayName = userDisplayName(currentCustomer, bannedUserDisplayName); - const transactionState = currentTransaction.attributes.state; const lastTransitionedAt = currentTransaction.attributes.lastTransitionedAt; - const lastTransition = currentTransaction.attributes.lastTransitione; + const lastTransition = currentTransaction.attributes.lastTransition; let listingLink = null; @@ -163,21 +163,10 @@ export const OrderDetailsPanelComponent = props => { : currentListing.attributes.title; const bookingInfo = breakdown(currentTransaction); - const orderHeading = orderTitle( - transactionState, - listingLink, - customerDisplayName, - lastTransition - ); + const orderHeading = orderTitle(lastTransition, listingLink, customerDisplayName); const message = listingDeleted ? orderMessageDeletedListing - : orderMessage( - transactionState, - listingLink, - authorDisplayName, - lastTransitionedAt, - lastTransition - ); + : orderMessage(lastTransition, listingLink, authorDisplayName, lastTransitionedAt); const firstImage = currentListing.images && currentListing.images.length > 0 ? currentListing.images[0] diff --git a/src/components/OrderDetailsPanel/OrderDetailsPanel.test.js b/src/components/OrderDetailsPanel/OrderDetailsPanel.test.js index 5fbbac92..33902d45 100644 --- a/src/components/OrderDetailsPanel/OrderDetailsPanel.test.js +++ b/src/components/OrderDetailsPanel/OrderDetailsPanel.test.js @@ -4,6 +4,7 @@ import { types } from '../../util/sdkLoader'; import { createBooking, createListing, createUser, createTransaction } from '../../util/test-data'; import { renderShallow } from '../../util/test-helpers'; import { fakeIntl } from '../../util/test-data'; +import { TX_TRANSITION_PREAUTHORIZE } from '../../util/propTypes'; import { BookingBreakdown } from '../../components'; import { OrderDetailsPanelComponent } from './OrderDetailsPanel.js'; @@ -12,7 +13,7 @@ describe('OrderDetailsPanel', () => { const { Money } = types; const tx = createTransaction({ id: 'order-tx', - state: 'state/preauthorized', + lastTransition: TX_TRANSITION_PREAUTHORIZE, total: new Money(16500, 'USD'), booking: createBooking('booking1', { start: new Date(Date.UTC(2017, 5, 10)), @@ -29,7 +30,7 @@ describe('OrderDetailsPanel', () => { const { Money } = types; const tx = createTransaction({ id: 'order-tx', - state: 'state/preauthorized', + lastTransition: TX_TRANSITION_PREAUTHORIZE, total: new Money(16500, 'USD'), booking: createBooking('booking1', { start: new Date(Date.UTC(2017, 5, 10)), diff --git a/src/components/OrderDetailsPanel/__snapshots__/OrderDetailsPanel.test.js.snap b/src/components/OrderDetailsPanel/__snapshots__/OrderDetailsPanel.test.js.snap index bd276447..24dad4a0 100644 --- a/src/components/OrderDetailsPanel/__snapshots__/OrderDetailsPanel.test.js.snap +++ b/src/components/OrderDetailsPanel/__snapshots__/OrderDetailsPanel.test.js.snap @@ -141,7 +141,6 @@ exports[`OrderDetailsPanel matches snapshot 1`] = ` "amount": 16400, "currency": "USD", }, - "state": "state/preauthorized", }, "booking": Object { "attributes": Object { @@ -319,7 +318,6 @@ exports[`OrderDetailsPanel matches snapshot 1`] = ` "amount": 16400, "currency": "USD", }, - "state": "state/preauthorized", }, "booking": Object { "attributes": Object { diff --git a/src/components/SaleDetailsPanel/SaleDetailsPanel.js b/src/components/SaleDetailsPanel/SaleDetailsPanel.js index 57b6ae59..c1c4249c 100644 --- a/src/components/SaleDetailsPanel/SaleDetailsPanel.js +++ b/src/components/SaleDetailsPanel/SaleDetailsPanel.js @@ -28,30 +28,37 @@ const breakdown = transaction => { : null; }; -const saleTitle = (saleState, listingLink, customerName) => { - switch (saleState) { - case propTypes.TX_STATE_PREAUTHORIZED: +const saleTitle = (lastTransition, listingLink, customerName) => { + switch (lastTransition) { + case propTypes.TX_TRANSITION_PREAUTHORIZE: return ( ); - case propTypes.TX_STATE_ACCEPTED: + case propTypes.TX_TRANSITION_ACCEPT: return ( ); - case propTypes.TX_STATE_REJECTED: + case propTypes.TX_TRANSITION_REJECT: return ( ); - case propTypes.TX_STATE_DELIVERED: + case propTypes.TX_TRANSITION_AUTO_REJECT: + return ( + + ); + case propTypes.TX_TRANSITION_MARK_DELIVERED: return ( { } }; -const saleMessage = (saleState, customerName, lastTransitionedAt, lastTransition) => { +const saleMessage = (lastTransition, customerName, lastTransitionedAt) => { const formattedDate = ( ); - const rejectedStatusTranslationId = lastTransition === propTypes.TX_TRANSITION_AUTO_REJECT - ? 'SaleDetailsPanel.saleAutoRejectedStatus' - : 'SaleDetailsPanel.saleRejectedStatus'; - switch (saleState) { - case propTypes.TX_STATE_PREAUTHORIZED: + switch (lastTransition) { + case propTypes.TX_TRANSITION_PREAUTHORIZE: return ( ); - case propTypes.TX_STATE_ACCEPTED: { + case propTypes.TX_TRANSITION_ACCEPT: { return ( ); } - case propTypes.TX_STATE_REJECTED: - return ; - case propTypes.TX_STATE_DELIVERED: + case propTypes.TX_TRANSITION_REJECT: + return ( + + ); + case propTypes.TX_TRANSITION_AUTO_REJECT: + return ( + + ); + case propTypes.TX_TRANSITION_MARK_DELIVERED: return ( ); @@ -123,7 +133,6 @@ export const SaleDetailsPanelComponent = props => { }); const customerDisplayName = userDisplayName(currentCustomer, bannedUserDisplayName); - const transactionState = currentTransaction.attributes.state; const lastTransitionedAt = currentTransaction.attributes.lastTransitionedAt; const lastTransition = currentTransaction.attributes.lastTransition; @@ -141,20 +150,20 @@ export const SaleDetailsPanelComponent = props => { const bookingInfo = breakdown(currentTransaction); - const title = saleTitle(transactionState, listingLink, customerDisplayName, lastTransition); + const title = saleTitle(lastTransition, listingLink, customerDisplayName); const message = isCustomerBanned ? intl.formatMessage({ id: 'SaleDetailsPanel.customerBannedStatus', }) - : saleMessage(transactionState, customerDisplayName, lastTransitionedAt, lastTransition); + : saleMessage(lastTransition, customerDisplayName, lastTransitionedAt); const listingTitle = currentListing.attributes.title; const firstImage = currentListing.images && currentListing.images.length > 0 ? currentListing.images[0] : null; - const isPreauthorizedState = currentTransaction.attributes.state === - propTypes.TX_STATE_PREAUTHORIZED; + const isPreauthorizedState = currentTransaction.attributes.lastTransition === + propTypes.TX_TRANSITION_PREAUTHORIZE; const canShowButtons = isPreauthorizedState && !isCustomerBanned; const buttonsDisabled = acceptInProgress || rejectInProgress; diff --git a/src/components/SaleDetailsPanel/SaleDetailsPanel.test.js b/src/components/SaleDetailsPanel/SaleDetailsPanel.test.js index 0bd976a0..e9983bb6 100644 --- a/src/components/SaleDetailsPanel/SaleDetailsPanel.test.js +++ b/src/components/SaleDetailsPanel/SaleDetailsPanel.test.js @@ -4,6 +4,7 @@ import { types } from '../../util/sdkLoader'; import { createTransaction, createBooking, createListing, createUser } from '../../util/test-data'; import { renderShallow } from '../../util/test-helpers'; import { fakeIntl } from '../../util/test-data'; +import { TX_TRANSITION_PREAUTHORIZE } from '../../util/propTypes'; import { BookingBreakdown } from '../../components'; import { SaleDetailsPanelComponent } from './SaleDetailsPanel.js'; @@ -14,7 +15,7 @@ describe('SaleDetailsPanel', () => { const { Money } = types; const transaction = createTransaction({ id: 'sale-tx', - state: 'state/preauthorized', + lastTransition: TX_TRANSITION_PREAUTHORIZE, total: new Money(16500, 'USD'), commission: new Money(1000, 'USD'), booking: createBooking('booking1', { @@ -40,7 +41,7 @@ describe('SaleDetailsPanel', () => { const { Money } = types; const transaction = createTransaction({ id: 'sale-tx', - state: 'state/preauthorized', + lastTransition: TX_TRANSITION_PREAUTHORIZE, total: new Money(16500, 'USD'), commission: new Money(1000, 'USD'), booking: createBooking('booking1', { diff --git a/src/components/SaleDetailsPanel/__snapshots__/SaleDetailsPanel.test.js.snap b/src/components/SaleDetailsPanel/__snapshots__/SaleDetailsPanel.test.js.snap index dd3f8af3..e723112c 100644 --- a/src/components/SaleDetailsPanel/__snapshots__/SaleDetailsPanel.test.js.snap +++ b/src/components/SaleDetailsPanel/__snapshots__/SaleDetailsPanel.test.js.snap @@ -167,7 +167,6 @@ exports[`SaleDetailsPanel matches snapshot 1`] = ` "amount": 15500, "currency": "USD", }, - "state": "state/preauthorized", }, "booking": Object { "attributes": Object { @@ -302,7 +301,6 @@ exports[`SaleDetailsPanel matches snapshot 1`] = ` "amount": 15500, "currency": "USD", }, - "state": "state/preauthorized", }, "booking": Object { "attributes": Object { diff --git a/src/containers/BookingDatesForm/BookingDatesForm.js b/src/containers/BookingDatesForm/BookingDatesForm.js index 0fbe6083..0b112b8e 100644 --- a/src/containers/BookingDatesForm/BookingDatesForm.js +++ b/src/containers/BookingDatesForm/BookingDatesForm.js @@ -40,7 +40,6 @@ const estimatedNightlyTransaction = (bookingStart, bookingEnd, unitPrice) => { createdAt: now, lastTransitionedAt: now, lastTransition: propTypes.TX_TRANSITION_PREAUTHORIZE, - state: propTypes.TX_STATE_PREAUTHORIZED, payinTotal: totalPrice, payoutTotal: totalPrice, lineItems: [ diff --git a/src/containers/BookingDatesForm/BookingDatesForm.test.js b/src/containers/BookingDatesForm/BookingDatesForm.test.js index c9b2755c..2095f898 100644 --- a/src/containers/BookingDatesForm/BookingDatesForm.test.js +++ b/src/containers/BookingDatesForm/BookingDatesForm.test.js @@ -50,7 +50,6 @@ describe('BookingDatesForm', () => { expect(booking.attributes.start).toEqual(startDate); expect(booking.attributes.end).toEqual(endDate); expect(transaction.attributes.lastTransition).toEqual(propTypes.TX_TRANSITION_PREAUTHORIZE); - expect(transaction.attributes.state).toEqual(propTypes.TX_STATE_PREAUTHORIZED); expect(transaction.attributes.payinTotal).toEqual(new Money(2198, 'USD')); expect(transaction.attributes.payoutTotal).toEqual(new Money(2198, 'USD')); expect(transaction.attributes.lineItems).toEqual([ diff --git a/src/containers/InboxPage/InboxPage.js b/src/containers/InboxPage/InboxPage.js index 5438681a..fd23d4e4 100644 --- a/src/containers/InboxPage/InboxPage.js +++ b/src/containers/InboxPage/InboxPage.js @@ -39,8 +39,8 @@ const formatDate = (intl, date) => { // Translated name of the state of the given transaction const txState = (intl, tx, isOrder) => { - const { attributes: { state } } = tx; - if (state === propTypes.TX_STATE_ACCEPTED) { + const { attributes: { lastTransition } } = tx; + if (lastTransition === propTypes.TX_TRANSITION_ACCEPT) { return { nameClassName: css.nameAccepted, bookingClassName: css.bookingAccepted, @@ -50,7 +50,7 @@ const txState = (intl, tx, isOrder) => { id: 'InboxPage.stateAccepted', }), }; - } else if (state === propTypes.TX_STATE_REJECTED) { + } else if (lastTransition === propTypes.TX_TRANSITION_REJECT) { return { nameClassName: css.nameDeclined, bookingClassName: css.bookingDeclined, @@ -60,7 +60,7 @@ const txState = (intl, tx, isOrder) => { id: 'InboxPage.stateDeclined', }), }; - } else if (state === propTypes.TX_STATE_DELIVERED) { + } else if (lastTransition === propTypes.TX_TRANSITION_MARK_DELIVERED) { return { nameClassName: css.nameDelivered, bookingClassName: css.bookingDelivered, @@ -101,7 +101,8 @@ export const InboxItem = props => { const otherUserDisplayName = userDisplayName(otherUser, bannedUserDisplayName); const stateData = txState(intl, tx, isOrder); - const isSaleNotification = !isOrder && tx.attributes.state === propTypes.TX_STATE_PREAUTHORIZED; + const isPreauthorized = tx.attributes.lastTransition === propTypes.TX_TRANSITION_PREAUTHORIZE; + const isSaleNotification = !isOrder && isPreauthorized; const rowNotificationDot = isSaleNotification ?
: null; const lastTransitionedAt = formatDate(intl, tx.attributes.lastTransitionedAt); const bookingStart = formatDate(intl, booking.attributes.start); diff --git a/src/containers/InboxPage/InboxPage.test.js b/src/containers/InboxPage/InboxPage.test.js index 3fe348ea..a19fc4fb 100644 --- a/src/containers/InboxPage/InboxPage.test.js +++ b/src/containers/InboxPage/InboxPage.test.js @@ -5,6 +5,7 @@ import { fakeIntl, createUser, createTransaction, createBooking } from '../../ut import { InboxPageComponent, InboxItem } from './InboxPage'; import routesConfiguration from '../../routesConfiguration'; import { flattenRoutes } from '../../util/routes'; +import { TX_TRANSITION_PREAUTHORIZE } from '../../util/propTypes'; const noop = () => null; @@ -39,14 +40,14 @@ describe('InboxPage', () => { transactions: [ createTransaction({ id: 'order-1', - state: 'state/preauthorized', + lastTransition: TX_TRANSITION_PREAUTHORIZE, provider, lastTransitionedAt: new Date(Date.UTC(2017, 0, 15)), booking: booking1, }), createTransaction({ id: 'order-2', - state: 'state/preauthorized', + lastTransition: TX_TRANSITION_PREAUTHORIZE, provider, lastTransitionedAt: new Date(Date.UTC(2016, 0, 15)), booking: booking2, @@ -86,14 +87,14 @@ describe('InboxPage', () => { transactions: [ createTransaction({ id: 'sale-1', - state: 'state/preauthorized', + lastTransition: TX_TRANSITION_PREAUTHORIZE, customer, lastTransitionedAt: new Date(Date.UTC(2017, 0, 15)), booking: booking1, }), createTransaction({ id: 'sale-2', - state: 'state/preauthorized', + lastTransition: TX_TRANSITION_PREAUTHORIZE, customer, lastTransitionedAt: new Date(Date.UTC(2016, 0, 15)), booking: booking2, diff --git a/src/containers/InboxPage/__snapshots__/InboxPage.test.js.snap b/src/containers/InboxPage/__snapshots__/InboxPage.test.js.snap index c8c6cfa2..ec68e807 100644 --- a/src/containers/InboxPage/__snapshots__/InboxPage.test.js.snap +++ b/src/containers/InboxPage/__snapshots__/InboxPage.test.js.snap @@ -127,7 +127,6 @@ exports[`InboxPage matches snapshot 1`] = ` "amount": 900, "currency": "USD", }, - "state": "state/preauthorized", }, "booking": Object { "attributes": Object { @@ -215,7 +214,6 @@ exports[`InboxPage matches snapshot 1`] = ` "amount": 900, "currency": "USD", }, - "state": "state/preauthorized", }, "booking": Object { "attributes": Object { @@ -437,7 +435,6 @@ exports[`InboxPage matches snapshot 3`] = ` "amount": 900, "currency": "USD", }, - "state": "state/preauthorized", }, "booking": Object { "attributes": Object { @@ -525,7 +522,6 @@ exports[`InboxPage matches snapshot 3`] = ` "amount": 900, "currency": "USD", }, - "state": "state/preauthorized", }, "booking": Object { "attributes": Object { diff --git a/src/containers/OrderPage/OrderPage.test.js b/src/containers/OrderPage/OrderPage.test.js index 0b34c99e..9525e239 100644 --- a/src/containers/OrderPage/OrderPage.test.js +++ b/src/containers/OrderPage/OrderPage.test.js @@ -8,6 +8,7 @@ import { fakeIntl, } from '../../util/test-data'; import { renderShallow } from '../../util/test-helpers'; +import { TX_TRANSITION_PREAUTHORIZE } from '../../util/propTypes'; import { OrderPageComponent } from './OrderPage'; const noop = () => null; @@ -17,7 +18,7 @@ describe('OrderPage', () => { const txId = 'tx-order-1'; const transaction = createTransaction({ id: txId, - state: 'state/preauthorized', + lastTransition: TX_TRANSITION_PREAUTHORIZE, booking: createBooking('booking1', { start: new Date(Date.UTC(2017, 5, 10)), end: new Date(Date.UTC(2017, 5, 13)), diff --git a/src/containers/OrderPage/__snapshots__/OrderPage.test.js.snap b/src/containers/OrderPage/__snapshots__/OrderPage.test.js.snap index 6a0c4e9d..5599df1c 100644 --- a/src/containers/OrderPage/__snapshots__/OrderPage.test.js.snap +++ b/src/containers/OrderPage/__snapshots__/OrderPage.test.js.snap @@ -86,7 +86,6 @@ exports[`OrderPage matches snapshot 1`] = ` "amount": 900, "currency": "USD", }, - "state": "state/preauthorized", }, "booking": Object { "attributes": Object { diff --git a/src/containers/SalePage/SalePage.test.js b/src/containers/SalePage/SalePage.test.js index faa564b1..2c5a74a4 100644 --- a/src/containers/SalePage/SalePage.test.js +++ b/src/containers/SalePage/SalePage.test.js @@ -8,6 +8,7 @@ import { fakeIntl, } from '../../util/test-data'; import { renderShallow } from '../../util/test-helpers'; +import { TX_TRANSITION_PREAUTHORIZE } from '../../util/propTypes'; import { SalePageComponent } from './SalePage'; const noop = () => null; @@ -17,7 +18,7 @@ describe('SalePage', () => { const txId = 'tx-sale-1'; const transaction = createTransaction({ id: txId, - state: 'state/preauthorized', + lastTransition: TX_TRANSITION_PREAUTHORIZE, booking: createBooking('booking1', { start: new Date(Date.UTC(2017, 5, 10)), end: new Date(Date.UTC(2017, 5, 13)), diff --git a/src/containers/SalePage/__snapshots__/SalePage.test.js.snap b/src/containers/SalePage/__snapshots__/SalePage.test.js.snap index e2fc9d4b..3a600384 100644 --- a/src/containers/SalePage/__snapshots__/SalePage.test.js.snap +++ b/src/containers/SalePage/__snapshots__/SalePage.test.js.snap @@ -93,7 +93,6 @@ exports[`SalePage matches snapshot 1`] = ` "amount": 900, "currency": "USD", }, - "state": "state/preauthorized", }, "booking": Object { "attributes": Object { diff --git a/src/ducks/user.duck.js b/src/ducks/user.duck.js index ea8c59e4..ede121a4 100644 --- a/src/ducks/user.duck.js +++ b/src/ducks/user.duck.js @@ -1,5 +1,4 @@ import { updatedEntities, denormalisedEntities } from '../util/data'; -import { TX_STATE_PREAUTHORIZED } from '../util/propTypes'; // ================ Action types ================ // @@ -299,7 +298,8 @@ export const fetchCurrentUserNotifications = () => const apiQueryParams = { only: 'sale', - states: [TX_STATE_PREAUTHORIZED], + // TODO: how to change this to use lastTransition? + // states: [TX_STATE_PREAUTHORIZED], page: 1, per_page: NOTIFICATION_PAGE_SIZE, }; diff --git a/src/util/propTypes.js b/src/util/propTypes.js index e89e6446..2529bd6c 100644 --- a/src/util/propTypes.js +++ b/src/util/propTypes.js @@ -135,18 +135,6 @@ export const booking = shape({ }), }); -export const TX_STATE_ACCEPTED = 'state/accepted'; -export const TX_STATE_REJECTED = 'state/rejected'; -export const TX_STATE_PREAUTHORIZED = 'state/preauthorized'; -export const TX_STATE_DELIVERED = 'state/delivered'; - -export const TX_STATES = [ - TX_STATE_ACCEPTED, - TX_STATE_REJECTED, - TX_STATE_PREAUTHORIZED, - TX_STATE_DELIVERED, -]; - // When the customer requests a booking, a transaction is created. The // initial state is preauthorized that is transitioned with the // initial preauthorize transition. The customer can see this @@ -183,7 +171,6 @@ export const transaction = shape({ createdAt: instanceOf(Date).isRequired, lastTransitionedAt: instanceOf(Date).isRequired, lastTransition: oneOf(TX_TRANSITIONS).isRequired, - state: oneOf(TX_STATES).isRequired, payinTotal: money.isRequired, payoutTotal: money.isRequired, lineItems: arrayOf( diff --git a/src/util/test-data.js b/src/util/test-data.js index 5086bd02..4145ec80 100644 --- a/src/util/test-data.js +++ b/src/util/test-data.js @@ -89,7 +89,6 @@ export const createListing = (id, attributes = {}, includes = {}) => ({ export const createTransaction = options => { const { id, - state = propTypes.TX_STATE_PREAUTHORIZED, lastTransition = propTypes.TX_TRANSITION_PREAUTHORIZE, total = new Money(1000, 'USD'), commission = new Money(100, 'USD'), @@ -106,7 +105,6 @@ export const createTransaction = options => { attributes: { createdAt: new Date(Date.UTC(2017, 4, 1)), lastTransitionedAt, - state, lastTransition, payinTotal: total, payoutTotal: new Money(total.amount - commission.amount, total.currency), From ddb02dd059f890b94ea9cced3940a67cd9c19c45 Mon Sep 17 00:00:00 2001 From: Kimmo Puputti Date: Fri, 29 Sep 2017 13:42:53 +0300 Subject: [PATCH 02/14] Add test for rejected/autorejected tx transitions --- .../OrderDetailsPanel.test.js | 42 +- .../OrderDetailsPanel.test.js.snap | 776 +++++++++++++++++- .../SaleDetailsPanel/SaleDetailsPanel.test.js | 60 +- .../SaleDetailsPanel.test.js.snap | 702 +++++++++++++++- 4 files changed, 1570 insertions(+), 10 deletions(-) diff --git a/src/components/OrderDetailsPanel/OrderDetailsPanel.test.js b/src/components/OrderDetailsPanel/OrderDetailsPanel.test.js index 33902d45..1401b57e 100644 --- a/src/components/OrderDetailsPanel/OrderDetailsPanel.test.js +++ b/src/components/OrderDetailsPanel/OrderDetailsPanel.test.js @@ -4,12 +4,16 @@ import { types } from '../../util/sdkLoader'; import { createBooking, createListing, createUser, createTransaction } from '../../util/test-data'; import { renderShallow } from '../../util/test-helpers'; import { fakeIntl } from '../../util/test-data'; -import { TX_TRANSITION_PREAUTHORIZE } from '../../util/propTypes'; +import { + TX_TRANSITION_PREAUTHORIZE, + TX_TRANSITION_REJECT, + TX_TRANSITION_AUTO_REJECT, +} from '../../util/propTypes'; import { BookingBreakdown } from '../../components'; import { OrderDetailsPanelComponent } from './OrderDetailsPanel.js'; describe('OrderDetailsPanel', () => { - it('matches snapshot', () => { + it('preauthorized matches snapshot', () => { const { Money } = types; const tx = createTransaction({ id: 'order-tx', @@ -26,6 +30,40 @@ describe('OrderDetailsPanel', () => { const tree = renderShallow(); expect(tree).toMatchSnapshot(); }); + it('rejected matches snapshot', () => { + const { Money } = types; + const tx = createTransaction({ + id: 'order-rejected', + lastTransition: TX_TRANSITION_REJECT, + total: new Money(16500, 'USD'), + 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'), + }); + const tree = renderShallow(); + expect(tree).toMatchSnapshot(); + }); + it('autorejected matches snapshot', () => { + const { Money } = types; + const tx = createTransaction({ + id: 'order-autorejected', + lastTransition: TX_TRANSITION_AUTO_REJECT, + total: new Money(16500, 'USD'), + 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'), + }); + const tree = renderShallow(); + expect(tree).toMatchSnapshot(); + }); it('renders correct total price', () => { const { Money } = types; const tx = createTransaction({ diff --git a/src/components/OrderDetailsPanel/__snapshots__/OrderDetailsPanel.test.js.snap b/src/components/OrderDetailsPanel/__snapshots__/OrderDetailsPanel.test.js.snap index 24dad4a0..a1e39649 100644 --- a/src/components/OrderDetailsPanel/__snapshots__/OrderDetailsPanel.test.js.snap +++ b/src/components/OrderDetailsPanel/__snapshots__/OrderDetailsPanel.test.js.snap @@ -1,4 +1,389 @@ -exports[`OrderDetailsPanel matches snapshot 1`] = ` +exports[`OrderDetailsPanel autorejected matches snapshot 1`] = ` +
+
+
+ +
+
+ +
+
+

+ + listing1 title + , + } + } /> +

+
+ + + , + } + } /> +
+
+
+
+

+ +

+ +
+
+
+ +
+
+ +
+
+

+ listing1 title +

+

+ +

+
+

+ +

+ +
+
+
+
+`; + +exports[`OrderDetailsPanel preauthorized matches snapshot 1`] = `
@@ -171,13 +556,12 @@ exports[`OrderDetailsPanel matches snapshot 1`] = ` "listing": Object { "attributes": Object { "address": "listing1 address", - "closed": false, - "deleted": false, "description": "listing1 description", "geolocation": LatLng { "lat": 40, "lng": 60, }, + "open": true, "price": Money { "amount": 5500, "currency": "USD", @@ -345,6 +729,392 @@ exports[`OrderDetailsPanel matches snapshot 1`] = ` "id": UUID { "uuid": "order-tx", }, + "listing": Object { + "attributes": Object { + "address": "listing1 address", + "description": "listing1 description", + "geolocation": LatLng { + "lat": 40, + "lng": 60, + }, + "open": true, + "price": Money { + "amount": 5500, + "currency": "USD", + }, + "title": "listing1 title", + }, + "id": UUID { + "uuid": "listing1", + }, + "type": "listing", + }, + "provider": Object { + "attributes": Object { + "banned": false, + "profile": Object { + "abbreviatedName": "provider abbreviated name", + "displayName": "provider display name", + }, + }, + "id": UUID { + "uuid": "provider", + }, + "type": "user", + }, + "type": "transaction", + } + } + userRole="customer" /> +
+
+
+ +`; + +exports[`OrderDetailsPanel rejected matches snapshot 1`] = ` +
+
+
+ +
+
+ +
+
+

+ + listing1 title + , + } + } /> +

+
+ + + , + } + } /> +
+
+
+
+

+ +

+ +
+
+
+ +
+
+ +
+
+

+ listing1 title +

+

+ +

+
+

+ +

+ null; describe('SaleDetailsPanel', () => { - it('matches snapshot', () => { + it('preauthorized matches snapshot', () => { const { Money } = types; const transaction = createTransaction({ id: 'sale-tx', @@ -37,6 +41,58 @@ describe('SaleDetailsPanel', () => { const tree = renderShallow(); expect(tree).toMatchSnapshot(); }); + it('rejected matches snapshot', () => { + const { Money } = types; + const transaction = createTransaction({ + id: 'sale-tx', + lastTransition: TX_TRANSITION_REJECT, + 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)), + }), + listing: createListing('listing1'), + customer: createUser('customer1'), + lastTransitionedAt: new Date(Date.UTC(2017, 5, 10)), + }); + const props = { + transaction, + onAcceptSale: noop, + onRejectSale: noop, + acceptInProgress: false, + rejectInProgress: false, + intl: fakeIntl, + }; + const tree = renderShallow(); + expect(tree).toMatchSnapshot(); + }); + it('autorejected matches snapshot', () => { + const { Money } = types; + const transaction = createTransaction({ + id: 'sale-tx', + lastTransition: TX_TRANSITION_AUTO_REJECT, + 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)), + }), + listing: createListing('listing1'), + customer: createUser('customer1'), + lastTransitionedAt: new Date(Date.UTC(2017, 5, 10)), + }); + const props = { + transaction, + onAcceptSale: noop, + onRejectSale: noop, + acceptInProgress: false, + rejectInProgress: false, + intl: fakeIntl, + }; + const tree = renderShallow(); + expect(tree).toMatchSnapshot(); + }); it('renders correct total price', () => { const { Money } = types; const transaction = createTransaction({ diff --git a/src/components/SaleDetailsPanel/__snapshots__/SaleDetailsPanel.test.js.snap b/src/components/SaleDetailsPanel/__snapshots__/SaleDetailsPanel.test.js.snap index e723112c..b2df6870 100644 --- a/src/components/SaleDetailsPanel/__snapshots__/SaleDetailsPanel.test.js.snap +++ b/src/components/SaleDetailsPanel/__snapshots__/SaleDetailsPanel.test.js.snap @@ -1,4 +1,352 @@ -exports[`SaleDetailsPanel matches snapshot 1`] = ` +exports[`SaleDetailsPanel autorejected matches snapshot 1`] = ` +
+
+
+ +
+
+ +
+
+
+ +
+

+ + listing1 title + , + } + } /> +

+

+ + + , + } + } /> +

+
+
+
+

+ +

+ +
+
+
+ +
+

+ +

+
+ +
+
+
+
+`; + +exports[`SaleDetailsPanel preauthorized matches snapshot 1`] = `
@@ -197,13 +545,12 @@ exports[`SaleDetailsPanel matches snapshot 1`] = ` "listing": Object { "attributes": Object { "address": "listing1 address", - "closed": false, - "deleted": false, "description": "listing1 description", "geolocation": LatLng { "lat": 40, "lng": 60, }, + "open": true, "price": Money { "amount": 5500, "currency": "USD", @@ -328,6 +675,355 @@ exports[`SaleDetailsPanel matches snapshot 1`] = ` "id": UUID { "uuid": "sale-tx", }, + "listing": Object { + "attributes": Object { + "address": "listing1 address", + "description": "listing1 description", + "geolocation": LatLng { + "lat": 40, + "lng": 60, + }, + "open": true, + "price": Money { + "amount": 5500, + "currency": "USD", + }, + "title": "listing1 title", + }, + "id": UUID { + "uuid": "listing1", + }, + "type": "listing", + }, + "provider": null, + "type": "transaction", + } + } + userRole="provider" /> +
+
+
+
+`; + +exports[`SaleDetailsPanel rejected matches snapshot 1`] = ` +
+
+
+ +
+
+ +
+
+
+ +
+

+ + listing1 title + , + } + } /> +

+

+ + + , + } + } /> +

+
+
+
+

+ +

+ +
+
+
+ +
+

+ +

+
+ Date: Fri, 29 Sep 2017 14:12:18 +0300 Subject: [PATCH 03/14] Add snapshot for each tx state in order panel --- .../OrderDetailsPanel.test.js | 114 +-- .../OrderDetailsPanel.test.js.snap | 785 +++++++++++++++++- 2 files changed, 849 insertions(+), 50 deletions(-) diff --git a/src/components/OrderDetailsPanel/OrderDetailsPanel.test.js b/src/components/OrderDetailsPanel/OrderDetailsPanel.test.js index 1401b57e..9d71d71c 100644 --- a/src/components/OrderDetailsPanel/OrderDetailsPanel.test.js +++ b/src/components/OrderDetailsPanel/OrderDetailsPanel.test.js @@ -4,71 +4,89 @@ import { types } from '../../util/sdkLoader'; import { createBooking, createListing, createUser, createTransaction } from '../../util/test-data'; import { renderShallow } from '../../util/test-helpers'; import { fakeIntl } from '../../util/test-data'; -import { - TX_TRANSITION_PREAUTHORIZE, - TX_TRANSITION_REJECT, - TX_TRANSITION_AUTO_REJECT, -} from '../../util/propTypes'; +import * as propTypes from '../../util/propTypes'; import { BookingBreakdown } from '../../components'; import { OrderDetailsPanelComponent } from './OrderDetailsPanel.js'; +const { Money } = types; + +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)), + }), + listing: createListing('listing1'), + provider: createUser('provider'), + customer: createUser('customer'), +}; + +const txPreauthorized = createTransaction({ + id: 'order-preauthorized', + lastTransition: propTypes.TX_TRANSITION_PREAUTHORIZE, + ...baseTxAttrs, +}); + +const txAccepted = createTransaction({ + id: 'order-accepted', + lastTransition: propTypes.TX_TRANSITION_ACCEPT, + ...baseTxAttrs, +}); + +const txRejected = createTransaction({ + id: 'order-rejected', + lastTransition: propTypes.TX_TRANSITION_REJECT, + ...baseTxAttrs, +}); + +const txAutoRejected = createTransaction({ + id: 'order-autorejected', + lastTransition: propTypes.TX_TRANSITION_AUTO_REJECT, + ...baseTxAttrs, +}); + +const txDelivered = createTransaction({ + id: 'order-delivered', + lastTransition: propTypes.TX_TRANSITION_MARK_DELIVERED, + ...baseTxAttrs, +}); + describe('OrderDetailsPanel', () => { it('preauthorized matches snapshot', () => { - const { Money } = types; - const tx = createTransaction({ - id: 'order-tx', - lastTransition: TX_TRANSITION_PREAUTHORIZE, - total: new Money(16500, 'USD'), - 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'), - }); - const tree = renderShallow(); + const tree = renderShallow( + + ); + expect(tree).toMatchSnapshot(); + }); + it('accepted matches snapshot', () => { + const tree = renderShallow( + + ); expect(tree).toMatchSnapshot(); }); it('rejected matches snapshot', () => { - const { Money } = types; - const tx = createTransaction({ - id: 'order-rejected', - lastTransition: TX_TRANSITION_REJECT, - total: new Money(16500, 'USD'), - 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'), - }); - const tree = renderShallow(); + const tree = renderShallow( + + ); expect(tree).toMatchSnapshot(); }); it('autorejected matches snapshot', () => { - const { Money } = types; - const tx = createTransaction({ - id: 'order-autorejected', - lastTransition: TX_TRANSITION_AUTO_REJECT, - total: new Money(16500, 'USD'), - 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'), - }); - const tree = renderShallow(); + const tree = renderShallow( + + ); + expect(tree).toMatchSnapshot(); + }); + it('delivered matches snapshot', () => { + const tree = renderShallow( + + ); expect(tree).toMatchSnapshot(); }); it('renders correct total price', () => { const { Money } = types; const tx = createTransaction({ id: 'order-tx', - lastTransition: TX_TRANSITION_PREAUTHORIZE, + lastTransition: propTypes.TX_TRANSITION_PREAUTHORIZE, total: new Money(16500, 'USD'), booking: createBooking('booking1', { start: new Date(Date.UTC(2017, 5, 10)), diff --git a/src/components/OrderDetailsPanel/__snapshots__/OrderDetailsPanel.test.js.snap b/src/components/OrderDetailsPanel/__snapshots__/OrderDetailsPanel.test.js.snap index a1e39649..b6d0e5b9 100644 --- a/src/components/OrderDetailsPanel/__snapshots__/OrderDetailsPanel.test.js.snap +++ b/src/components/OrderDetailsPanel/__snapshots__/OrderDetailsPanel.test.js.snap @@ -1,3 +1,399 @@ +exports[`OrderDetailsPanel accepted matches snapshot 1`] = ` +
+
+
+ +
+
+ +
+
+

+ + + + + + listing1 title + , + } + } /> + +

+
+ + + , + } + } /> +
+
+
+
+

+ +

+ +
+
+
+ +
+
+ +
+
+

+ listing1 title +

+

+ +

+
+

+ +

+ +
+
+
+
+`; + exports[`OrderDetailsPanel autorejected matches snapshot 1`] = `
@@ -383,6 +779,391 @@ exports[`OrderDetailsPanel autorejected matches snapshot 1`] = `
`; +exports[`OrderDetailsPanel delivered matches snapshot 1`] = ` +
+
+
+ +
+
+ +
+
+

+ + listing1 title + , + } + } /> +

+
+ + + , + } + } /> +
+
+
+
+

+ +

+ +
+
+
+ +
+
+ +
+
+

+ listing1 title +

+

+ +

+
+

+ +

+ +
+
+
+
+`; + exports[`OrderDetailsPanel preauthorized matches snapshot 1`] = `
@@ -551,7 +1332,7 @@ exports[`OrderDetailsPanel preauthorized matches snapshot 1`] = ` "type": "user", }, "id": UUID { - "uuid": "order-tx", + "uuid": "order-preauthorized", }, "listing": Object { "attributes": Object { @@ -727,7 +1508,7 @@ exports[`OrderDetailsPanel preauthorized matches snapshot 1`] = ` "type": "user", }, "id": UUID { - "uuid": "order-tx", + "uuid": "order-preauthorized", }, "listing": Object { "attributes": Object { From b28d0a9528dc103f8f42b911d419e78a9dc2ab57 Mon Sep 17 00:00:00 2001 From: Kimmo Puputti Date: Fri, 29 Sep 2017 14:17:31 +0300 Subject: [PATCH 04/14] Add snapshot for each tx state in sale panel --- .../SaleDetailsPanel/SaleDetailsPanel.test.js | 124 +-- .../SaleDetailsPanel.test.js.snap | 708 +++++++++++++++++- 2 files changed, 774 insertions(+), 58 deletions(-) diff --git a/src/components/SaleDetailsPanel/SaleDetailsPanel.test.js b/src/components/SaleDetailsPanel/SaleDetailsPanel.test.js index 3aa39698..a286d976 100644 --- a/src/components/SaleDetailsPanel/SaleDetailsPanel.test.js +++ b/src/components/SaleDetailsPanel/SaleDetailsPanel.test.js @@ -4,34 +4,71 @@ import { types } from '../../util/sdkLoader'; import { createTransaction, createBooking, createListing, createUser } from '../../util/test-data'; import { renderShallow } from '../../util/test-helpers'; import { fakeIntl } from '../../util/test-data'; -import { - TX_TRANSITION_PREAUTHORIZE, - TX_TRANSITION_REJECT, - TX_TRANSITION_AUTO_REJECT, -} from '../../util/propTypes'; +import * as propTypes from '../../util/propTypes'; import { BookingBreakdown } from '../../components'; import { SaleDetailsPanelComponent } from './SaleDetailsPanel.js'; const noop = () => null; +const { Money } = types; + +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)), + }), + listing: createListing('listing1'), + customer: createUser('customer1'), + lastTransitionedAt: new Date(Date.UTC(2017, 5, 10)), +}; +const txPreauthorized = createTransaction({ + id: 'sale-preauthorized', + lastTransition: propTypes.TX_TRANSITION_PREAUTHORIZE, + ...baseTxAttrs, +}); + +const txAccepted = createTransaction({ + id: 'sale-accepted', + lastTransition: propTypes.TX_TRANSITION_ACCEPT, + ...baseTxAttrs, +}); + +const txRejected = createTransaction({ + id: 'sale-rejected', + lastTransition: propTypes.TX_TRANSITION_REJECT, + ...baseTxAttrs, +}); + +const txAutoRejected = createTransaction({ + id: 'sale-autorejected', + lastTransition: propTypes.TX_TRANSITION_AUTO_REJECT, + ...baseTxAttrs, +}); + +const txDelivered = createTransaction({ + id: 'sale-delivered', + lastTransition: propTypes.TX_TRANSITION_MARK_DELIVERED, + ...baseTxAttrs, +}); + describe('SaleDetailsPanel', () => { it('preauthorized matches snapshot', () => { - const { Money } = types; - const transaction = createTransaction({ - id: 'sale-tx', - lastTransition: TX_TRANSITION_PREAUTHORIZE, - 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)), - }), - listing: createListing('listing1'), - customer: createUser('customer1'), - lastTransitionedAt: new Date(Date.UTC(2017, 5, 10)), - }); const props = { - transaction, + transaction: txPreauthorized, + onAcceptSale: noop, + onRejectSale: noop, + acceptInProgress: false, + rejectInProgress: false, + intl: fakeIntl, + }; + const tree = renderShallow(); + expect(tree).toMatchSnapshot(); + }); + it('accepted matches snapshot', () => { + const props = { + transaction: txAccepted, onAcceptSale: noop, onRejectSale: noop, acceptInProgress: false, @@ -42,22 +79,8 @@ describe('SaleDetailsPanel', () => { expect(tree).toMatchSnapshot(); }); it('rejected matches snapshot', () => { - const { Money } = types; - const transaction = createTransaction({ - id: 'sale-tx', - lastTransition: TX_TRANSITION_REJECT, - 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)), - }), - listing: createListing('listing1'), - customer: createUser('customer1'), - lastTransitionedAt: new Date(Date.UTC(2017, 5, 10)), - }); const props = { - transaction, + transaction: txRejected, onAcceptSale: noop, onRejectSale: noop, acceptInProgress: false, @@ -68,22 +91,20 @@ describe('SaleDetailsPanel', () => { expect(tree).toMatchSnapshot(); }); it('autorejected matches snapshot', () => { - const { Money } = types; - const transaction = createTransaction({ - id: 'sale-tx', - lastTransition: TX_TRANSITION_AUTO_REJECT, - 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)), - }), - listing: createListing('listing1'), - customer: createUser('customer1'), - lastTransitionedAt: new Date(Date.UTC(2017, 5, 10)), - }); const props = { - transaction, + transaction: txAutoRejected, + onAcceptSale: noop, + onRejectSale: noop, + acceptInProgress: false, + rejectInProgress: false, + intl: fakeIntl, + }; + const tree = renderShallow(); + expect(tree).toMatchSnapshot(); + }); + it('delivered matches snapshot', () => { + const props = { + transaction: txDelivered, onAcceptSale: noop, onRejectSale: noop, acceptInProgress: false, @@ -94,10 +115,9 @@ describe('SaleDetailsPanel', () => { expect(tree).toMatchSnapshot(); }); it('renders correct total price', () => { - const { Money } = types; const transaction = createTransaction({ id: 'sale-tx', - lastTransition: TX_TRANSITION_PREAUTHORIZE, + lastTransition: propTypes.TX_TRANSITION_PREAUTHORIZE, total: new Money(16500, 'USD'), commission: new Money(1000, 'USD'), booking: createBooking('booking1', { diff --git a/src/components/SaleDetailsPanel/__snapshots__/SaleDetailsPanel.test.js.snap b/src/components/SaleDetailsPanel/__snapshots__/SaleDetailsPanel.test.js.snap index b2df6870..cf1acf9f 100644 --- a/src/components/SaleDetailsPanel/__snapshots__/SaleDetailsPanel.test.js.snap +++ b/src/components/SaleDetailsPanel/__snapshots__/SaleDetailsPanel.test.js.snap @@ -1,3 +1,351 @@ +exports[`SaleDetailsPanel accepted matches snapshot 1`] = ` +
+
+
+ +
+
+ +
+
+
+ +
+

+ + listing1 title + , + } + } /> +

+

+ + + , + } + } /> +

+
+
+
+

+ +

+ +
+
+
+ +
+

+ +

+
+ +
+
+
+
+`; + exports[`SaleDetailsPanel autorejected matches snapshot 1`] = `
@@ -180,7 +528,7 @@ exports[`SaleDetailsPanel autorejected matches snapshot 1`] = ` "type": "user", }, "id": UUID { - "uuid": "sale-tx", + "uuid": "sale-autorejected", }, "listing": Object { "attributes": Object { @@ -313,7 +661,355 @@ exports[`SaleDetailsPanel autorejected matches snapshot 1`] = ` "type": "user", }, "id": UUID { - "uuid": "sale-tx", + "uuid": "sale-autorejected", + }, + "listing": Object { + "attributes": Object { + "address": "listing1 address", + "description": "listing1 description", + "geolocation": LatLng { + "lat": 40, + "lng": 60, + }, + "open": true, + "price": Money { + "amount": 5500, + "currency": "USD", + }, + "title": "listing1 title", + }, + "id": UUID { + "uuid": "listing1", + }, + "type": "listing", + }, + "provider": null, + "type": "transaction", + } + } + userRole="provider" /> +
+
+
+
+`; + +exports[`SaleDetailsPanel delivered matches snapshot 1`] = ` +
+
+
+ +
+
+ +
+
+
+ +
+

+ + listing1 title + , + } + } /> +

+

+ + + , + } + } /> +

+
+
+
+

+ +

+ +
+
+
+ +
+

+ +

+
+ Date: Fri, 29 Sep 2017 14:18:29 +0300 Subject: [PATCH 05/14] Add tx state helpers --- src/util/propTypes.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/util/propTypes.js b/src/util/propTypes.js index 2529bd6c..8619e2a5 100644 --- a/src/util/propTypes.js +++ b/src/util/propTypes.js @@ -163,6 +163,22 @@ export const TX_TRANSITIONS = [ TX_TRANSITION_MARK_DELIVERED, ]; +const txLastTransition = tx => { + return tx && tx.attributes && tx.attributes.lastTransition ? tx.attributes.lastTransition : null; +}; + +export const txIsPreauthorized = tx => txLastTransition(tx) === TX_TRANSITION_PREAUTHORIZE; + +export const txIsAccepted = tx => txLastTransition(tx) === TX_TRANSITION_ACCEPT; + +export const txIsRejected = tx => txLastTransition(tx) === TX_TRANSITION_REJECT; + +export const txIsAutorejected = tx => txLastTransition(tx) === TX_TRANSITION_AUTO_REJECT; + +export const txIsRejectedOrAutorejected = tx => txIsRejected(tx) || txIsAutorejected(tx); + +export const txIsDelivered = tx => txLastTransition(tx) === TX_TRANSITION_MARK_DELIVERED; + // Denormalised transaction object export const transaction = shape({ id: uuid.isRequired, From 9ba1f4eceec5c5db7102d4d3d14091d26c23e662 Mon Sep 17 00:00:00 2001 From: Kimmo Puputti Date: Fri, 29 Sep 2017 14:18:49 +0300 Subject: [PATCH 06/14] Fix autorejected handling to match rejected handling --- src/components/BookingBreakdown/BookingBreakdown.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/components/BookingBreakdown/BookingBreakdown.js b/src/components/BookingBreakdown/BookingBreakdown.js index 73aa1ecd..48d07130 100644 --- a/src/components/BookingBreakdown/BookingBreakdown.js +++ b/src/components/BookingBreakdown/BookingBreakdown.js @@ -111,9 +111,9 @@ export const BookingBreakdownComponent = props => { } let providerTotalMessageId = 'BookingBreakdown.providerTotalDefault'; - if (transaction.attributes.lastTransition === propTypes.TX_TRANSITION_MARK_DELIVERED) { + if (propTypes.txIsDelivered(transaction)) { providerTotalMessageId = 'BookingBreakdown.providerTotalDelivered'; - } else if (transaction.attributes.lastTransition === propTypes.TX_TRANSITION_REJECT) { + } else if (propTypes.txIsRejectedOrAutorejected(transaction)) { providerTotalMessageId = 'BookingBreakdown.providerTotalRejected'; } From 234aeb342a8e648804247b7a9d079cba7f82d530 Mon Sep 17 00:00:00 2001 From: Kimmo Puputti Date: Fri, 29 Sep 2017 14:19:11 +0300 Subject: [PATCH 07/14] Use tx state helpers --- .../OrderDetailsPanel/OrderDetailsPanel.js | 155 +++++++++--------- 1 file changed, 74 insertions(+), 81 deletions(-) diff --git a/src/components/OrderDetailsPanel/OrderDetailsPanel.js b/src/components/OrderDetailsPanel/OrderDetailsPanel.js index ed77c31d..3602ab2a 100644 --- a/src/components/OrderDetailsPanel/OrderDetailsPanel.js +++ b/src/components/OrderDetailsPanel/OrderDetailsPanel.js @@ -21,93 +21,89 @@ const breakdown = transaction => { : null; }; -const orderTitle = (lastTransition, listingLink, customerName) => { - switch (lastTransition) { - case propTypes.TX_TRANSITION_PREAUTHORIZE: - return ( - - - - +const orderTitle = (transaction, listingLink, customerName) => { + if (propTypes.txIsPreauthorized(transaction)) { + return ( + + - ); - case propTypes.TX_TRANSITION_ACCEPT: - return ( - - - - - + + + ); + } else if (propTypes.txIsAccepted(transaction)) { + return ( + + + - ); - case propTypes.TX_TRANSITION_REJECT: - return ( - - ); - case propTypes.TX_TRANSITION_AUTO_REJECT: - return ( - - ); - case propTypes.TX_TRANSITION_MARK_DELIVERED: - return ( - - ); - default: - return null; + + + ); + } else if (propTypes.txIsRejected(transaction)) { + return ; + } else if (propTypes.txIsAutorejected(transaction)) { + return ( + + ); + } else if (propTypes.txIsDelivered(transaction)) { + return ; + } else { + return null; } }; -const orderMessage = (lastTransition, listingTitle, providerName, lastTransitionedAt) => { +const orderMessage = (transaction, listingTitle, providerName) => { const transitionDate = ( - + ); - switch (lastTransition) { - case propTypes.TX_TRANSITION_PREAUTHORIZE: - return ( - - ); - case propTypes.TX_TRANSITION_ACCEPT: - return ( - - ); - case propTypes.TX_TRANSITION_REJECT: - return ( - - ); - case propTypes.TX_TRANSITION_AUTO_REJECT: - return ( - - ); - case propTypes.TX_TRANSITION_MARK_DELIVERED: - return ( - - ); - default: - return null; + if (propTypes.txIsPreauthorized(transaction)) { + return ( + + ); + } else if (propTypes.txIsAccepted(transaction)) { + return ( + + ); + } else if (propTypes.txIsRejected(transaction)) { + return ( + + ); + } else if (propTypes.txIsAutorejected(transaction)) { + return ( + + ); + } else if (propTypes.txIsDelivered(transaction)) { + return ( + + ); + } else { + return null; } }; @@ -141,8 +137,6 @@ export const OrderDetailsPanelComponent = props => { const authorDisplayName = userDisplayName(currentProvider, bannedUserDisplayName); const customerDisplayName = userDisplayName(currentCustomer, bannedUserDisplayName); - const lastTransitionedAt = currentTransaction.attributes.lastTransitionedAt; - const lastTransition = currentTransaction.attributes.lastTransition; let listingLink = null; @@ -163,10 +157,10 @@ export const OrderDetailsPanelComponent = props => { : currentListing.attributes.title; const bookingInfo = breakdown(currentTransaction); - const orderHeading = orderTitle(lastTransition, listingLink, customerDisplayName); + const orderHeading = orderTitle(currentTransaction, listingLink, customerDisplayName); const message = listingDeleted ? orderMessageDeletedListing - : orderMessage(lastTransition, listingLink, authorDisplayName, lastTransitionedAt); + : orderMessage(currentTransaction, listingLink, authorDisplayName); const firstImage = currentListing.images && currentListing.images.length > 0 ? currentListing.images[0] @@ -244,7 +238,6 @@ export const OrderDetailsPanelComponent = props => { OrderDetailsPanelComponent.defaultProps = { rootClassName: null, className: null, - lastTransition: null, }; const { string } = PropTypes; From 24afaa179418280cada7f83802434fd1e55686f2 Mon Sep 17 00:00:00 2001 From: Kimmo Puputti Date: Fri, 29 Sep 2017 14:27:01 +0300 Subject: [PATCH 08/14] Use tx state helpers --- .../SaleDetailsPanel/SaleDetailsPanel.js | 132 ++++++++---------- 1 file changed, 59 insertions(+), 73 deletions(-) diff --git a/src/components/SaleDetailsPanel/SaleDetailsPanel.js b/src/components/SaleDetailsPanel/SaleDetailsPanel.js index c1c4249c..b0b320db 100644 --- a/src/components/SaleDetailsPanel/SaleDetailsPanel.js +++ b/src/components/SaleDetailsPanel/SaleDetailsPanel.js @@ -28,53 +28,52 @@ const breakdown = transaction => { : null; }; -const saleTitle = (lastTransition, listingLink, customerName) => { - switch (lastTransition) { - case propTypes.TX_TRANSITION_PREAUTHORIZE: - return ( - - ); - case propTypes.TX_TRANSITION_ACCEPT: - return ( - - ); - case propTypes.TX_TRANSITION_REJECT: - return ( - - ); - case propTypes.TX_TRANSITION_AUTO_REJECT: - return ( - - ); - case propTypes.TX_TRANSITION_MARK_DELIVERED: - return ( - - ); - default: - return null; +const saleTitle = (transaction, listingLink, customerName) => { + if (propTypes.txIsPreauthorized(transaction)) { + return ( + + ); + } else if (propTypes.txIsAccepted(transaction)) { + return ( + + ); + } else if (propTypes.txIsRejected(transaction)) { + return ( + + ); + } else if (propTypes.txIsAutorejected(transaction)) { + return ( + + ); + } else if (propTypes.txIsDelivered(transaction)) { + return ( + + ); + } else { + return null; } }; -const saleMessage = (lastTransition, customerName, lastTransitionedAt) => { +const saleMessage = (transaction, customerName) => { const formattedDate = ( { /> ); - switch (lastTransition) { - case propTypes.TX_TRANSITION_PREAUTHORIZE: - return ( - - ); - case propTypes.TX_TRANSITION_ACCEPT: { - return ( - - ); - } - case propTypes.TX_TRANSITION_REJECT: - return ( - - ); - case propTypes.TX_TRANSITION_AUTO_REJECT: - return ( - - ); - case propTypes.TX_TRANSITION_MARK_DELIVERED: - return ( - - ); - default: - return null; + if (propTypes.txIsPreauthorized(transaction)) { + return ; + } else if (propTypes.txIsAccepted(transaction)) { + return ; + } else if (propTypes.txIsRejected(transaction)) { + return ; + } else if (propTypes.txIsAutorejected(transaction)) { + return ( + + ); + } else if (propTypes.txIsDelivered(transaction)) { + return ( + + ); + } else { + return null; } }; @@ -133,8 +124,6 @@ export const SaleDetailsPanelComponent = props => { }); const customerDisplayName = userDisplayName(currentCustomer, bannedUserDisplayName); - const lastTransitionedAt = currentTransaction.attributes.lastTransitionedAt; - const lastTransition = currentTransaction.attributes.lastTransition; let listingLink = null; @@ -150,21 +139,19 @@ export const SaleDetailsPanelComponent = props => { const bookingInfo = breakdown(currentTransaction); - const title = saleTitle(lastTransition, listingLink, customerDisplayName); + const title = saleTitle(currentTransaction, listingLink, customerDisplayName); const message = isCustomerBanned ? intl.formatMessage({ id: 'SaleDetailsPanel.customerBannedStatus', }) - : saleMessage(lastTransition, customerDisplayName, lastTransitionedAt); + : saleMessage(currentTransaction, customerDisplayName); const listingTitle = currentListing.attributes.title; const firstImage = currentListing.images && currentListing.images.length > 0 ? currentListing.images[0] : null; - const isPreauthorizedState = currentTransaction.attributes.lastTransition === - propTypes.TX_TRANSITION_PREAUTHORIZE; - const canShowButtons = isPreauthorizedState && !isCustomerBanned; + const canShowButtons = propTypes.txIsPreauthorized(currentTransaction) && !isCustomerBanned; const buttonsDisabled = acceptInProgress || rejectInProgress; const acceptErrorMessage = acceptSaleError @@ -269,7 +256,6 @@ export const SaleDetailsPanelComponent = props => { SaleDetailsPanelComponent.defaultProps = { rootClassName: null, className: null, - lastTransition: null, acceptSaleError: null, rejectSaleError: null, }; From 3bcb461842fd7295562f6e600e6b3732867d3f5b Mon Sep 17 00:00:00 2001 From: Kimmo Puputti Date: Fri, 29 Sep 2017 14:41:03 +0300 Subject: [PATCH 09/14] Use createBooking helper --- .../BookingBreakdown/BookingBreakdown.test.js | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/src/components/BookingBreakdown/BookingBreakdown.test.js b/src/components/BookingBreakdown/BookingBreakdown.test.js index 8c0f4aca..377be544 100644 --- a/src/components/BookingBreakdown/BookingBreakdown.test.js +++ b/src/components/BookingBreakdown/BookingBreakdown.test.js @@ -1,6 +1,6 @@ import React from 'react'; import Decimal from 'decimal.js'; -import { fakeIntl } from '../../util/test-data'; +import { fakeIntl, createBooking } from '../../util/test-data'; import { renderDeep } from '../../util/test-helpers'; import { types } from '../../util/sdkLoader'; import * as propTypes from '../../util/propTypes'; @@ -8,14 +8,6 @@ import { BookingBreakdownComponent } from './BookingBreakdown'; const { UUID, Money } = types; -const exampleBooking = attributes => { - return { - id: new UUID('example-booking'), - type: 'booking', - attributes, - }; -}; - const exampleTransaction = params => { const created = new Date(Date.UTC(2017, 1, 1)); return { @@ -49,7 +41,7 @@ describe('BookingBreakdown', () => { }, ], })} - booking={exampleBooking({ + booking={createBooking('example-booking', { start: new Date(Date.UTC(2017, 3, 14)), end: new Date(Date.UTC(2017, 3, 16)), })} @@ -75,7 +67,7 @@ describe('BookingBreakdown', () => { }, ], })} - booking={exampleBooking({ + booking={createBooking('example-booking', { start: new Date(Date.UTC(2017, 3, 14)), end: new Date(Date.UTC(2017, 3, 16)), })} @@ -106,7 +98,7 @@ describe('BookingBreakdown', () => { }, ], })} - booking={exampleBooking({ + booking={createBooking('example-booking', { start: new Date(Date.UTC(2017, 3, 14)), end: new Date(Date.UTC(2017, 3, 16)), })} From fa359f082630f297ff5f3992e260cb1b5588a127 Mon Sep 17 00:00:00 2001 From: Kimmo Puputti Date: Fri, 29 Sep 2017 14:45:26 +0300 Subject: [PATCH 10/14] Add breakdown examples for all provider tx states --- .../BookingBreakdown.example.js | 87 +++++++++++++++++++ 1 file changed, 87 insertions(+) diff --git a/src/components/BookingBreakdown/BookingBreakdown.example.js b/src/components/BookingBreakdown/BookingBreakdown.example.js index 2e714deb..b5adb477 100644 --- a/src/components/BookingBreakdown/BookingBreakdown.example.js +++ b/src/components/BookingBreakdown/BookingBreakdown.example.js @@ -159,6 +159,64 @@ export const ProviderSaleSingleNight = { }, }; +export const ProviderSalePreauthorized = { + component: BookingBreakdown, + props: { + userRole: 'provider', + transaction: exampleTransaction({ + lastTransition: propTypes.TX_TRANSITION_PREAUTHORIZE, + payinTotal: new Money(4500, 'USD'), + payoutTotal: new Money(2500, 'USD'), + lineItems: [ + { + code: 'line-item/night', + quantity: new Decimal(1), + unitPrice: new Money(4500, 'USD'), + lineTotal: new Money(4500, 'USD'), + }, + { + code: 'line-item/provider-commission', + unitPrice: new Money(-2000, 'USD'), + lineTotal: new Money(-2000, 'USD'), + }, + ], + }), + booking: exampleBooking({ + start: new Date(Date.UTC(2017, 3, 14)), + end: new Date(Date.UTC(2017, 3, 15)), + }), + }, +}; + +export const ProviderSaleAccepted = { + component: BookingBreakdown, + props: { + userRole: 'provider', + transaction: exampleTransaction({ + lastTransition: propTypes.TX_TRANSITION_ACCEPT, + payinTotal: new Money(4500, 'USD'), + payoutTotal: new Money(2500, 'USD'), + lineItems: [ + { + code: 'line-item/night', + quantity: new Decimal(1), + unitPrice: new Money(4500, 'USD'), + lineTotal: new Money(4500, 'USD'), + }, + { + code: 'line-item/provider-commission', + unitPrice: new Money(-2000, 'USD'), + lineTotal: new Money(-2000, 'USD'), + }, + ], + }), + booking: exampleBooking({ + start: new Date(Date.UTC(2017, 3, 14)), + end: new Date(Date.UTC(2017, 3, 15)), + }), + }, +}; + export const ProviderSaleRejected = { component: BookingBreakdown, props: { @@ -188,6 +246,35 @@ export const ProviderSaleRejected = { }, }; +export const ProviderSaleAutoRejected = { + component: BookingBreakdown, + props: { + userRole: 'provider', + transaction: exampleTransaction({ + lastTransition: propTypes.TX_TRANSITION_AUTO_REJECT, + payinTotal: new Money(4500, 'USD'), + payoutTotal: new Money(2500, 'USD'), + lineItems: [ + { + code: 'line-item/night', + quantity: new Decimal(1), + unitPrice: new Money(4500, 'USD'), + lineTotal: new Money(4500, 'USD'), + }, + { + code: 'line-item/provider-commission', + unitPrice: new Money(-2000, 'USD'), + lineTotal: new Money(-2000, 'USD'), + }, + ], + }), + booking: exampleBooking({ + start: new Date(Date.UTC(2017, 3, 14)), + end: new Date(Date.UTC(2017, 3, 15)), + }), + }, +}; + export const ProviderSaleDelivered = { component: BookingBreakdown, props: { From 449d47b199ca4e18dcc66b51278a49a2c87836cf Mon Sep 17 00:00:00 2001 From: Kimmo Puputti Date: Fri, 29 Sep 2017 14:57:24 +0300 Subject: [PATCH 11/14] Rebase to changed listing shape --- .../OrderDetailsPanel.test.js.snap | 24 ++++++++++++------- .../SaleDetailsPanel.test.js.snap | 24 ++++++++++++------- 2 files changed, 32 insertions(+), 16 deletions(-) diff --git a/src/components/OrderDetailsPanel/__snapshots__/OrderDetailsPanel.test.js.snap b/src/components/OrderDetailsPanel/__snapshots__/OrderDetailsPanel.test.js.snap index b6d0e5b9..de84932a 100644 --- a/src/components/OrderDetailsPanel/__snapshots__/OrderDetailsPanel.test.js.snap +++ b/src/components/OrderDetailsPanel/__snapshots__/OrderDetailsPanel.test.js.snap @@ -178,12 +178,13 @@ exports[`OrderDetailsPanel accepted matches snapshot 1`] = ` "listing": Object { "attributes": Object { "address": "listing1 address", + "closed": false, + "deleted": false, "description": "listing1 description", "geolocation": LatLng { "lat": 40, "lng": 60, }, - "open": true, "price": Money { "amount": 5500, "currency": "USD", @@ -354,12 +355,13 @@ exports[`OrderDetailsPanel accepted matches snapshot 1`] = ` "listing": Object { "attributes": Object { "address": "listing1 address", + "closed": false, + "deleted": false, "description": "listing1 description", "geolocation": LatLng { "lat": 40, "lng": 60, }, - "open": true, "price": Money { "amount": 5500, "currency": "USD", @@ -563,12 +565,13 @@ exports[`OrderDetailsPanel autorejected matches snapshot 1`] = ` "listing": Object { "attributes": Object { "address": "listing1 address", + "closed": false, + "deleted": false, "description": "listing1 description", "geolocation": LatLng { "lat": 40, "lng": 60, }, - "open": true, "price": Money { "amount": 5500, "currency": "USD", @@ -739,12 +742,13 @@ exports[`OrderDetailsPanel autorejected matches snapshot 1`] = ` "listing": Object { "attributes": Object { "address": "listing1 address", + "closed": false, + "deleted": false, "description": "listing1 description", "geolocation": LatLng { "lat": 40, "lng": 60, }, - "open": true, "price": Money { "amount": 5500, "currency": "USD", @@ -948,12 +952,13 @@ exports[`OrderDetailsPanel delivered matches snapshot 1`] = ` "listing": Object { "attributes": Object { "address": "listing1 address", + "closed": false, + "deleted": false, "description": "listing1 description", "geolocation": LatLng { "lat": 40, "lng": 60, }, - "open": true, "price": Money { "amount": 5500, "currency": "USD", @@ -1124,12 +1129,13 @@ exports[`OrderDetailsPanel delivered matches snapshot 1`] = ` "listing": Object { "attributes": Object { "address": "listing1 address", + "closed": false, + "deleted": false, "description": "listing1 description", "geolocation": LatLng { "lat": 40, "lng": 60, }, - "open": true, "price": Money { "amount": 5500, "currency": "USD", @@ -1337,12 +1343,13 @@ exports[`OrderDetailsPanel preauthorized matches snapshot 1`] = ` "listing": Object { "attributes": Object { "address": "listing1 address", + "closed": false, + "deleted": false, "description": "listing1 description", "geolocation": LatLng { "lat": 40, "lng": 60, }, - "open": true, "price": Money { "amount": 5500, "currency": "USD", @@ -1513,12 +1520,13 @@ exports[`OrderDetailsPanel preauthorized matches snapshot 1`] = ` "listing": Object { "attributes": Object { "address": "listing1 address", + "closed": false, + "deleted": false, "description": "listing1 description", "geolocation": LatLng { "lat": 40, "lng": 60, }, - "open": true, "price": Money { "amount": 5500, "currency": "USD", diff --git a/src/components/SaleDetailsPanel/__snapshots__/SaleDetailsPanel.test.js.snap b/src/components/SaleDetailsPanel/__snapshots__/SaleDetailsPanel.test.js.snap index cf1acf9f..0071a5d9 100644 --- a/src/components/SaleDetailsPanel/__snapshots__/SaleDetailsPanel.test.js.snap +++ b/src/components/SaleDetailsPanel/__snapshots__/SaleDetailsPanel.test.js.snap @@ -185,12 +185,13 @@ exports[`SaleDetailsPanel accepted matches snapshot 1`] = ` "listing": Object { "attributes": Object { "address": "listing1 address", + "closed": false, + "deleted": false, "description": "listing1 description", "geolocation": LatLng { "lat": 40, "lng": 60, }, - "open": true, "price": Money { "amount": 5500, "currency": "USD", @@ -318,12 +319,13 @@ exports[`SaleDetailsPanel accepted matches snapshot 1`] = ` "listing": Object { "attributes": Object { "address": "listing1 address", + "closed": false, + "deleted": false, "description": "listing1 description", "geolocation": LatLng { "lat": 40, "lng": 60, }, - "open": true, "price": Money { "amount": 5500, "currency": "USD", @@ -533,12 +535,13 @@ exports[`SaleDetailsPanel autorejected matches snapshot 1`] = ` "listing": Object { "attributes": Object { "address": "listing1 address", + "closed": false, + "deleted": false, "description": "listing1 description", "geolocation": LatLng { "lat": 40, "lng": 60, }, - "open": true, "price": Money { "amount": 5500, "currency": "USD", @@ -666,12 +669,13 @@ exports[`SaleDetailsPanel autorejected matches snapshot 1`] = ` "listing": Object { "attributes": Object { "address": "listing1 address", + "closed": false, + "deleted": false, "description": "listing1 description", "geolocation": LatLng { "lat": 40, "lng": 60, }, - "open": true, "price": Money { "amount": 5500, "currency": "USD", @@ -881,12 +885,13 @@ exports[`SaleDetailsPanel delivered matches snapshot 1`] = ` "listing": Object { "attributes": Object { "address": "listing1 address", + "closed": false, + "deleted": false, "description": "listing1 description", "geolocation": LatLng { "lat": 40, "lng": 60, }, - "open": true, "price": Money { "amount": 5500, "currency": "USD", @@ -1014,12 +1019,13 @@ exports[`SaleDetailsPanel delivered matches snapshot 1`] = ` "listing": Object { "attributes": Object { "address": "listing1 address", + "closed": false, + "deleted": false, "description": "listing1 description", "geolocation": LatLng { "lat": 40, "lng": 60, }, - "open": true, "price": Money { "amount": 5500, "currency": "USD", @@ -1241,12 +1247,13 @@ exports[`SaleDetailsPanel preauthorized matches snapshot 1`] = ` "listing": Object { "attributes": Object { "address": "listing1 address", + "closed": false, + "deleted": false, "description": "listing1 description", "geolocation": LatLng { "lat": 40, "lng": 60, }, - "open": true, "price": Money { "amount": 5500, "currency": "USD", @@ -1374,12 +1381,13 @@ exports[`SaleDetailsPanel preauthorized matches snapshot 1`] = ` "listing": Object { "attributes": Object { "address": "listing1 address", + "closed": false, + "deleted": false, "description": "listing1 description", "geolocation": LatLng { "lat": 40, "lng": 60, }, - "open": true, "price": Money { "amount": 5500, "currency": "USD", From df9bd83e806df2799cae6706fe88fdffd7a358f4 Mon Sep 17 00:00:00 2001 From: Kimmo Puputti Date: Fri, 29 Sep 2017 15:10:19 +0300 Subject: [PATCH 12/14] Use tx state helpers in Inbox --- src/containers/InboxPage/InboxPage.js | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/containers/InboxPage/InboxPage.js b/src/containers/InboxPage/InboxPage.js index fd23d4e4..38e77ba5 100644 --- a/src/containers/InboxPage/InboxPage.js +++ b/src/containers/InboxPage/InboxPage.js @@ -39,8 +39,7 @@ const formatDate = (intl, date) => { // Translated name of the state of the given transaction const txState = (intl, tx, isOrder) => { - const { attributes: { lastTransition } } = tx; - if (lastTransition === propTypes.TX_TRANSITION_ACCEPT) { + if (propTypes.txIsAccepted(tx)) { return { nameClassName: css.nameAccepted, bookingClassName: css.bookingAccepted, @@ -50,7 +49,7 @@ const txState = (intl, tx, isOrder) => { id: 'InboxPage.stateAccepted', }), }; - } else if (lastTransition === propTypes.TX_TRANSITION_REJECT) { + } else if (propTypes.txIsRejectedOrAutorejected(tx)) { return { nameClassName: css.nameDeclined, bookingClassName: css.bookingDeclined, @@ -60,7 +59,7 @@ const txState = (intl, tx, isOrder) => { id: 'InboxPage.stateDeclined', }), }; - } else if (lastTransition === propTypes.TX_TRANSITION_MARK_DELIVERED) { + } else if (propTypes.txIsDelivered(tx)) { return { nameClassName: css.nameDelivered, bookingClassName: css.bookingDelivered, @@ -101,8 +100,7 @@ export const InboxItem = props => { const otherUserDisplayName = userDisplayName(otherUser, bannedUserDisplayName); const stateData = txState(intl, tx, isOrder); - const isPreauthorized = tx.attributes.lastTransition === propTypes.TX_TRANSITION_PREAUTHORIZE; - const isSaleNotification = !isOrder && isPreauthorized; + const isSaleNotification = !isOrder && propTypes.txIsPreauthorized(tx); const rowNotificationDot = isSaleNotification ?
: null; const lastTransitionedAt = formatDate(intl, tx.attributes.lastTransitionedAt); const bookingStart = formatDate(intl, booking.attributes.start); From da7f2e686d172d270cf1b161099df21a9e34a8d4 Mon Sep 17 00:00:00 2001 From: Kimmo Puputti Date: Mon, 2 Oct 2017 16:04:43 +0300 Subject: [PATCH 13/14] Use ensureTransaction instead of something similar manual --- src/util/propTypes.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/util/propTypes.js b/src/util/propTypes.js index 8619e2a5..d2669da5 100644 --- a/src/util/propTypes.js +++ b/src/util/propTypes.js @@ -20,6 +20,7 @@ import { PropTypes } from 'react'; import Decimal from 'decimal.js'; import { types as sdkTypes } from './sdkLoader'; +import { ensureTransaction } from './data'; const { UUID, LatLng, LatLngBounds, Money } = sdkTypes; const { arrayOf, bool, func, instanceOf, number, oneOf, shape, string } = PropTypes; @@ -163,9 +164,7 @@ export const TX_TRANSITIONS = [ TX_TRANSITION_MARK_DELIVERED, ]; -const txLastTransition = tx => { - return tx && tx.attributes && tx.attributes.lastTransition ? tx.attributes.lastTransition : null; -}; +const txLastTransition = tx => ensureTransaction(tx).attributes.lastTransition; export const txIsPreauthorized = tx => txLastTransition(tx) === TX_TRANSITION_PREAUTHORIZE; From d9996c9084535afccd1f2bf3cc525819a07d29c1 Mon Sep 17 00:00:00 2001 From: Kimmo Puputti Date: Mon, 2 Oct 2017 16:05:06 +0300 Subject: [PATCH 14/14] Use the current state filtering until API is changed --- src/ducks/user.duck.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/ducks/user.duck.js b/src/ducks/user.duck.js index ede121a4..57ec1e71 100644 --- a/src/ducks/user.duck.js +++ b/src/ducks/user.duck.js @@ -298,8 +298,14 @@ export const fetchCurrentUserNotifications = () => const apiQueryParams = { only: 'sale', - // TODO: how to change this to use lastTransition? - // states: [TX_STATE_PREAUTHORIZED], + + // TODO: Currently the API supports only filtering by tx + // state. However, the state will be removed and support for + // filtering by last transitions is added. The code below should + // be changed at that point. + states: ['state/preauthorized'], + // last_transitions: [TX_TRANSITION_PREAUTHORIZE], + page: 1, per_page: NOTIFICATION_PAGE_SIZE, };