How to use streamBuilder method in fast-check-monorepo

Best JavaScript code snippet using fast-check-monorepo

streamPayments.spec.js

Source:streamPayments.spec.js Github

copy

Full Screen

1import omit from "lodash/omit";2import { exceptions } from "config";3import {4 streamPaymentActions as actions,5 streamPaymentTypes as types,6 streamPaymentOperations as operations,7 streamPaymentSelectors as selectors,8} from "modules/streamPayments";9import streamPaymentReducer, { initStateStreamPayment } from "modules/streamPayments/reducers";10import { accountOperations, accountTypes } from "modules/account";11import { appTypes, appOperations } from "modules/app";12import { channelsOperations } from "modules/channels";13import { notificationsTypes } from "modules/notifications";14import { lightningOperations } from "modules/lightning";15import { configureStore, persistedState } from "store/configure-store";16import { SUCCESS_RESPONSE, STREAM_INFINITE_TIME_VALUE } from "config/consts";17import { db, errorPromise, successPromise, delay } from "additional";18describe("Stream Payment Unit Tests", () => {19 describe("Action creators", () => {20 let data;21 let expectedData;22 beforeEach(() => {23 data = "foo";24 expectedData = {25 payload: data,26 type: undefined,27 };28 });29 it("should create an action to set stream payment prepare details", () => {30 expectedData.type = types.PREPARE_STREAM_PAYMENT;31 expect(actions.prepareStreamPayment(data)).to.deep.equal(expectedData);32 });33 it("should create an action to set current stream payment", () => {34 expectedData.type = types.SET_CURRENT_STREAM;35 expect(actions.setCurrentStream(data)).to.deep.equal(expectedData);36 });37 it("should create an action to set stream payment status", () => {38 data = {39 streamId: "foo",40 details: "bar",41 };42 expectedData = {43 payload: data,44 type: types.UPDATE_STREAM_PAYMENT,45 };46 expect(actions.updateStreamPayment(data.streamId, data.details)).to.deep.equal(expectedData);47 });48 it("should create an action to change stream parts paid", () => {49 data = {50 streamId: "foo",51 change: 1,52 };53 expectedData = {54 payload: data,55 type: types.CHANGE_STREAM_PARTS_PAID,56 };57 expect(actions.changeStreamPartsPaid(data.streamId, data.change)).to.deep.equal(expectedData);58 });59 it("should create an action to change stream parts pending", () => {60 data = {61 streamId: "foo",62 change: 1,63 };64 expectedData = {65 payload: data,66 type: types.CHANGE_STREAM_PARTS_PENDING,67 };68 expect(actions.changeStreamPartsPending(data.streamId, data.change)).to.deep.equal(expectedData);69 });70 it("should create an action to add stream to list", () => {71 expectedData = {72 type: types.ADD_STREAM_PAYMENT_TO_LIST,73 };74 expect(actions.addStreamPaymentToList(data)).to.deep.equal(expectedData);75 });76 it("should create an action to set streams", () => {77 expectedData.type = types.SET_STREAM_PAYMENTS;78 expect(actions.setStreamPayments(data)).to.deep.equal(expectedData);79 });80 });81 describe("Reducer actions", () => {82 let data;83 let action;84 let expectedData;85 let state;86 beforeEach(() => {87 data = "foo";88 action = {89 payload: data,90 type: undefined,91 };92 expectedData = JSON.parse(JSON.stringify(initStateStreamPayment));93 state = undefined;94 });95 it("should return the initial state", () => {96 expect(streamPaymentReducer(state, action)).to.deep.equal(expectedData);97 });98 it("should handle LOGOUT_ACCOUNT action", () => {99 action.type = accountTypes.LOGOUT_ACCOUNT;100 state = JSON.parse(JSON.stringify(initStateStreamPayment));101 state.streamDetails = "foo";102 expect(streamPaymentReducer(state, action)).to.deep.equal(expectedData);103 });104 it("should handle PREPARE_STREAM_PAYMENT action", () => {105 action.type = types.PREPARE_STREAM_PAYMENT;106 expectedData.streamDetails = data;107 expect(streamPaymentReducer(state, action)).to.deep.equal(expectedData);108 });109 it("should handle SET_CURRENT_STREAM action", () => {110 action.type = types.SET_CURRENT_STREAM;111 expectedData.currentStream = data;112 expect(streamPaymentReducer(state, action)).to.deep.equal(expectedData);113 });114 it("should handle UPDATE_STREAM_PAYMENT action", () => {115 data = {116 streamId: "qux",117 details: {118 some: 1,119 },120 };121 action = {122 payload: data,123 type: types.UPDATE_STREAM_PAYMENT,124 };125 state = JSON.parse(JSON.stringify(initStateStreamPayment));126 state.streams = [127 {128 some: 2,129 id: "bar",130 },131 {132 some: 3,133 id: "qux",134 },135 ];136 expectedData.streams = [137 {138 some: 2,139 id: "bar",140 },141 {142 some: 1,143 id: "qux",144 },145 ];146 expect(streamPaymentReducer(state, action)).to.deep.equal(expectedData);147 });148 it("should handle CHANGE_STREAM_PARTS_PAID action", () => {149 data = {150 streamId: "qux",151 change: 1,152 };153 action = {154 payload: data,155 type: types.CHANGE_STREAM_PARTS_PAID,156 };157 state = JSON.parse(JSON.stringify(initStateStreamPayment));158 state.streams = [159 {160 partsPaid: 2,161 id: "bar",162 },163 {164 partsPaid: 3,165 id: "qux",166 },167 ];168 expectedData.streams = [169 {170 partsPaid: 2,171 id: "bar",172 },173 {174 partsPaid: 4,175 id: "qux",176 },177 ];178 expect(streamPaymentReducer(state, action)).to.deep.equal(expectedData);179 });180 it("should handle CHANGE_STREAM_PARTS_PENDING action", () => {181 data = {182 streamId: "qux",183 change: 1,184 };185 action = {186 payload: data,187 type: types.CHANGE_STREAM_PARTS_PENDING,188 };189 state = JSON.parse(JSON.stringify(initStateStreamPayment));190 state.streams = [191 {192 partsPending: 2,193 id: "bar",194 },195 {196 partsPending: 3,197 id: "qux",198 },199 ];200 expectedData.streams = [201 {202 partsPending: 2,203 id: "bar",204 },205 {206 partsPending: 4,207 id: "qux",208 },209 ];210 expect(streamPaymentReducer(state, action)).to.deep.equal(expectedData);211 });212 it("should handle ADD_STREAM_PAYMENT_TO_LIST action", () => {213 action = {214 type: types.ADD_STREAM_PAYMENT_TO_LIST,215 };216 state = JSON.parse(JSON.stringify(initStateStreamPayment));217 state.streams = ["foo"];218 state.streamDetails = "bar";219 expectedData.streams = ["foo", "bar"];220 expect(streamPaymentReducer(state, action)).to.deep.equal(expectedData);221 });222 it("should handle SET_STREAM_PAYMENTS action", () => {223 data = ["foo"];224 action = {225 payload: data,226 type: types.SET_STREAM_PAYMENTS,227 };228 expectedData.streams = data;229 expect(streamPaymentReducer(state, action)).to.deep.equal(expectedData);230 });231 });232 describe("Operations tests", () => {233 const lightningID = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";234 let fakeDB;235 let data;236 let store;237 let initState;238 let expectedActions;239 let listActions;240 let expectedData;241 let errorResp;242 let successResp;243 let fakeLightning;244 let fakeDispatchReturnError;245 let fakeDispatchReturnSuccess;246 let fakeApp;247 let fakeAccount;248 let fakeChannels;249 beforeEach(async () => {250 errorResp = await errorPromise(undefined, { name: undefined });251 successResp = await successPromise();252 fakeDispatchReturnError = () => errorResp;253 fakeDispatchReturnSuccess = () => successResp;254 listActions = [];255 fakeDB = sinon.stub(db);256 fakeApp = sinon.stub(appOperations);257 fakeAccount = sinon.stub(accountOperations);258 fakeLightning = sinon.stub(lightningOperations);259 fakeChannels = sinon.stub(channelsOperations);260 window.ipcClient.resetHistory();261 window.ipcRenderer.send.resetHistory();262 data = {263 streamBuilder: {264 insert: sinon.stub(),265 values: sinon.stub(),266 update: sinon.stub(),267 set: sinon.stub(),268 where: sinon.stub(),269 execute: sinon.stub(),270 getMany: sinon.stub(),271 },272 streamPartBuilder: {273 insert: sinon.stub(),274 values: sinon.stub(),275 execute: sinon.stub(),276 },277 };278 initState = JSON.parse(JSON.stringify(persistedState));279 initState.account.kernelConnectIndicator = accountTypes.KERNEL_CONNECTED;280 store = configureStore(initState);281 expectedData = undefined;282 expectedActions = [];283 });284 afterEach(() => {285 sinon.restore();286 });287 describe("Modal windows", () => {288 beforeEach(() => {289 expectedData = { type: appTypes.SET_MODAL_STATE };290 });291 it("openStreamPaymentDetailsModal()", async () => {292 expectedData.payload = types.MODAL_STATE_STREAM_PAYMENT_DETAILS;293 expectedActions = [expectedData];294 expect(await store.dispatch(operations.openStreamPaymentDetailsModal())).to.deep.equal(expectedData);295 expect(store.getState().listActions).to.deep.equal(expectedActions);296 });297 it("openActiveRecurringWarningModal()", async () => {298 expectedData.payload = types.MODAL_STATE_ACTIVE_RECURRING_WARNING;299 expectedActions = [expectedData];300 expect(await store.dispatch(operations.openActiveRecurringWarningModal())).to.deep.equal(expectedData);301 expect(store.getState().listActions).to.deep.equal(expectedActions);302 });303 it("openEditStreamModal()", async () => {304 expectedData.payload = types.MODAL_STATE_EDIT_STREAM_PAYMENT;305 expectedActions = [expectedData];306 expect(await store.dispatch(operations.openEditStreamModal())).to.deep.equal(expectedData);307 expect(store.getState().listActions).to.deep.equal(expectedActions);308 });309 });310 it("clearPrepareStreamPayment()", async () => {311 expectedActions = [312 {313 payload: null,314 type: types.PREPARE_STREAM_PAYMENT,315 },316 ];317 expect(await store.dispatch(operations.clearPrepareStreamPayment())).to.deep.equal(expectedData);318 expect(store.getState().listActions).to.deep.equal(expectedActions);319 });320 describe("prepareStreamPayment()", () => {321 let successRespTest;322 beforeEach(async () => {323 data.lightningID = lightningID;324 data.price = 10;325 data.delay = 1000;326 data.totalParts = 10;327 data.paymentName = "foo";328 data.contact_name = "bar";329 data.currency = "USD";330 successRespTest = await successPromise({ fee: "fee" });331 fakeDispatchReturnSuccess = () => successRespTest;332 fakeLightning.getLightningFee.returns(fakeDispatchReturnSuccess);333 });334 it("kernel disconnected", async () => {335 initState.account.kernelConnectIndicator = accountTypes.KERNEL_DISCONNECTED;336 store = configureStore(initState);337 expectedData = {338 ...errorResp,339 error: exceptions.ACCOUNT_NO_KERNEL,340 f: "prepareStreamPayment",341 };342 expect(await store.dispatch(operations.prepareStreamPayment(343 data.lightningID,344 data.price,345 ))).to.deep.equal(expectedData);346 expect(store.getState().listActions).to.deep.equal(expectedActions);347 expect(fakeLightning.getLightningFee).not.to.be.called;348 });349 it("error getLightningFee()", async () => {350 fakeLightning.getLightningFee.returns(fakeDispatchReturnError);351 expectedData = {352 ...errorResp,353 f: "prepareStreamPayment",354 };355 expect(await store.dispatch(operations.prepareStreamPayment(356 data.lightningID,357 data.price,358 ))).to.deep.equal(expectedData);359 expect(store.getState().listActions).to.deep.equal(expectedActions);360 expect(fakeLightning.getLightningFee).to.be.calledOnce;361 });362 it("success with BTC currency", async () => {363 expectedData = { ...successResp };364 expectedActions = [365 {366 payload: {367 contact_name: "",368 currency: "BTC",369 delay: 1000,370 fee: "fee",371 lastPayment: 0,372 lightningID: data.lightningID,373 name: "Recurring payment",374 partsPaid: 0,375 partsPending: 0,376 price: 10,377 status: types.STREAM_PAYMENT_PAUSED,378 totalAmount: 0,379 totalParts: STREAM_INFINITE_TIME_VALUE,380 },381 type: types.PREPARE_STREAM_PAYMENT,382 },383 ];384 expect(await store.dispatch(operations.prepareStreamPayment(385 data.lightningID,386 data.price,387 ))).to.deep.equal(expectedData);388 ({ listActions } = store.getState());389 listActions[0].payload = omit(listActions[0].payload, ["date", "memo", "id"]);390 expect(listActions).to.deep.equal(expectedActions);391 expect(fakeLightning.getLightningFee).to.be.calledOnce;392 });393 it("success with USD currency", async () => {394 fakeApp.convertUsdToSatoshi.returns(fakeDispatchReturnSuccess);395 expectedData = { ...successResp };396 expectedActions = [397 {398 payload: {399 contact_name: "bar",400 currency: "USD",401 delay: 1000,402 fee: "fee",403 lastPayment: 0,404 lightningID: data.lightningID,405 name: "foo",406 partsPaid: 0,407 partsPending: 0,408 price: 10,409 status: types.STREAM_PAYMENT_PAUSED,410 totalAmount: 0,411 totalParts: 10,412 },413 type: types.PREPARE_STREAM_PAYMENT,414 },415 ];416 expect(await store.dispatch(operations.prepareStreamPayment(417 data.lightningID,418 data.price,419 data.delay,420 data.totalParts,421 data.paymentName,422 data.contact_name,423 data.currency,424 ))).to.deep.equal(expectedData);425 ({ listActions } = store.getState());426 listActions[0].payload = omit(listActions[0].payload, ["date", "memo", "id"]);427 expect(listActions).to.deep.equal(expectedActions);428 expect(fakeLightning.getLightningFee).to.be.calledOnce;429 });430 });431 describe("updateStreamPayment()", () => {432 let successRespTest;433 beforeEach(async () => {434 data.streamId = "bar";435 data.lightningID = lightningID;436 data.status = types.STREAM_PAYMENT_FINISHED;437 data.price = 10;438 data.delay = 1000;439 data.totalParts = 10;440 data.paymentName = "foo";441 data.currency = "BTC";442 successRespTest = await successPromise({ fee: "fee" });443 fakeDispatchReturnSuccess = () => successRespTest;444 fakeLightning.getLightningFee.returns(fakeDispatchReturnSuccess);445 fakeDB.streamBuilder.returns({446 update: data.streamBuilder.update.returns({447 set: data.streamBuilder.set.returns({448 where: data.streamBuilder.where.returns({449 execute: data.streamBuilder.execute,450 }),451 }),452 }),453 });454 });455 it("kernel disconnected", async () => {456 initState.account.kernelConnectIndicator = accountTypes.KERNEL_DISCONNECTED;457 store = configureStore(initState);458 expectedData = {459 ...errorResp,460 error: exceptions.ACCOUNT_NO_KERNEL,461 f: "updateStreamPayment",462 };463 expect(await store.dispatch(operations.updateStreamPayment(464 data.streamId,465 data.lightningID,466 data.status,467 data.price,468 data.delay,469 data.totalParts,470 data.paymentName,471 data.currency,472 ))).to.deep.equal(expectedData);473 expect(store.getState().listActions).to.deep.equal(expectedActions);474 expect(fakeLightning.getLightningFee).not.to.be.called;475 expect(fakeDB.streamBuilder).not.to.be.called;476 });477 it("active stream not in store", async () => {478 data.status = types.STREAM_PAYMENT_PAUSED;479 initState.streamPayment.streams = [{ id: "foo" }];480 store = configureStore(initState);481 expectedData = {482 ...errorResp,483 error: exceptions.RECURRING_NOT_IN_STORE,484 f: "updateStreamPayment",485 };486 expect(await store.dispatch(operations.updateStreamPayment(487 data.streamId,488 data.lightningID,489 data.status,490 data.price,491 data.delay,492 data.totalParts,493 data.paymentName,494 data.currency,495 ))).to.deep.equal(expectedData);496 expect(store.getState().listActions).to.deep.equal(expectedActions);497 expect(fakeLightning.getLightningFee).not.to.be.called;498 expect(fakeDB.streamBuilder).not.to.be.called;499 });500 it("error getLightningFee()", async () => {501 fakeLightning.getLightningFee.returns(fakeDispatchReturnError);502 expectedData = {503 ...errorResp,504 f: "updateStreamPayment",505 };506 expect(await store.dispatch(operations.updateStreamPayment(507 data.streamId,508 data.lightningID,509 data.status,510 data.price,511 data.delay,512 data.totalParts,513 data.paymentName,514 data.currency,515 ))).to.deep.equal(expectedData);516 expect(store.getState().listActions).to.deep.equal(expectedActions);517 expect(fakeDB.streamBuilder).not.to.be.called;518 expect(fakeLightning.getLightningFee).to.be.calledOnce;519 });520 it("success with BTC currency", async () => {521 expectedData = { ...successResp };522 expectedActions = [523 {524 payload: {525 streamId: data.streamId,526 details: {527 currency: data.currency,528 delay: data.delay,529 name: data.paymentName,530 price: data.price,531 totalParts: data.totalParts,532 },533 },534 type: types.UPDATE_STREAM_PAYMENT,535 },536 ];537 expect(await store.dispatch(operations.updateStreamPayment(538 data.streamId,539 data.lightningID,540 data.status,541 data.price,542 data.delay,543 data.totalParts,544 data.paymentName,545 data.currency,546 ))).to.deep.equal(expectedData);547 expect(store.getState().listActions).to.deep.equal(expectedActions);548 expect(fakeLightning.getLightningFee).to.be.calledOnce;549 expect(fakeDB.streamBuilder).to.be.calledOnce;550 expect(data.streamBuilder.update).to.be.calledOnce;551 expect(data.streamBuilder.update).to.be.calledImmediatelyAfter(fakeDB.streamBuilder);552 expect(data.streamBuilder.set).to.be.calledOnce;553 expect(data.streamBuilder.set).to.be.calledImmediatelyAfter(data.streamBuilder.update);554 expect(data.streamBuilder.set)555 .to.be.calledWithExactly({556 currency: data.currency,557 delay: data.delay,558 name: data.paymentName,559 price: data.price,560 totalParts: data.totalParts,561 });562 expect(data.streamBuilder.where).to.be.calledOnce;563 expect(data.streamBuilder.where).to.be.calledImmediatelyAfter(data.streamBuilder.set);564 expect(data.streamBuilder.where).to.be.calledWithExactly("id = :id", { id: "bar" });565 expect(data.streamBuilder.execute).to.be.calledOnce;566 expect(data.streamBuilder.execute).to.be.calledImmediatelyAfter(data.streamBuilder.where);567 });568 it("success with USD currency", async () => {569 data.currency = "USD";570 fakeApp.convertUsdToSatoshi.returns(fakeDispatchReturnSuccess);571 expectedData = { ...successResp };572 expectedActions = [573 {574 payload: {575 streamId: data.streamId,576 details: {577 currency: data.currency,578 delay: data.delay,579 name: data.paymentName,580 price: data.price,581 totalParts: data.totalParts,582 },583 },584 type: types.UPDATE_STREAM_PAYMENT,585 },586 ];587 expect(await store.dispatch(operations.updateStreamPayment(588 data.streamId,589 data.lightningID,590 data.status,591 data.price,592 data.delay,593 data.totalParts,594 data.paymentName,595 data.currency,596 ))).to.deep.equal(expectedData);597 expect(store.getState().listActions).to.deep.equal(expectedActions);598 expect(store.getState().listActions).to.deep.equal(expectedActions);599 expect(fakeLightning.getLightningFee).to.be.calledOnce;600 expect(fakeDB.streamBuilder).to.be.calledOnce;601 expect(data.streamBuilder.update).to.be.calledOnce;602 expect(data.streamBuilder.update).to.be.calledImmediatelyAfter(fakeDB.streamBuilder);603 expect(data.streamBuilder.set).to.be.calledOnce;604 expect(data.streamBuilder.set).to.be.calledImmediatelyAfter(data.streamBuilder.update);605 expect(data.streamBuilder.set)606 .to.be.calledWithExactly({607 currency: data.currency,608 delay: data.delay,609 name: data.paymentName,610 price: data.price,611 totalParts: data.totalParts,612 });613 expect(data.streamBuilder.where).to.be.calledOnce;614 expect(data.streamBuilder.where).to.be.calledImmediatelyAfter(data.streamBuilder.set);615 expect(data.streamBuilder.where).to.be.calledWithExactly("id = :id", { id: "bar" });616 expect(data.streamBuilder.execute).to.be.calledOnce;617 expect(data.streamBuilder.execute).to.be.calledImmediatelyAfter(data.streamBuilder.where);618 });619 });620 describe("pauseDbStreams()", () => {621 beforeEach(() => {622 data.streamId = "foo";623 fakeDB.streamBuilder.returns({624 update: data.streamBuilder.update.returns({625 set: data.streamBuilder.set.returns({626 where: data.streamBuilder.where.returns({627 execute: data.streamBuilder.execute,628 }),629 }),630 }),631 });632 });633 it("db error", async () => {634 fakeDB.streamBuilder.throws(new Error("foo"));635 expect(await operations.pauseDbStreams()).to.deep.equal(expectedData);636 expect(store.getState().listActions).to.deep.equal(expectedActions);637 expect(fakeDB.streamBuilder).to.be.calledOnce;638 expect(data.streamBuilder.update).not.to.be.called;639 });640 it("success", async () => {641 expect(await operations.pauseDbStreams()).to.deep.equal(expectedData);642 expect(store.getState().listActions).to.deep.equal(expectedActions);643 expect(window.ipcRenderer.send).not.to.be.called;644 expect(fakeDB.streamBuilder).to.be.calledOnce;645 expect(data.streamBuilder.update).to.be.calledOnce;646 expect(data.streamBuilder.update).to.be.calledImmediatelyAfter(fakeDB.streamBuilder);647 expect(data.streamBuilder.set).to.be.calledOnce;648 expect(data.streamBuilder.set).to.be.calledImmediatelyAfter(data.streamBuilder.update);649 expect(data.streamBuilder.set)650 .to.be.calledWithExactly({ status: types.STREAM_PAYMENT_PAUSED });651 expect(data.streamBuilder.where).to.be.calledOnce;652 expect(data.streamBuilder.where).to.be.calledImmediatelyAfter(data.streamBuilder.set);653 expect(data.streamBuilder.where).to.be.calledWithExactly("status = :status", {654 status: types.STREAM_PAYMENT_STREAMING,655 });656 expect(data.streamBuilder.execute).to.be.calledOnce;657 expect(data.streamBuilder.execute).to.be.calledImmediatelyAfter(data.streamBuilder.where);658 });659 });660 describe("pauseStreamPayment()", () => {661 beforeEach(() => {662 data.streamId = "foo";663 fakeDB.streamBuilder.returns({664 update: data.streamBuilder.update.returns({665 set: data.streamBuilder.set.returns({666 where: data.streamBuilder.where.returns({667 execute: data.streamBuilder.execute,668 }),669 }),670 }),671 });672 });673 it("empty streams list", async () => {674 expect(await store.dispatch(operations.pauseStreamPayment(data.streamId))).to.deep.equal(expectedData);675 expect(store.getState().listActions).to.deep.equal(expectedActions);676 expect(window.ipcRenderer.send).not.to.be.called;677 expect(fakeDB.streamBuilder).not.to.be.called;678 });679 it("success", async () => {680 initState.streamPayment.streams = [681 {682 id: "foo",683 partsPaid: 0,684 status: types.STREAM_PAYMENT_STREAMING,685 },686 {687 id: "bar",688 partsPaid: 0,689 status: types.STREAM_PAYMENT_STREAMING,690 },691 ];692 store = configureStore(initState);693 expectedActions = [694 {695 payload: {696 details: {697 status: types.STREAM_PAYMENT_PAUSED,698 },699 streamId: "foo",700 },701 type: types.UPDATE_STREAM_PAYMENT,702 },703 ];704 expect(await store.dispatch(operations.pauseStreamPayment(data.streamId))).to.deep.equal(expectedData);705 expect(store.getState().listActions).to.deep.equal(expectedActions);706 expect(window.ipcRenderer.send).not.to.be.called;707 expect(fakeDB.streamBuilder).to.be.calledOnce;708 expect(data.streamBuilder.update).to.be.calledOnce;709 expect(data.streamBuilder.update).to.be.calledImmediatelyAfter(fakeDB.streamBuilder);710 expect(data.streamBuilder.set).to.be.calledOnce;711 expect(data.streamBuilder.set).to.be.calledImmediatelyAfter(data.streamBuilder.update);712 expect(data.streamBuilder.set)713 .to.be.calledWithExactly({ partsPaid: 0, status: types.STREAM_PAYMENT_PAUSED });714 expect(data.streamBuilder.where).to.be.calledOnce;715 expect(data.streamBuilder.where).to.be.calledImmediatelyAfter(data.streamBuilder.set);716 expect(data.streamBuilder.where).to.be.calledWithExactly("id = :id", { id: "foo" });717 expect(data.streamBuilder.execute).to.be.calledOnce;718 expect(data.streamBuilder.execute).to.be.calledImmediatelyAfter(data.streamBuilder.where);719 });720 });721 describe("pauseAllStreams()", () => {722 beforeEach(() => {723 data.streamId = "foo";724 fakeDB.streamBuilder.returns({725 update: data.streamBuilder.update.returns({726 set: data.streamBuilder.set.returns({727 where: data.streamBuilder.where.returns({728 execute: data.streamBuilder.execute,729 }),730 }),731 }),732 });733 });734 it("empty streams list", async () => {735 expect(await store.dispatch(operations.pauseAllStreams(data.streamId))).to.deep.equal(expectedData);736 expect(store.getState().listActions).to.deep.equal(expectedActions);737 expect(window.ipcRenderer.send).not.to.be.called;738 expect(fakeDB.streamBuilder).not.to.be.called;739 });740 it("success", async () => {741 initState.streamPayment.streams = [742 {743 id: "foo",744 partsPaid: 0,745 status: types.STREAM_PAYMENT_STREAMING,746 },747 {748 id: "bar",749 partsPaid: 0,750 status: types.STREAM_PAYMENT_PAUSED,751 },752 ];753 store = configureStore(initState);754 expectedActions = [755 {756 payload: {757 details: {758 status: types.STREAM_PAYMENT_PAUSED,759 },760 streamId: "foo",761 },762 type: types.UPDATE_STREAM_PAYMENT,763 },764 ];765 expect(await store.dispatch(operations.pauseAllStreams(data.streamId))).to.deep.equal(expectedData);766 expect(store.getState().listActions).to.deep.equal(expectedActions);767 expect(window.ipcRenderer.send).not.to.be.called;768 expect(fakeDB.streamBuilder).to.be.calledOnce;769 expect(data.streamBuilder.update).to.be.calledOnce;770 expect(data.streamBuilder.update).to.be.calledImmediatelyAfter(fakeDB.streamBuilder);771 expect(data.streamBuilder.set).to.be.calledOnce;772 expect(data.streamBuilder.set).to.be.calledImmediatelyAfter(data.streamBuilder.update);773 expect(data.streamBuilder.set)774 .to.be.calledWithExactly({ partsPaid: 0, status: types.STREAM_PAYMENT_PAUSED });775 expect(data.streamBuilder.where).to.be.calledOnce;776 expect(data.streamBuilder.where).to.be.calledImmediatelyAfter(data.streamBuilder.set);777 expect(data.streamBuilder.where).to.be.calledWithExactly("id = :id", { id: "foo" });778 expect(data.streamBuilder.execute).to.be.calledOnce;779 expect(data.streamBuilder.execute).to.be.calledImmediatelyAfter(data.streamBuilder.where);780 });781 });782 it("loadStreams(): ", async () => {783 const streams = [784 {785 date: 1,786 status: types.STREAM_PAYMENT_FINISHED,787 lightningID: "foo",788 id: 1,789 extra: "buz",790 },791 {792 date: 2,793 status: types.STREAM_PAYMENT_STREAMING,794 lightningID: "bar",795 id: 2,796 totalParts: 1,797 partsPending: 0,798 partsPaid: 1,799 lastPayment: 0,800 },801 {802 date: 3,803 status: types.STREAM_PAYMENT_PAUSED,804 lightningID: "baz",805 id: 3,806 },807 ];808 initState.streamPayment.streams = streams;809 store = configureStore(initState);810 fakeDB.streamBuilder.returns({811 getMany: data.streamBuilder.getMany.returns(streams),812 });813 expectedData = { ...successResp };814 expectedActions = [815 {816 payload: [817 {818 contact_name: "",819 date: 3,820 id: 3,821 lightningID: "baz",822 partsPending: 0,823 status: types.STREAM_PAYMENT_PAUSED,824 },825 {826 contact_name: "",827 date: 2,828 id: 2,829 lastPayment: 0,830 lightningID: "bar",831 partsPaid: 1,832 partsPending: 0,833 status: types.STREAM_PAYMENT_STREAMING,834 totalParts: 1,835 },836 ],837 type: types.SET_STREAM_PAYMENTS,838 },839 ];840 expect(await store.dispatch(operations.loadStreams())).to.deep.equal(expectedData);841 expect(store.getState().listActions).to.deep.equal(expectedActions);842 expect(window.ipcRenderer.send).not.to.be.called;843 expect(fakeDB.streamBuilder).to.be.calledOnce;844 expect(data.streamBuilder.getMany).to.be.calledOnce;845 expect(data.streamBuilder.getMany).to.be.calledImmediatelyAfter(fakeDB.streamBuilder);846 });847 describe("addStreamPaymentToList()", () => {848 beforeEach(() => {849 fakeDB.streamBuilder.returns({850 insert: data.streamBuilder.insert.returns({851 values: data.streamBuilder.values.returns({852 execute: data.streamBuilder.execute.returns(),853 }),854 }),855 });856 });857 it("no stream details", async () => {858 expectedData = {859 ...errorResp,860 error: exceptions.RECURRING_DETAILS_REQUIRED,861 f: "addStreamPaymentToList",862 };863 expect(await store.dispatch(operations.addStreamPaymentToList())).to.deep.equal(expectedData);864 expect(store.getState().listActions).to.deep.equal(expectedActions);865 expect(window.ipcRenderer.send).not.to.be.called;866 expect(fakeDB.streamBuilder).not.to.be.called;867 });868 it("success", async () => {869 const details = {};870 initState.streamPayment.streamDetails = details;871 store = configureStore(initState);872 expectedData = { ...successResp };873 expectedActions = [874 {875 type: types.ADD_STREAM_PAYMENT_TO_LIST,876 },877 ];878 expect(await store.dispatch(operations.addStreamPaymentToList())).to.deep.equal(expectedData);879 expect(store.getState().listActions).to.deep.equal(expectedActions);880 expect(window.ipcRenderer.send).not.to.be.called;881 expect(fakeDB.streamBuilder).to.be.calledOnce;882 expect(data.streamBuilder.insert).to.be.calledOnce;883 expect(data.streamBuilder.insert).to.be.calledImmediatelyAfter(fakeDB.streamBuilder);884 expect(data.streamBuilder.values).to.be.calledOnce;885 expect(data.streamBuilder.values).to.be.calledImmediatelyAfter(data.streamBuilder.insert);886 expect(data.streamBuilder.execute).to.be.calledOnce;887 expect(data.streamBuilder.execute).to.be.calledImmediatelyAfter(data.streamBuilder.values);888 });889 });890 describe("finishStreamPayment()", () => {891 beforeEach(() => {892 fakeDB.streamBuilder.returns({893 update: data.streamBuilder.update.returns({894 set: data.streamBuilder.set.returns({895 where: data.streamBuilder.where.returns({896 execute: data.streamBuilder.execute,897 }),898 }),899 }),900 });901 });902 it("no payment", async () => {903 expect(await store.dispatch(operations.finishStreamPayment(0))).to.deep.equal(expectedData);904 expect(store.getState().listActions).to.deep.equal(expectedActions);905 expect(window.ipcRenderer.send).not.to.be.called;906 });907 it("success", async () => {908 const streams = [909 {910 date: 1,911 status: types.STREAM_PAYMENT_PAUSED,912 lightningID: "foo",913 id: "baz",914 partsPaid: 1,915 },916 ];917 initState.streamPayment.streams = streams;918 store = configureStore(initState);919 expectedActions = [920 {921 payload: {922 details: {923 status: types.STREAM_PAYMENT_FINISHED,924 },925 streamId: "baz",926 },927 type: types.UPDATE_STREAM_PAYMENT,928 },929 ];930 expect(await store.dispatch(operations.finishStreamPayment("baz"))).to.deep.equal(expectedData);931 expect(store.getState().listActions).to.deep.equal(expectedActions);932 expect(window.ipcRenderer.send).not.to.be.called;933 expect(fakeDB.streamBuilder).to.be.calledOnce;934 expect(data.streamBuilder.update).to.be.calledOnce;935 expect(data.streamBuilder.update).to.be.calledImmediatelyAfter(fakeDB.streamBuilder);936 expect(data.streamBuilder.set).to.be.calledOnce;937 expect(data.streamBuilder.set).to.be.calledImmediatelyAfter(data.streamBuilder.update);938 expect(data.streamBuilder.set).to.be.calledWithExactly({939 partsPaid: 1,940 status: types.STREAM_PAYMENT_FINISHED,941 });942 expect(data.streamBuilder.where).to.be.calledOnce;943 expect(data.streamBuilder.where).to.be.calledImmediatelyAfter(data.streamBuilder.set);944 expect(data.streamBuilder.where).to.be.calledWithExactly("id = :id", { id: "baz" });945 expect(data.streamBuilder.execute).to.be.calledOnce;946 expect(data.streamBuilder.execute).to.be.calledImmediatelyAfter(data.streamBuilder.where);947 });948 });949 describe("startStreamPayment()", () => {950 let successRespTest;951 let errorRespTest;952 beforeEach(async () => {953 errorRespTest = await errorPromise("error", { name: "something" });954 fakeDispatchReturnError = () => errorRespTest;955 fakeLightning.addInvoiceRemote.returns(fakeDispatchReturnError);956 fakeAccount.checkBalance.returns(fakeDispatchReturnSuccess);957 fakeChannels.getChannels.returns(fakeDispatchReturnSuccess);958 fakeApp.convertUsdToSatoshi.returns(fakeDispatchReturnSuccess);959 window.ipcClient960 .withArgs("sendPayment")961 .returns({962 ok: false,963 });964 fakeDB.streamBuilder.returns({965 update: data.streamBuilder.update.returns({966 set: data.streamBuilder.set.returns({967 where: data.streamBuilder.where.returns({968 execute: data.streamBuilder.execute,969 }),970 }),971 }),972 });973 fakeDB.streamPartBuilder.returns({974 insert: data.streamPartBuilder.insert.returns({975 values: data.streamPartBuilder.values.returns({976 execute: data.streamPartBuilder.execute,977 }),978 }),979 });980 initState.account.isLogined = true;981 initState.account.lightningBalance = Number.MAX_SAFE_INTEGER;982 store = configureStore(initState);983 });984 it("no payment", async () => {985 expect(await store.dispatch(operations.startStreamPayment("foo"))).to.deep.equal(expectedData);986 expect(store.getState().listActions).to.deep.equal(expectedActions);987 expect(window.ipcClient).not.to.be.called;988 expect(fakeDB.streamBuilder).not.to.be.called;989 });990 it("error insufficient funds on lightning balance", async () => {991 const streams = [992 {993 partsPaid: 1,994 partsPending: 0,995 delay: 100,996 lastPayment: Date.now() - 50,997 totalParts: 2,998 id: "foo",999 price: 100,1000 status: types.STREAM_PAYMENT_PAUSED,1001 currency: "BTC",1002 },1003 ];1004 initState.streamPayment.streams = streams;1005 initState.account.lightningBalance = 50;1006 store = configureStore(initState);1007 expectedActions = [1008 {1009 payload: {1010 details: {1011 status: types.STREAM_PAYMENT_STREAMING,1012 },1013 streamId: "foo",1014 },1015 type: types.UPDATE_STREAM_PAYMENT,1016 },1017 {1018 payload: {1019 details: {1020 status: types.STREAM_PAYMENT_PAUSED,1021 },1022 streamId: "foo",1023 },1024 type: types.UPDATE_STREAM_PAYMENT,1025 },1026 {1027 type: notificationsTypes.SHOW_NOTIFICATION,1028 },1029 ];1030 expect(await store.dispatch(operations.startStreamPayment("foo"))).to.deep.equal(expectedData);1031 await delay(100);1032 ({ listActions } = store.getState());1033 listActions[2] = omit(listActions[2], "payload");1034 expect(listActions).to.deep.equal(expectedActions);1035 expect(window.ipcRenderer.send).not.to.be.called;1036 expect(fakeDB.streamBuilder).to.be.calledTwice;1037 expect(data.streamBuilder.update).to.be.calledTwice;1038 expect(data.streamBuilder.update).to.be.calledImmediatelyAfter(fakeDB.streamBuilder);1039 expect(data.streamBuilder.set).to.be.calledTwice;1040 expect(data.streamBuilder.set).to.be.calledImmediatelyAfter(data.streamBuilder.update);1041 expect(data.streamBuilder.set).to.be.calledWithExactly({1042 partsPaid: 1,1043 status: types.STREAM_PAYMENT_STREAMING,1044 });1045 expect(data.streamBuilder.set).to.be.calledWithExactly({1046 partsPaid: 1,1047 status: types.STREAM_PAYMENT_PAUSED,1048 });1049 expect(data.streamBuilder.where).to.be.calledTwice;1050 expect(data.streamBuilder.where).to.be.calledImmediatelyAfter(data.streamBuilder.set);1051 expect(data.streamBuilder.where).to.be.calledWithExactly("id = :id", { id: "foo" });1052 expect(data.streamBuilder.execute).to.be.calledTwice;1053 expect(data.streamBuilder.execute).to.be.calledImmediatelyAfter(data.streamBuilder.where);1054 expect(fakeDB.streamPartBuilder).not.to.be.called;1055 });1056 it("error on get invoice from lis", async () => {1057 const streams = [1058 {1059 partsPaid: 1,1060 partsPending: 0,1061 delay: 100,1062 lastPayment: Date.now() - 50,1063 totalParts: 2,1064 id: "foo",1065 price: 100,1066 status: types.STREAM_PAYMENT_PAUSED,1067 currency: "BTC",1068 },1069 ];1070 initState.streamPayment.streams = streams;1071 store = configureStore(initState);1072 expectedActions = [1073 {1074 payload: {1075 details: {1076 status: types.STREAM_PAYMENT_STREAMING,1077 },1078 streamId: "foo",1079 },1080 type: types.UPDATE_STREAM_PAYMENT,1081 },1082 {1083 payload: {1084 change: 1,1085 streamId: "foo",1086 },1087 type: types.CHANGE_STREAM_PARTS_PENDING,1088 },1089 {1090 payload: {1091 change: -1,1092 streamId: "foo",1093 },1094 type: types.CHANGE_STREAM_PARTS_PENDING,1095 },1096 {1097 payload: {1098 details: {1099 status: types.STREAM_PAYMENT_PAUSED,1100 },1101 streamId: "foo",1102 },1103 type: types.UPDATE_STREAM_PAYMENT,1104 },1105 {1106 type: notificationsTypes.SHOW_NOTIFICATION,1107 },1108 ];1109 expect(await store.dispatch(operations.startStreamPayment("foo"))).to.deep.equal(expectedData);1110 await delay(100);1111 ({ listActions } = store.getState());1112 listActions[4] = omit(listActions[4], "payload");1113 expect(listActions).to.deep.equal(expectedActions);1114 expect(window.ipcRenderer.send).not.to.be.called;1115 expect(fakeDB.streamBuilder).to.be.calledTwice;1116 expect(data.streamBuilder.update).to.be.calledTwice;1117 expect(data.streamBuilder.update).to.be.calledImmediatelyAfter(fakeDB.streamBuilder);1118 expect(data.streamBuilder.set).to.be.calledTwice;1119 expect(data.streamBuilder.set).to.be.calledImmediatelyAfter(data.streamBuilder.update);1120 expect(data.streamBuilder.set).to.be.calledWithExactly({1121 partsPaid: 1,1122 status: types.STREAM_PAYMENT_STREAMING,1123 });1124 expect(data.streamBuilder.set).to.be.calledWithExactly({1125 partsPaid: 1,1126 status: types.STREAM_PAYMENT_PAUSED,1127 });1128 expect(data.streamBuilder.where).to.be.calledTwice;1129 expect(data.streamBuilder.where).to.be.calledImmediatelyAfter(data.streamBuilder.set);1130 expect(data.streamBuilder.where).to.be.calledWithExactly("id = :id", { id: "foo" });1131 expect(data.streamBuilder.execute).to.be.calledTwice;1132 expect(data.streamBuilder.execute).to.be.calledImmediatelyAfter(data.streamBuilder.where);1133 expect(fakeDB.streamPartBuilder).not.to.be.called;1134 });1135 it("error on sendPayment", async () => {1136 successRespTest = await successPromise({1137 response: {1138 payment_request: "foo",1139 },1140 });1141 fakeDispatchReturnSuccess = () => successRespTest;1142 fakeLightning.addInvoiceRemote.returns(fakeDispatchReturnSuccess);1143 const streams = [1144 {1145 partsPaid: 1,1146 partsPending: 0,1147 delay: 100,1148 lastPayment: Date.now() - 50,1149 totalParts: 2,1150 id: "foo",1151 price: 100,1152 status: types.STREAM_PAYMENT_PAUSED,1153 currency: "BTC",1154 },1155 ];1156 initState.streamPayment.streams = streams;1157 store = configureStore(initState);1158 expectedActions = [1159 {1160 payload: {1161 details: {1162 status: types.STREAM_PAYMENT_STREAMING,1163 },1164 streamId: "foo",1165 },1166 type: types.UPDATE_STREAM_PAYMENT,1167 },1168 {1169 payload: {1170 change: 1,1171 streamId: "foo",1172 },1173 type: types.CHANGE_STREAM_PARTS_PENDING,1174 },1175 {1176 payload: {1177 change: -1,1178 streamId: "foo",1179 },1180 type: types.CHANGE_STREAM_PARTS_PENDING,1181 },1182 {1183 payload: {1184 details: {1185 status: types.STREAM_PAYMENT_PAUSED,1186 },1187 streamId: "foo",1188 },1189 type: types.UPDATE_STREAM_PAYMENT,1190 },1191 {1192 type: notificationsTypes.SHOW_NOTIFICATION,1193 },1194 ];1195 expect(await store.dispatch(operations.startStreamPayment("foo"))).to.deep.equal(expectedData);1196 await delay(100);1197 ({ listActions } = store.getState());1198 listActions[4] = omit(listActions[4], "payload");1199 expect(listActions).to.deep.equal(expectedActions);1200 expect(window.ipcRenderer.send).not.to.be.called;1201 expect(fakeDB.streamBuilder).to.be.calledTwice;1202 expect(data.streamBuilder.update).to.be.calledTwice;1203 expect(data.streamBuilder.update).to.be.calledImmediatelyAfter(fakeDB.streamBuilder);1204 expect(data.streamBuilder.set).to.be.calledTwice;1205 expect(data.streamBuilder.set).to.be.calledImmediatelyAfter(data.streamBuilder.update);1206 expect(data.streamBuilder.set).to.be.calledWithExactly({1207 partsPaid: 1,1208 status: types.STREAM_PAYMENT_STREAMING,1209 });1210 expect(data.streamBuilder.set).to.be.calledWithExactly({1211 partsPaid: 1,1212 status: types.STREAM_PAYMENT_PAUSED,1213 });1214 expect(data.streamBuilder.where).to.be.calledTwice;1215 expect(data.streamBuilder.where).to.be.calledImmediatelyAfter(data.streamBuilder.set);1216 expect(data.streamBuilder.where).to.be.calledWithExactly("id = :id", { id: "foo" });1217 expect(data.streamBuilder.execute).to.be.calledTwice;1218 expect(data.streamBuilder.execute).to.be.calledImmediatelyAfter(data.streamBuilder.where);1219 expect(fakeDB.streamPartBuilder).not.to.be.called;1220 });1221 it("success with last payment close than delay, 2 payments left, interval started", async () => {1222 successRespTest = await successPromise({1223 response: {1224 payment_request: "foo",1225 },1226 });1227 fakeDispatchReturnSuccess = () => successRespTest;1228 fakeLightning.addInvoiceRemote.returns(fakeDispatchReturnSuccess);1229 window.ipcClient1230 .withArgs("sendPayment")1231 .returns({1232 ok: true,1233 });1234 const streams = [1235 {1236 partsPaid: 1,1237 partsPending: 0,1238 delay: 100,1239 lastPayment: Date.now() - 10,1240 totalParts: 3,1241 id: "foo",1242 price: 100,1243 status: types.STREAM_PAYMENT_PAUSED,1244 currency: "BTC",1245 totalAmount: 0,1246 },1247 ];1248 initState.streamPayment.streams = streams;1249 store = configureStore(initState);1250 expectedActions = [1251 {1252 payload: {1253 details: {1254 status: types.STREAM_PAYMENT_STREAMING,1255 },1256 streamId: "foo",1257 },1258 type: types.UPDATE_STREAM_PAYMENT,1259 },1260 {1261 payload: {1262 change: 1,1263 streamId: "foo",1264 },1265 type: types.CHANGE_STREAM_PARTS_PENDING,1266 },1267 {1268 payload: {1269 change: -1,1270 streamId: "foo",1271 },1272 type: types.CHANGE_STREAM_PARTS_PENDING,1273 },1274 {1275 payload: {1276 change: 1,1277 streamId: "foo",1278 },1279 type: types.CHANGE_STREAM_PARTS_PAID,1280 },1281 {1282 payload: {1283 details: {1284 partsPaid: 2,1285 totalAmount: 100,1286 },1287 streamId: "foo",1288 },1289 type: types.UPDATE_STREAM_PAYMENT,1290 },1291 {1292 payload: {1293 change: 1,1294 streamId: "foo",1295 },1296 type: types.CHANGE_STREAM_PARTS_PENDING,1297 },1298 {1299 payload: {1300 change: -1,1301 streamId: "foo",1302 },1303 type: types.CHANGE_STREAM_PARTS_PENDING,1304 },1305 {1306 payload: {1307 change: 1,1308 streamId: "foo",1309 },1310 type: types.CHANGE_STREAM_PARTS_PAID,1311 },1312 {1313 payload: {1314 details: {1315 partsPaid: 3,1316 totalAmount: 200,1317 },1318 streamId: "foo",1319 },1320 type: types.UPDATE_STREAM_PAYMENT,1321 },1322 {1323 payload: {1324 details: {1325 status: types.STREAM_PAYMENT_FINISHED,1326 },1327 streamId: "foo",1328 },1329 type: types.UPDATE_STREAM_PAYMENT,1330 },1331 {1332 type: notificationsTypes.SHOW_NOTIFICATION,1333 },1334 ];1335 expect(await store.dispatch(operations.startStreamPayment("foo"))).to.deep.equal(expectedData);1336 await delay(200);1337 ({ listActions } = store.getState());1338 listActions[4].payload.details = omit(listActions[4].payload.details, "lastPayment");1339 listActions[8].payload.details = omit(listActions[8].payload.details, "lastPayment");1340 listActions[10] = omit(listActions[10], "payload");1341 expect(listActions).to.deep.equal(expectedActions);1342 expect(window.ipcRenderer.send).not.to.be.called;1343 expect(fakeDB.streamBuilder).to.be.callCount(4);1344 expect(data.streamBuilder.update).to.be.callCount(4);1345 expect(data.streamBuilder.update).to.be.calledImmediatelyAfter(fakeDB.streamBuilder);1346 expect(data.streamBuilder.set).to.be.callCount(4);1347 expect(data.streamBuilder.set).to.be.calledImmediatelyAfter(data.streamBuilder.update);1348 expect(data.streamBuilder.set).to.be.calledWithExactly({1349 partsPaid: 1,1350 status: types.STREAM_PAYMENT_STREAMING,1351 });1352 expect(data.streamBuilder.set).to.be.calledWithExactly({1353 partsPaid: 3,1354 status: types.STREAM_PAYMENT_FINISHED,1355 });1356 expect(data.streamBuilder.where).to.be.callCount(4);1357 expect(data.streamBuilder.where).to.be.calledImmediatelyAfter(data.streamBuilder.set);1358 expect(data.streamBuilder.where).to.be.calledWithExactly("id = :id", { id: "foo" });1359 expect(data.streamBuilder.execute).to.be.callCount(4);1360 expect(data.streamBuilder.execute).to.be.calledImmediatelyAfter(data.streamBuilder.where);1361 expect(fakeDB.streamPartBuilder).to.be.calledTwice;1362 expect(data.streamPartBuilder.insert).to.be.calledTwice;1363 expect(data.streamPartBuilder.insert).to.be.calledImmediatelyAfter(fakeDB.streamPartBuilder);1364 expect(data.streamPartBuilder.values).to.be.calledTwice;1365 expect(data.streamPartBuilder.values).to.be.calledImmediatelyAfter(data.streamPartBuilder.insert);1366 expect(data.streamPartBuilder.values)1367 .to.be.calledWithExactly({ payment_hash: undefined, stream: "foo" });1368 expect(data.streamPartBuilder.execute).to.be.calledTwice;1369 expect(data.streamPartBuilder.execute).to.be.calledImmediatelyAfter(data.streamPartBuilder.values);1370 });1371 it("success with last payment between 1 and 2 delay periods, 1 payment left", async () => {1372 successRespTest = await successPromise({1373 response: {1374 payment_request: "foo",1375 },1376 });1377 fakeDispatchReturnSuccess = () => successRespTest;1378 fakeLightning.addInvoiceRemote.returns(fakeDispatchReturnSuccess);1379 window.ipcClient1380 .withArgs("sendPayment")1381 .returns({1382 ok: true,1383 });1384 const streams = [1385 {1386 partsPaid: 1,1387 partsPending: 0,1388 delay: 100,1389 lastPayment: Date.now() - 110,1390 totalParts: 2,1391 id: "foo",1392 price: 100,1393 status: types.STREAM_PAYMENT_PAUSED,1394 currency: "USD",1395 totalAmount: 1,1396 },1397 ];1398 initState.streamPayment.streams = streams;1399 store = configureStore(initState);1400 expectedActions = [1401 {1402 payload: {1403 details: {1404 status: types.STREAM_PAYMENT_STREAMING,1405 },1406 streamId: "foo",1407 },1408 type: types.UPDATE_STREAM_PAYMENT,1409 },1410 {1411 payload: {1412 change: 1,1413 streamId: "foo",1414 },1415 type: types.CHANGE_STREAM_PARTS_PENDING,1416 },1417 {1418 payload: {1419 change: -1,1420 streamId: "foo",1421 },1422 type: types.CHANGE_STREAM_PARTS_PENDING,1423 },1424 {1425 payload: {1426 change: 1,1427 streamId: "foo",1428 },1429 type: types.CHANGE_STREAM_PARTS_PAID,1430 },1431 {1432 payload: {1433 details: {1434 partsPaid: 2,1435 totalAmount: 101,1436 },1437 streamId: "foo",1438 },1439 type: types.UPDATE_STREAM_PAYMENT,1440 },1441 {1442 payload: {1443 details: {1444 status: types.STREAM_PAYMENT_FINISHED,1445 },1446 streamId: "foo",1447 },1448 type: types.UPDATE_STREAM_PAYMENT,1449 },1450 {1451 type: notificationsTypes.SHOW_NOTIFICATION,1452 },1453 ];1454 expect(await store.dispatch(operations.startStreamPayment("foo"))).to.deep.equal(expectedData);1455 await delay(100);1456 ({ listActions } = store.getState());1457 listActions[4].payload.details = omit(listActions[4].payload.details, "lastPayment");1458 listActions[6] = omit(listActions[6], "payload");1459 expect(listActions).to.deep.equal(expectedActions);1460 expect(window.ipcRenderer.send).not.to.be.called;1461 expect(fakeDB.streamBuilder).to.be.calledThrice;1462 expect(data.streamBuilder.update).to.be.calledThrice;1463 expect(data.streamBuilder.update).to.be.calledImmediatelyAfter(fakeDB.streamBuilder);1464 expect(data.streamBuilder.set).to.be.calledThrice;1465 expect(data.streamBuilder.set).to.be.calledImmediatelyAfter(data.streamBuilder.update);1466 expect(data.streamBuilder.set).to.be.calledWithExactly({1467 partsPaid: 1,1468 status: types.STREAM_PAYMENT_STREAMING,1469 });1470 expect(data.streamBuilder.set).to.be.calledWithExactly({1471 partsPaid: 2,1472 status: types.STREAM_PAYMENT_FINISHED,1473 });1474 expect(data.streamBuilder.where).to.be.calledThrice;1475 expect(data.streamBuilder.where).to.be.calledImmediatelyAfter(data.streamBuilder.set);1476 expect(data.streamBuilder.where).to.be.calledWithExactly("id = :id", { id: "foo" });1477 expect(data.streamBuilder.execute).to.be.calledThrice;1478 expect(data.streamBuilder.execute).to.be.calledImmediatelyAfter(data.streamBuilder.where);1479 expect(fakeDB.streamPartBuilder).to.be.calledOnce;1480 expect(data.streamPartBuilder.insert).to.be.calledOnce;1481 expect(data.streamPartBuilder.insert).to.be.calledImmediatelyAfter(fakeDB.streamPartBuilder);1482 expect(data.streamPartBuilder.values).to.be.calledOnce;1483 expect(data.streamPartBuilder.values).to.be.calledImmediatelyAfter(data.streamPartBuilder.insert);1484 expect(data.streamPartBuilder.values)1485 .to.be.calledWithExactly({ payment_hash: undefined, stream: "foo" });1486 expect(data.streamPartBuilder.execute).to.be.calledOnce;1487 expect(data.streamPartBuilder.execute).to.be.calledImmediatelyAfter(data.streamPartBuilder.values);1488 });1489 });1490 });1491 describe("Selectors Unit Tests", () => {1492 let state;1493 let expectedData;1494 beforeEach(() => {1495 state = {1496 streamPayment: {1497 ...initStateStreamPayment,1498 streams: [],1499 },1500 };1501 expectedData = {};1502 });1503 describe("isActiveStreamRunning()", () => {1504 it("no streaming stream", () => {1505 state.streamPayment.streams = [1506 {1507 status: types.STREAM_PAYMENT_FINISHED,1508 extra: "bar",1509 },1510 {1511 status: types.STREAM_PAYMENT_PAUSED,1512 extra: "foo",1513 },1514 ];1515 expectedData = false;1516 expect(selectors.isActiveStreamRunning(state)).to.deep.equal(expectedData);1517 });1518 it("contain streaming stream", () => {1519 state.streamPayment.streams = [1520 {1521 status: types.STREAM_PAYMENT_PAUSED,1522 extra: "bar",1523 },1524 {1525 status: types.STREAM_PAYMENT_STREAMING,1526 extra: "foo",1527 },1528 ];1529 expectedData = true;1530 expect(selectors.isActiveStreamRunning(state)).to.deep.equal(expectedData);1531 });1532 });1533 });...

Full Screen

Full Screen

stream-builder.ts

Source:stream-builder.ts Github

copy

Full Screen

1import { LineStream } from 'byline';2import { createReadStream, createWriteStream, mkdirSync } from 'fs';3import { decodeStream } from 'iconv-lite';4import { join } from 'path';5import { Field, PLAYERNAMES_PRIMARY_COLUMN, playersPlayernamesColumns, RawData, Table } from '../interfaces';6import {7 AppendDefaultTransform,8 ApplyPlayernamesTransform,9 Csv2JsonTransform,10 ExtendContractTransform,11 FilterTransform,12 Json2CsvTransform,13 NewLineTransform,14 ReindexMap2RawDataTransform,15 ReindexTransform,16 SkipTransform,17 ValidateTransform18} from '../transforms';19import { ReindexMap } from '../utils';20import { OutputFormat, StreamBuilderType } from './interfaces';21export class StreamBuilder {22 private stream: StreamBuilderType;23 constructor(private inputFolder: string, private table: Table, private fields: Field[]) {24 this.stream = this.init(this.inputFolder, this.table, this.fields);25 }26 private init(inputFolder: string, table: Table, fields: Field[]): StreamBuilderType {27 const inputFile = join(inputFolder, `${table}.txt`);28 return createReadStream(inputFile)29 .pipe(decodeStream('utf16le'))30 .pipe(new LineStream({ keepEmptyLines: false }))31 .pipe(new SkipTransform({ skip: 1 }))32 .pipe(new Csv2JsonTransform({ fields }));33 }34 public actionValidate(fields: Field[]): StreamBuilder {35 this.stream = this.stream.pipe(new ValidateTransform({ fields }));36 return this;37 }38 public actionFilter(filterFn: (data: RawData) => boolean): StreamBuilder {39 this.stream = this.stream.pipe(new FilterTransform({ filterFn }));40 return this;41 }42 public actionAppendDefault(fields: Field[]): StreamBuilder {43 this.stream = this.stream.pipe(new AppendDefaultTransform({ fields }));44 return this;45 }46 public actionExtendContract(fields: Field[], refDate?: Date): StreamBuilder {47 this.stream = this.stream.pipe(new ExtendContractTransform({ fields, refDate }));48 return this;49 }50 public actionReindex(startingPos: number = 0): StreamBuilder {51 this.stream = this.stream.pipe(new ReindexTransform({ startingPos }));52 return this;53 }54 public actionApplyPlayernames(55 reindexMap: ReindexMap[],56 foreingKeyPrimaryColumn: string = PLAYERNAMES_PRIMARY_COLUMN,57 foreignKeyColumns: string[] = playersPlayernamesColumns58 ): StreamBuilder {59 this.stream = this.stream.pipe(60 new ApplyPlayernamesTransform({ reindexMap, foreingKeyPrimaryColumn, foreignKeyColumns })61 );62 return this;63 }64 public actionReindexMap2RawData(primaryColumn: string): StreamBuilder {65 this.stream = this.stream.pipe(new ReindexMap2RawDataTransform({ primaryColumn }));66 return this;67 }68 public actionOnData(onDataFn: (data: any) => void): StreamBuilder {69 this.stream = this.stream.on('data', (buffer: Buffer) => {70 const cur = JSON.parse(buffer.toString());71 onDataFn(cur);72 });73 return this;74 }75 public actionWrite(outputFolder: string, fields: Field[], format: OutputFormat = OutputFormat.Csv): StreamBuilder {76 mkdirSync(outputFolder, { recursive: true });77 const outputFile = join(outputFolder, `${this.table}.txt`);78 const ws = createWriteStream(outputFile, { encoding: 'utf16le' });79 if (format === OutputFormat.Csv) {80 this.stream = this.stream.pipe(new Json2CsvTransform({ fields }));81 }82 this.stream = this.stream.pipe(new NewLineTransform()).pipe(ws);83 return this;84 }85 public onData(fn: (buffer: Buffer) => void): StreamBuilder {86 this.stream = this.stream.on('data', fn);87 return this;88 }89 public onFinish(fn: () => void): StreamBuilder {90 this.stream = this.stream.on('finish', fn);91 return this;92 }93 public onError(fn: () => void): StreamBuilder {94 this.stream = this.stream.on('error', fn);95 return this;96 }...

Full Screen

Full Screen

streaming.js

Source:streaming.js Github

copy

Full Screen

1const { StreamBuilder, dependencies } = require("../services/Streaming/StreamBuilder")2module.exports = {3 createStream: async function (req, res) {4 const streamBuilder = new StreamBuilder()5 const result = await streamBuilder.build()6 },7 deleteStream: async function (req, res) {8 }...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const { streamBuilder } = require('fast-check');2const { pipe } = require('fp-ts/lib/pipeable');3const { map } = require('fp-ts/lib/Array');4const { map as map2 } = require('fp-ts/lib/Option');5const { filter } = require('fp-ts/lib/Array');6const { chain } = require('fp-ts/lib/Array');7const { flatten } = require('fp-ts/lib/Array');8const { fold } = require('fp-ts/lib/Either');9const { map: map3 } = require('fp-ts/lib/Task');10const { chain: chain2 } = require('fp-ts/lib/Task');11const { flatten: flatten2 } = require('fp-ts/lib/Task');12const { map: map4 } = require('fp-ts/lib/TaskEither');13const { chain: chain3 } = require('fp-ts/lib/TaskEither');14const { flatten: flatten3 } = require('fp-ts/lib/TaskEither');15const { fold: fold2 } = require('fp-ts/lib/TaskEither');16const { map: map5 } = require('fp-ts/lib/IO');17const { chain: chain4 } = require('fp-ts/lib/IO');18const { flatten: flatten4 } = require('fp-ts/lib/IO');19const { map: map6 } = require('fp-ts/lib/IOEither');20const { chain: chain5 } = require('fp-ts/lib/IOEither');21const { flatten: flatten5 } = require('fp-ts/lib/IOEither');22const { fold: fold3 } = require('fp-ts/lib/IOEither');23const { map: map7 } = require('fp-ts/lib/Reader');24const { chain: chain6 } = require('fp-ts/lib/Reader');25const { flatten: flatten6 } = require('fp-ts/lib/Reader');26const { map: map8 } = require('fp-ts/lib/ReaderTask');27const { chain: chain7 } = require('fp-ts/lib/ReaderTask');28const { flatten: flatten7 } = require('fp-ts/lib/ReaderTask');29const { map: map9 } = require('fp-ts/lib/ReaderTaskEither');30const { chain: chain8 } = require('fp-ts/lib/ReaderTaskEither');31const { flatten: flatten8 } = require('fp-ts/lib/ReaderTaskEither');32const { fold: fold4 }

Full Screen

Using AI Code Generation

copy

Full Screen

1const { streamBuilder } = require('fast-check');2const { pipe } = require('fp-ts/lib/function');3const { map, filter, take } = require('fp-ts/lib/Stream');4const stream = pipe(5 streamBuilder(n => n + 1, 1),6 map(n => n * 2),7 filter(n => n % 2 === 0),8 take(10)9);10stream.forEach(console.log);11const { streamBuilder } = require('fast-check');12const { pipe } = require('fp-ts/lib/function');13const { map, filter, take } = require('fp-ts/lib/Stream');14const stream = pipe(15 streamBuilder(n => n + 1, 1),16 map(n => n * 2),17 filter(n => n % 2 === 0),18 take(10)19);20stream.forEach(console.log);21const { streamBuilder } = require('fast-check');22const { pipe } = require('fp-ts/lib/function');23const { map, filter, take } = require('fp-ts/lib/Stream');24const stream = pipe(25 streamBuilder(n => n + 1, 1),26 map(n => n * 2),27 filter(n => n % 2 === 0),28 take(10)29);30stream.forEach(console.log);31const { streamBuilder } = require('fast-check');32const { pipe } = require('fp-ts/lib/function');33const { map, filter, take } = require('fp-ts/lib/Stream');34const stream = pipe(35 streamBuilder(n => n + 1, 1),36 map(n => n * 2),37 filter(n => n % 2 === 0),38 take(10)39);40stream.forEach(console.log);

Full Screen

Using AI Code Generation

copy

Full Screen

1const { streamBuilder } = require('fast-check');2const stream = streamBuilder().integer().between(0, 100).build();3stream.subscribe((value) => {4 console.log(value);5});6stream.subscribe((value) => {7 console.log(value);8});

Full Screen

Using AI Code Generation

copy

Full Screen

1const { streamBuilder } = require('fast-check');2const { strictEqual } = require('assert');3const s = streamBuilder();4s.add(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);5s.on('data', (data) => {6 strictEqual(data, 1);7});8s.on('end', () => {9 console.log('done');10});11s.end();

Full Screen

Using AI Code Generation

copy

Full Screen

1const fc = require('fast-check');2const { streamBuilder } = require('fast-check');3const { streamBuilder } = require('fast-check/lib/stream/StreamBuilder');4const builder = streamBuilder();5 .generate(fc.nat())6 .filter(n => n % 2 === 0)7 .map(n => n * 2)8 .take(5)9 .forEach(n => console.log(n));10const fc = require('fast-check');11const { streamBuilder } = require('fast-check');12const builder = streamBuilder();13 .generate(fc.nat())14 .filter(n => n % 2 === 0)15 .map(n => n * 2)16 .take(5)17 .forEach(n => console.log(n));18const fc = require('fast-check');19const { streamBuilder } = require('fast-check');20const builder = streamBuilder();21 .generate(fc.nat())22 .filter(n => n % 2 === 0)23 .map(n => n * 2)24 .take(5)25 .forEach(n => console.log(n));26const fc = require('fast-check');27const { streamBuilder } = require('fast-check');28const builder = streamBuilder();29 .generate(fc.nat())30 .filter(n => n % 2 === 0)31 .map(n => n * 2)32 .take(5)33 .forEach(n => console.log(n));34const fc = require('fast-check');35const { streamBuilder } = require('fast-check');36const builder = streamBuilder();37 .generate(fc.nat())

Full Screen

Using AI Code Generation

copy

Full Screen

1const { streamBuilder } = require('fast-check');2const { map } = require('rxjs/operators');3const gen = streamBuilder(4 map((v) => {5 return v;6 })7);8const { streamBuilder } = require('fast-check/lib/stream/StreamBuilder');9const { map } = require('rxjs/operators');10const gen = streamBuilder(11 map((v) => {12 return v;13 })14);15Ok, I see. I think that the problem is that you are using the streamBuilder from fast-check (which is not the same as the one from fast-check-monorepo). I tried to reproduce your issue on my end and it works fine. I think that you are using the streamBuilder from fast-check instead of the one from fast-check-monorepo. I tried to reproduce your issue on my end and it works fine. I think that you are using the streamBuilder from fast-check instead of the one from fast-check-monorepo. I tried to reproduce your issue on my end and it works fine. I think that you are using the streamBuilder from fast-check instead of the one from fast-check-monorepo. I tried to reproduce your issue on my end and it works fine. I think that you are using the streamBuilder from fast-check instead of the one from fast-check-monorepo. I tried to reproduce your issue on my end and it works fine. I think that you are using the streamBuilder from fast-check instead of the one from fast-check-monorepo. I tried to reproduce your issue on my end and it works fine. I think that you are using the streamBuilder from fast-check instead of the one from fast-check-monorepo. I tried to reproduce your issue on my end and it works fine. I think that you are using the streamBuilder from fast-check instead of the one from fast-check-monorepo. I tried to reproduce your issue on my end and it works fine. I think that you are using the streamBuilder from fast-check instead of the one from fast-check-monorepo. I tried to reproduce your issue on my end and it works fine. I think that you are using the streamBuilder from fast-check instead of the one from fast-check-monorepo. I tried to reproduce your issue on my end and it works fine. I think that you are using the streamBuilder from fast-check instead of the one

Full Screen

Using AI Code Generation

copy

Full Screen

1const { streamBuilder } = require('@fast-check/stream');2const { Random } = require('@fast-check/random');3const { Stream } = require('@fast-check/stream');4const { makeStream } = require('./makeStream');5const makeStream = (seed, size) => {6 const random = new Random(seed);7 const stream = Stream.of(random.next());8 return streamBuilder(stream, random, size);9};10test('makeStream', () => {11 const seed = 42;12 const size = 100;13 const stream = makeStream(seed, size);14 expect(stream.length()).toBe(100);15 expect(stream.toArray()).toEqual([0.3745401188473625, 0.9507143064099162, 0.7319939418114051, 0.5986584841970366, 0.15601864044243652, 0.15599452033620265, 0.05808361216819946, 0.8661761457749352, 0.6011150117432088, 0.7080725777960455, 0.020584494295802447, 0.9699098521619943, 0.8324426408004219, 0.21233911067827616, 0.18182496720710057, 0.18340450954298222, 0.3042422429595377, 0.5247564316322378, 0.43194501864211535, 0.2912291401980419, 0.6118528947222508, 0.1394938606520412, 0.2921446485352181, 0.3663618432936917, 0.45606998421703517, 0.7851759613930136, 0.19967378215835974, 0.5142344384136116, 0.5924145688620425, 0.046450412719997725, 0.6075448519014388, 0.1705241236872919, 0.06505159298527958, 0.9488855372537313, 0.9656320339081489, 0.808397348116

Full Screen

Using AI Code Generation

copy

Full Screen

1const fc = require('fast-check');2const { streamBuilder } = require('fast-check-monorepo');3const { stream } = require('./stream.js');4const streamArb = streamBuilder().map(stream);5fc.assert(6 fc.property(streamArb, (s) => {7 const result = s.run();8 return result === 'foo';9 })10);11const { streamBuilder } = require('fast-check-monorepo');12const stream = streamBuilder();13module.exports = { stream };14const { streamBuilder } = require('fast-check-monorepo');15const stream = streamBuilder();16module.exports = { stream };17const { streamBuilder } = require('fast-check-monorepo');18const stream = streamBuilder();19module.exports = { stream };20const { streamBuilder } = require('fast-check-monorepo');21const stream = streamBuilder();22module.exports = { stream };

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run fast-check-monorepo automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful