From 8d88bf99ba7af75acf9ec7238978d4e83b63bfe9 Mon Sep 17 00:00:00 2001 From: Jack Mallers Date: Tue, 15 Aug 2017 18:36:01 -0500 Subject: [PATCH] feature(payment): add basic tests for payments reducer --- .../__snapshots__/channels.spec.js.snap | 64 +++++++ .../__snapshots__/invoice.spec.js.snap | 169 ++++++++++++++++++ .../__snapshots__/payment.spec.js.snap | 46 +++++ test/reducers/invoice.spec.js | 2 +- test/reducers/payment.spec.js | 52 ++++++ 5 files changed, 332 insertions(+), 1 deletion(-) create mode 100644 test/reducers/__snapshots__/invoice.spec.js.snap create mode 100644 test/reducers/__snapshots__/payment.spec.js.snap create mode 100644 test/reducers/payment.spec.js diff --git a/test/reducers/__snapshots__/channels.spec.js.snap b/test/reducers/__snapshots__/channels.spec.js.snap index 2b2281f9..baf6af43 100644 --- a/test/reducers/__snapshots__/channels.spec.js.snap +++ b/test/reducers/__snapshots__/channels.spec.js.snap @@ -1,5 +1,69 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`reducers channelsReducer should correctly getChannels 1`] = ` +Object { + "channel": null, + "channelForm": Object { + "isOpen": false, + "local_amt": "", + "node_key": "", + "push_amt": "", + }, + "channels": Array [], + "channelsLoading": true, + "openingChannel": false, + "pendingChannels": Object { + "pending_closing_channels": Array [], + "pending_force_closing_channels": Array [], + "pending_open_channels": Array [], + "total_limbo_balance": "", + }, +} +`; + +exports[`reducers channelsReducer should correctly openingChannel 1`] = ` +Object { + "channel": null, + "channelForm": Object { + "isOpen": false, + "local_amt": "", + "node_key": "", + "push_amt": "", + }, + "channels": Array [], + "channelsLoading": false, + "openingChannel": true, + "pendingChannels": Object { + "pending_closing_channels": Array [], + "pending_force_closing_channels": Array [], + "pending_open_channels": Array [], + "total_limbo_balance": "", + }, +} +`; + +exports[`reducers channelsReducer should correctly receiveChannel 1`] = ` +Object { + "channel": null, + "channelForm": Object { + "isOpen": false, + "local_amt": "", + "node_key": "", + "push_amt": "", + }, + "channels": Array [ + 1, + 2, + ], + "channelsLoading": false, + "openingChannel": false, + "pendingChannels": Array [ + 3, + 4, + ], +} +`; + exports[`reducers channelsReducer should correctly setChannel 1`] = ` Object { "channel": "channel", diff --git a/test/reducers/__snapshots__/invoice.spec.js.snap b/test/reducers/__snapshots__/invoice.spec.js.snap new file mode 100644 index 00000000..728904d0 --- /dev/null +++ b/test/reducers/__snapshots__/invoice.spec.js.snap @@ -0,0 +1,169 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`reducers invoiceReducer should correctly getInvoice 1`] = ` +Object { + "data": Object {}, + "formInvoice": Object { + "amount": "0", + "payreq": "", + "r_hash": "", + }, + "invoice": null, + "invoiceLoading": true, + "invoices": Array [], + "invoicesSearchText": "", +} +`; + +exports[`reducers invoiceReducer should correctly getInvoices 1`] = ` +Object { + "data": Object {}, + "formInvoice": Object { + "amount": "0", + "payreq": "", + "r_hash": "", + }, + "invoice": null, + "invoiceLoading": true, + "invoices": Array [], + "invoicesSearchText": "", +} +`; + +exports[`reducers invoiceReducer should correctly invcoiceFailed 1`] = ` +Object { + "data": null, + "formInvoice": Object { + "amount": "0", + "payreq": "", + "r_hash": "", + }, + "invoice": null, + "invoiceLoading": false, + "invoices": Array [], + "invoicesSearchText": "", +} +`; + +exports[`reducers invoiceReducer should correctly invcoiceSuccessful 1`] = ` +Object { + "data": Object {}, + "formInvoice": Object { + "amount": "0", + "payreq": "", + "r_hash": "", + }, + "invoice": null, + "invoiceLoading": false, + "invoices": Array [ + "foo", + ], + "invoicesSearchText": "", +} +`; + +exports[`reducers invoiceReducer should correctly receiveFormInvoice 1`] = ` +Object { + "data": Object {}, + "formInvoice": Object { + "payreq": "foo", + }, + "invoice": null, + "invoiceLoading": false, + "invoices": Array [], + "invoicesSearchText": "", +} +`; + +exports[`reducers invoiceReducer should correctly receiveInvoice 1`] = ` +Object { + "data": Object {}, + "formInvoice": Object { + "amount": "0", + "payreq": "", + "r_hash": "", + }, + "invoice": "foo", + "invoiceLoading": false, + "invoices": Array [], + "invoicesSearchText": "", +} +`; + +exports[`reducers invoiceReducer should correctly receiveInvoices 1`] = ` +Object { + "data": Object {}, + "formInvoice": Object { + "amount": "0", + "payreq": "", + "r_hash": "", + }, + "invoice": null, + "invoiceLoading": false, + "invoices": Array [ + 1, + 2, + ], + "invoicesSearchText": "", +} +`; + +exports[`reducers invoiceReducer should correctly searchInvoices 1`] = ` +Object { + "data": Object {}, + "formInvoice": Object { + "amount": "0", + "payreq": "", + "r_hash": "", + }, + "invoice": null, + "invoiceLoading": false, + "invoices": Array [], + "invoicesSearchText": "foo", +} +`; + +exports[`reducers invoiceReducer should correctly sendInvoice 1`] = ` +Object { + "data": Object {}, + "formInvoice": Object { + "amount": "0", + "payreq": "", + "r_hash": "", + }, + "invoice": null, + "invoiceLoading": true, + "invoices": Array [], + "invoicesSearchText": "", +} +`; + +exports[`reducers invoiceReducer should correctly setInvoice 1`] = ` +Object { + "data": Object {}, + "formInvoice": Object { + "amount": "0", + "payreq": "", + "r_hash": "", + }, + "invoice": "foo", + "invoiceLoading": false, + "invoices": Array [], + "invoicesSearchText": "", +} +`; + +exports[`reducers invoiceReducer should handle initial state 1`] = ` +Object { + "data": Object {}, + "formInvoice": Object { + "amount": "0", + "payreq": "", + "r_hash": "", + }, + "invoice": null, + "invoiceLoading": false, + "invoices": Array [], + "invoicesSearchText": "", +} +`; diff --git a/test/reducers/__snapshots__/payment.spec.js.snap b/test/reducers/__snapshots__/payment.spec.js.snap new file mode 100644 index 00000000..135c163d --- /dev/null +++ b/test/reducers/__snapshots__/payment.spec.js.snap @@ -0,0 +1,46 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`reducers paymentReducer should correctly getPayments 1`] = ` +Object { + "payment": null, + "paymentLoading": true, + "payments": Array [], +} +`; + +exports[`reducers paymentReducer should correctly paymentSuccessful 1`] = ` +Object { + "payment": null, + "paymentLoading": false, + "payments": Array [ + "foo", + ], +} +`; + +exports[`reducers paymentReducer should correctly receivePayments 1`] = ` +Object { + "payment": null, + "paymentLoading": false, + "payments": Array [ + 1, + 2, + ], +} +`; + +exports[`reducers paymentReducer should correctly sendPayment 1`] = ` +Object { + "payment": "foo", + "paymentLoading": false, + "payments": Array [], +} +`; + +exports[`reducers paymentReducer should handle initial state 1`] = ` +Object { + "payment": null, + "paymentLoading": false, + "payments": Array [], +} +`; diff --git a/test/reducers/invoice.spec.js b/test/reducers/invoice.spec.js index 369ffd89..3e84aba4 100644 --- a/test/reducers/invoice.spec.js +++ b/test/reducers/invoice.spec.js @@ -9,7 +9,7 @@ import invoiceReducer, { SEND_INVOICE, INVOICE_SUCCESSFUL, INVOICE_FAILED -} from '../../app/reducers/info' +} from '../../app/reducers/invoice' describe('reducers', () => { describe('invoiceReducer', () => { diff --git a/test/reducers/payment.spec.js b/test/reducers/payment.spec.js new file mode 100644 index 00000000..743e64e3 --- /dev/null +++ b/test/reducers/payment.spec.js @@ -0,0 +1,52 @@ +import paymentReducer, { + SET_PAYMENT, + GET_PAYMENTS, + RECEIVE_PAYMENTS, + SEND_PAYMENT, + PAYMENT_SUCCESSFULL, + PAYMENT_FAILED +} from '../../app/reducers/payment' + +describe('reducers', () => { + describe('paymentReducer', () => { + it('should handle initial state', () => { + expect(paymentReducer(undefined, {})).toMatchSnapshot() + }) + + it('should have SET_PAYMENT', () => { + expect(SET_PAYMENT).toEqual('SET_PAYMENT') + }) + + it('should have RECEIVE_PAYMENTS', () => { + expect(RECEIVE_PAYMENTS).toEqual('RECEIVE_PAYMENTS') + }) + + it('should have SEND_PAYMENT', () => { + expect(SEND_PAYMENT).toEqual('SEND_PAYMENT') + }) + + it('should have PAYMENT_SUCCESSFULL', () => { + expect(PAYMENT_SUCCESSFULL).toEqual('PAYMENT_SUCCESSFULL') + }) + + it('should have PAYMENT_FAILED', () => { + expect(PAYMENT_FAILED).toEqual('PAYMENT_FAILED') + }) + + it('should correctly sendPayment', () => { + expect(paymentReducer(undefined, { type: SET_PAYMENT, payment: 'foo' })).toMatchSnapshot() + }) + + it('should correctly getPayments', () => { + expect(paymentReducer(undefined, { type: GET_PAYMENTS })).toMatchSnapshot() + }) + + it('should correctly receivePayments', () => { + expect(paymentReducer(undefined, { type: RECEIVE_PAYMENTS, payments: [1, 2] })).toMatchSnapshot() + }) + + it('should correctly paymentSuccessful', () => { + expect(paymentReducer(undefined, { type: PAYMENT_SUCCESSFULL, payment: 'foo' })).toMatchSnapshot() + }) + }) +})