Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
235 changes: 128 additions & 107 deletions src/actions/__tests__/payments.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,126 +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('setAmount', () => {
it('creates an action', () => {
expect(actions.setAmount('29.95', 'Receipt')).toEqual({
type: types.SET_AMOUNT,
payload: {
requestedAmount: '29.95',
receipt: 'Receipt'
}
it('accepts an empty receipt', () => {
expect(actions.setAmount('29.95')).toEqual({
type: types.SET_AMOUNT,
payload: {
requestedAmount: '29.95',
receipt: null
}
})
})
})

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

describe('setTip', () => {
it('creates an action', () => {
expect(actions.setTip('3.00')).toEqual({
type: types.SET_TIP,
payload: {
tip: 3
}
describe('cancelPayment', () => {
it('cancels a running payment request', () => {
expect(actions.cancelPayment()).toEqual({
type: types.CANCEL_PAYMENT
})
})
})
})

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',
fiatCurrency: 'EUR',
createdAt: '2017-06-17T17:30:00.000Z',
updatedAt: '2017-06-17T17:30:00.000Z'
}
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 @@ -138,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
Loading