Skip to content

Commit

Permalink
Refactored payment actions & specs.
Browse files Browse the repository at this point in the history
Payment states.
  • Loading branch information
amiuhle committed Oct 9, 2018
1 parent 7d736f0 commit 8c2b0dd
Show file tree
Hide file tree
Showing 5 changed files with 245 additions and 127 deletions.
236 changes: 128 additions & 108 deletions src/actions/__tests__/payments.js
Expand Up @@ -9,127 +9,144 @@ const creationTime = '2017-06-17T17:30:00.000Z'
const createdAt = () => creationTime

describe('Payment Actions', () => {
describe('requestPayment', () => {
it('creates an action', () => {
expect(actions.requestPayment(noop, noop, 3000))
.toEqual({
type: types.REQUEST_PAYMENT,
describe('User Input', () => {
describe('requestPayment', () => {
it('allows the seller to trigger a new payment workflow', () => {
expect(actions.requestPayment(noop, noop, 3000))
.toEqual({
type: types.REQUEST_PAYMENT,
payload: {
resolve: noop,
reject: noop
}
})
})
})

describe('setAmount', () => {
it('allows the seller to set amount and receipt', () => {
expect(actions.setAmount('29.95', 'Receipt')).toEqual({
type: types.SET_AMOUNT,
payload: {
resolve: noop,
reject: noop
requestedAmount: '29.95',
receipt: 'Receipt'
}
})
})
})
})

describe('createPayment', () => {
it('creates an action', () => {
expect(actions.createPayment(
'a2f8d724-5c7a-43e9-bbac-b0295b059e82', {
fiatCurrency: 'EUR'
}, createdAt)
).toEqual({
type: types.CREATE_PAYMENT,
payload: {
id: 'a2f8d724-5c7a-43e9-bbac-b0295b059e82',
state: 'CREATED',
fiatCurrency: 'EUR',
createdAt: '2017-06-17T17:30:00.000Z',
updatedAt: '2017-06-17T17:30:00.000Z'
}
it('accepts an empty receipt', () => {
expect(actions.setAmount('29.95')).toEqual({
type: types.SET_AMOUNT,
payload: {
requestedAmount: '29.95',
receipt: null
}
})
})
})
})

describe('setAmount', () => {
it('creates an action', () => {
expect(actions.setAmount('29.95', 'Receipt')).toEqual({
type: types.SET_AMOUNT,
payload: {
requestedAmount: '29.95',
receipt: 'Receipt'
}
describe('setTip', () => {
it('allows buyer to set a tip', () => {
expect(actions.setTip('0.015814568844')).toEqual({
type: types.SET_TIP,
payload: {
tip: '0.015814568844'
}
})
})
})

it('accepts empty receipt', () => {
expect(actions.setAmount('29.95')).toEqual({
type: types.SET_AMOUNT,
payload: {
requestedAmount: '29.95',
receipt: null
}
describe('cancelPayment', () => {
it('cancels a running payment request', () => {
expect(actions.cancelPayment()).toEqual({
type: types.CANCEL_PAYMENT
})
})
})
})

describe('setTip', () => {
it('creates an action', () => {
expect(actions.setTip('3.00')).toEqual({
type: types.SET_TIP,
payload: {
tip: 3
}
describe('Saga Actions', () => {
describe('createPayment', () => {
it('creates a new payment model', () => {
expect(actions.createPayment(
'a2f8d724-5c7a-43e9-bbac-b0295b059e82', {
fiatCurrency: 'EUR'
}, createdAt)
).toEqual({
type: types.CREATE_PAYMENT,
payload: {
id: 'a2f8d724-5c7a-43e9-bbac-b0295b059e82',
state: 'CREATED',
fiatCurrency: 'EUR',
createdAt: '2017-06-17T17:30:00.000Z',
updatedAt: '2017-06-17T17:30:00.000Z'
}
})
})
})
})

describe('updatePayment', () => {
it('creates an action', () => {
expect(
actions.updatePayment('a2f8d724-5c7a-43e9-bbac-b0295b059e82', {
address: '9sVBq8LNtWRLyWS8EWeUw1VqpqfwnDHTkG7Pb4NJ3RmZWeeMZhGMe2ZXz4bSk7BbtEYF5981nLxkDYQ6B46tX5DMLRHQFh6',
height: '1057120',
paymentId: '6b1887e13bbd81db',
rate: '315.84800377'
}, createdAt)
).toEqual({
type: types.UPDATE_PAYMENT,
payload: {
id: 'a2f8d724-5c7a-43e9-bbac-b0295b059e82',
address: '9sVBq8LNtWRLyWS8EWeUw1VqpqfwnDHTkG7Pb4NJ3RmZWeeMZhGMe2ZXz4bSk7BbtEYF5981nLxkDYQ6B46tX5DMLRHQFh6',
height: '1057120',
paymentId: '6b1887e13bbd81db',
rate: '315.84800377'
// updatedAt: creationTime
}
describe('networkInput', () => {
it('sets required network info', () => {
expect(actions.networkInput(
'a2f8d724-5c7a-43e9-bbac-b0295b059e82',
'9sVBq8LNtWRLyWS8EWeUw1VqpqfwnDHTkG7Pb4NJ3RmZWeeMZhGMe2ZXz4bSk7BbtEYF5981nLxkDYQ6B46tX5DMLRHQFh6',
'A3Brqw9sVmwLyWS8EWeUw1VqpqfwnDHTkG7Pb4NJ3RmZWeeMZhGMe2ZXz4bSk7BbtEYF5981nLxkDYQ6B46tX5DMVqg62UVmnbzRji2SB9',
'1057120',
'6b1887e13bbd81db',
'315.84800377'
)).toEqual({
type: types.UPDATE_PAYMENT,
payload: {
id: 'a2f8d724-5c7a-43e9-bbac-b0295b059e82',
address: '9sVBq8LNtWRLyWS8EWeUw1VqpqfwnDHTkG7Pb4NJ3RmZWeeMZhGMe2ZXz4bSk7BbtEYF5981nLxkDYQ6B46tX5DMLRHQFh6',
integratedAddress: 'A3Brqw9sVmwLyWS8EWeUw1VqpqfwnDHTkG7Pb4NJ3RmZWeeMZhGMe2ZXz4bSk7BbtEYF5981nLxkDYQ6B46tX5DMVqg62UVmnbzRji2SB9',
height: '1057120',
paymentId: '6b1887e13bbd81db',
rate: '315.84800377',
state: 'NETWORK_INPUT'
// updatedAt: creationTime
}
})
})
})

expect(
actions.updatePayment('a2f8d724-5c7a-43e9-bbac-b0295b059e82', {
requestedAmount: '49.95',
convertedAmount: '0.158145688444',
receipt: 'Receipt #12'
}, createdAt)
).toEqual({
type: types.UPDATE_PAYMENT,
payload: {
id: 'a2f8d724-5c7a-43e9-bbac-b0295b059e82',
requestedAmount: '49.95',
convertedAmount: '0.158145688444',
receipt: 'Receipt #12'
// updatedAt: creationTime
}
describe('sellerInput', () => {
it('sets required seller info', () => {
expect(
actions.sellerInput('a2f8d724-5c7a-43e9-bbac-b0295b059e82',
'49.95',
'0.158145688444'
)
).toEqual({
type: types.UPDATE_PAYMENT,
payload: {
id: 'a2f8d724-5c7a-43e9-bbac-b0295b059e82',
requestedAmount: '49.95',
convertedAmount: '0.158145688444',
state: 'SELLER_INPUT'
// updatedAt: creationTime
}
})
})
})

expect(
actions.updatePayment('a2f8d724-5c7a-43e9-bbac-b0295b059e82', {
uri: 'monero:9sVBq8LNtWRLyWS8EWeUw1VqpqfwnDHTkG7Pb4NJ3RmZWeeMZhGMe2ZXz4bSk7BbtEYF5981nLxkDYQ6B46tX5DMLRHQFh6?tx_payment_id=6b1887e13bbd81db&tx_amount=0.158145688444&recipient_name=Barolo%20Beach%20Cafe&tx_description=Receipt%20%2312'
}, createdAt)
).toEqual({
type: types.UPDATE_PAYMENT,
payload: {
id: 'a2f8d724-5c7a-43e9-bbac-b0295b059e82',
uri: 'monero:9sVBq8LNtWRLyWS8EWeUw1VqpqfwnDHTkG7Pb4NJ3RmZWeeMZhGMe2ZXz4bSk7BbtEYF5981nLxkDYQ6B46tX5DMLRHQFh6?tx_payment_id=6b1887e13bbd81db&tx_amount=0.158145688444&recipient_name=Barolo%20Beach%20Cafe&tx_description=Receipt%20%2312'
// updatedAt: creationTime
}
describe('setUri', () => {
it('updates the uri for the QR code', () => {
expect(
actions.setUri('a2f8d724-5c7a-43e9-bbac-b0295b059e82', 'monero:9sVBq8LNtWRLyWS8EWeUw1VqpqfwnDHTkG7Pb4NJ3RmZWeeMZhGMe2ZXz4bSk7BbtEYF5981nLxkDYQ6B46tX5DMLRHQFh6?tx_payment_id=6b1887e13bbd81db&tx_amount=0.158145688444&recipient_name=Barolo%20Beach%20Cafe&tx_description=Receipt%20%2312')
).toEqual({
type: types.UPDATE_PAYMENT,
payload: {
id: 'a2f8d724-5c7a-43e9-bbac-b0295b059e82',
uri: 'monero:9sVBq8LNtWRLyWS8EWeUw1VqpqfwnDHTkG7Pb4NJ3RmZWeeMZhGMe2ZXz4bSk7BbtEYF5981nLxkDYQ6B46tX5DMLRHQFh6?tx_payment_id=6b1887e13bbd81db&tx_amount=0.158145688444&recipient_name=Barolo%20Beach%20Cafe&tx_description=Receipt%20%2312',
tip: null
// updatedAt: creationTime
}
})
})

expect(
actions.updatePayment('a2f8d724-5c7a-43e9-bbac-b0295b059e82', {
uri: 'monero:9sVBq8LNtWRLyWS8EWeUw1VqpqfwnDHTkG7Pb4NJ3RmZWeeMZhGMe2ZXz4bSk7BbtEYF5981nLxkDYQ6B46tX5DMLRHQFh6?tx_payment_id=6b1887e13bbd81db&tx_amount=0.173960257288&recipient_name=Barolo%20Beach%20Cafe&tx_description=Receipt%20%2312',
tip: '0.015814568844'
}, createdAt)
actions.setUri('a2f8d724-5c7a-43e9-bbac-b0295b059e82', 'monero:9sVBq8LNtWRLyWS8EWeUw1VqpqfwnDHTkG7Pb4NJ3RmZWeeMZhGMe2ZXz4bSk7BbtEYF5981nLxkDYQ6B46tX5DMLRHQFh6?tx_payment_id=6b1887e13bbd81db&tx_amount=0.173960257288&recipient_name=Barolo%20Beach%20Cafe&tx_description=Receipt%20%2312', '0.015814568844')
).toEqual({
type: types.UPDATE_PAYMENT,
payload: {
Expand All @@ -139,18 +156,21 @@ describe('Payment Actions', () => {
// updatedAt: creationTime
}
})
})

expect(
actions.updatePayment('a2f8d724-5c7a-43e9-bbac-b0295b059e82', {
receivedAmount: '0.158145688444'
}, createdAt)
).toEqual({
type: types.UPDATE_PAYMENT,
payload: {
id: 'a2f8d724-5c7a-43e9-bbac-b0295b059e82',
receivedAmount: '0.158145688444'
// updatedAt: creationTime
}
describe('receivePayment', () => {
it('finalizes the payment', () => {
expect(
actions.receivePayment('a2f8d724-5c7a-43e9-bbac-b0295b059e82', '0.158145688444')
).toEqual({
type: types.UPDATE_PAYMENT,
payload: {
id: 'a2f8d724-5c7a-43e9-bbac-b0295b059e82',
receivedAmount: '0.158145688444',
state: 'PAYMENT_RECEIVED'
// updatedAt: creationTime
}
})
})
})
})
Expand Down

0 comments on commit 8c2b0dd

Please sign in to comment.