2020-04-16 15:18:35 +01:00
|
|
|
// Copyright (C) 2020 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
import Vuex from 'vuex';
|
|
|
|
|
2020-10-07 20:27:37 +01:00
|
|
|
import { newNodeModule } from '@/app/store/modules/node';
|
|
|
|
import { newPayoutModule, PAYOUT_ACTIONS, PAYOUT_MUTATIONS } from '@/app/store/modules/payout';
|
2020-09-08 18:39:16 +01:00
|
|
|
import { PayoutInfoRange } from '@/app/types/payout';
|
|
|
|
import { getHeldPercentage, getMonthsBeforeNow } from '@/app/utils/payout';
|
|
|
|
import { PayoutHttpApi } from '@/storagenode/api/payout';
|
2020-10-07 20:27:37 +01:00
|
|
|
import { StorageNodeApi } from '@/storagenode/api/storagenode';
|
2020-06-05 10:42:13 +01:00
|
|
|
import {
|
2020-07-01 17:34:01 +01:00
|
|
|
EstimatedPayout,
|
2020-06-05 10:42:13 +01:00
|
|
|
PayoutPeriod,
|
2020-09-08 18:39:16 +01:00
|
|
|
Paystub,
|
2020-07-01 17:34:01 +01:00
|
|
|
PreviousMonthEstimatedPayout,
|
2020-09-08 18:39:16 +01:00
|
|
|
SatelliteHeldHistory,
|
|
|
|
SatellitePayoutForPeriod,
|
|
|
|
TotalHeldAndPaid,
|
|
|
|
TotalPaystubForPeriod,
|
|
|
|
} from '@/storagenode/payouts/payouts';
|
|
|
|
import { PayoutService } from '@/storagenode/payouts/service';
|
2020-10-07 20:27:37 +01:00
|
|
|
import { StorageNodeService } from '@/storagenode/sno/service';
|
2020-04-16 15:18:35 +01:00
|
|
|
import { createLocalVue } from '@vue/test-utils';
|
|
|
|
|
|
|
|
const Vue = createLocalVue();
|
|
|
|
const payoutApi = new PayoutHttpApi();
|
2020-09-08 18:39:16 +01:00
|
|
|
const payoutService = new PayoutService(payoutApi);
|
2020-10-07 20:27:37 +01:00
|
|
|
const payoutModule = newPayoutModule(payoutService);
|
2020-04-16 15:18:35 +01:00
|
|
|
|
2020-10-07 20:27:37 +01:00
|
|
|
const nodeApi = new StorageNodeApi();
|
|
|
|
const nodeService = new StorageNodeService(nodeApi);
|
|
|
|
const nodeModule = newNodeModule(nodeService);
|
2020-04-16 15:18:35 +01:00
|
|
|
|
|
|
|
Vue.use(Vuex);
|
|
|
|
|
|
|
|
const store = new Vuex.Store({ modules: { payoutModule, node: nodeModule } });
|
|
|
|
|
|
|
|
const state = store.state as any;
|
|
|
|
|
2020-06-01 15:42:40 +01:00
|
|
|
describe('mutations', (): void => {
|
2020-04-16 15:18:35 +01:00
|
|
|
beforeEach(() => {
|
|
|
|
createLocalVue().use(Vuex);
|
|
|
|
});
|
|
|
|
|
2020-09-08 18:39:16 +01:00
|
|
|
it('sets payout information', (): void => {
|
|
|
|
const totalPaystubForPeriod = new TotalPaystubForPeriod([new Paystub(13, 12, 11)]);
|
2020-04-16 15:18:35 +01:00
|
|
|
|
2020-09-08 18:39:16 +01:00
|
|
|
store.commit(PAYOUT_MUTATIONS.SET_PAYOUT_INFO, totalPaystubForPeriod);
|
2020-04-16 15:18:35 +01:00
|
|
|
|
2020-09-08 18:39:16 +01:00
|
|
|
expect(state.payoutModule.totalPaystubForPeriod.usageAtRest).toBe(13);
|
|
|
|
expect(state.payoutModule.totalPaystubForPeriod.usageGet).toBe(12);
|
|
|
|
expect(state.payoutModule.totalPaystubForPeriod.usagePut).toBe(11);
|
2020-04-16 15:18:35 +01:00
|
|
|
});
|
|
|
|
|
2020-06-01 15:42:40 +01:00
|
|
|
it('sets total payout information', (): void => {
|
2020-09-08 18:39:16 +01:00
|
|
|
const paystub = new Paystub();
|
|
|
|
paystub.held = 600000;
|
|
|
|
paystub.disposed = 100000;
|
|
|
|
paystub.paid = 1000000;
|
|
|
|
|
|
|
|
const totalHeldAndPaid = new TotalHeldAndPaid([paystub]);
|
|
|
|
totalHeldAndPaid.setCurrentMonthEarnings(22);
|
2020-04-16 15:18:35 +01:00
|
|
|
|
2020-09-08 18:39:16 +01:00
|
|
|
store.commit(PAYOUT_MUTATIONS.SET_TOTAL, totalHeldAndPaid);
|
2020-04-16 15:18:35 +01:00
|
|
|
|
2020-09-08 18:39:16 +01:00
|
|
|
expect(state.payoutModule.totalHeldAndPaid.held).toBe(50);
|
|
|
|
expect(state.payoutModule.totalHeldAndPaid.paid).toBe(100);
|
2020-07-22 16:15:24 +01:00
|
|
|
expect(state.payoutModule.totalHeldAndPaid.disposed).toBe(10);
|
2020-05-20 18:10:15 +01:00
|
|
|
expect(state.payoutModule.currentMonthEarnings).toBe(22);
|
2020-04-16 15:18:35 +01:00
|
|
|
});
|
|
|
|
|
2020-06-01 15:42:40 +01:00
|
|
|
it('sets period range', (): void => {
|
2020-04-16 15:18:35 +01:00
|
|
|
const range = new PayoutInfoRange(new PayoutPeriod(2019, 2), new PayoutPeriod(2020, 3));
|
|
|
|
|
|
|
|
store.commit(PAYOUT_MUTATIONS.SET_RANGE, range);
|
|
|
|
|
|
|
|
if (!state.payoutModule.periodRange.start) {
|
|
|
|
fail('periodRange.start is null');
|
|
|
|
}
|
|
|
|
|
|
|
|
expect(state.payoutModule.periodRange.start.period).toBe('2019-03');
|
|
|
|
expect(state.payoutModule.periodRange.end.period).toBe('2020-04');
|
|
|
|
});
|
|
|
|
|
2020-06-01 15:42:40 +01:00
|
|
|
it('sets held percentage', (): void => {
|
2020-04-16 15:18:35 +01:00
|
|
|
const expectedHeldPercentage = 75;
|
|
|
|
|
|
|
|
store.commit(PAYOUT_MUTATIONS.SET_HELD_PERCENT, expectedHeldPercentage);
|
|
|
|
|
|
|
|
expect(state.payoutModule.heldPercentage).toBe(expectedHeldPercentage);
|
|
|
|
});
|
2020-06-05 10:42:13 +01:00
|
|
|
|
|
|
|
it('sets held history', (): void => {
|
2020-07-02 15:44:41 +01:00
|
|
|
const testJoinAt = new Date(Date.UTC(2020, 0, 30));
|
|
|
|
|
2020-09-08 18:39:16 +01:00
|
|
|
const testHeldHistory = [
|
|
|
|
new SatelliteHeldHistory('1', 'name1', 1, 50000, 0, 0, 1, testJoinAt),
|
|
|
|
new SatelliteHeldHistory('2', 'name2', 5, 50000, 422280, 0),
|
|
|
|
new SatelliteHeldHistory('3', 'name3', 6, 50000, 7333880, 7852235),
|
|
|
|
];
|
2020-06-05 10:42:13 +01:00
|
|
|
|
|
|
|
store.commit(PAYOUT_MUTATIONS.SET_HELD_HISTORY, testHeldHistory);
|
|
|
|
|
2020-09-08 18:39:16 +01:00
|
|
|
expect(state.payoutModule.heldHistory.length).toBe(testHeldHistory.length);
|
|
|
|
expect(state.payoutModule.heldHistory[1].satelliteName).toBe(testHeldHistory[1].satelliteName);
|
2020-09-10 15:08:25 +01:00
|
|
|
expect(state.payoutModule.heldHistory[1].holdForFirstPeriod).toBe(testHeldHistory[1].holdForFirstPeriod);
|
2020-09-08 18:39:16 +01:00
|
|
|
expect(state.payoutModule.heldHistory[0].joinedAt).toBe(testJoinAt);
|
|
|
|
expect(state.payoutModule.heldHistory[2].totalHeld).toBe(785.2235);
|
2020-06-05 10:42:13 +01:00
|
|
|
});
|
2020-05-27 19:41:51 +01:00
|
|
|
|
2020-07-01 17:34:01 +01:00
|
|
|
it('sets estimated payout information', (): void => {
|
|
|
|
const estimatedPayout = new EstimatedPayout(
|
|
|
|
new PreviousMonthEstimatedPayout(
|
|
|
|
1,
|
|
|
|
2,
|
|
|
|
3,
|
|
|
|
4,
|
|
|
|
5,
|
|
|
|
6,
|
|
|
|
7,
|
|
|
|
8,
|
|
|
|
9,
|
|
|
|
),
|
|
|
|
new PreviousMonthEstimatedPayout(
|
|
|
|
10,
|
|
|
|
11,
|
|
|
|
12,
|
|
|
|
13,
|
|
|
|
14,
|
|
|
|
15,
|
|
|
|
16,
|
|
|
|
17,
|
|
|
|
18,
|
|
|
|
),
|
|
|
|
);
|
|
|
|
|
|
|
|
store.commit(PAYOUT_MUTATIONS.SET_ESTIMATION, estimatedPayout);
|
|
|
|
|
|
|
|
expect(state.payoutModule.estimation.currentMonth.payout).toBe(8);
|
|
|
|
expect(state.payoutModule.estimation.previousMonth.heldRate).toBe(16);
|
|
|
|
});
|
|
|
|
|
2020-05-27 19:41:51 +01:00
|
|
|
it('sets available periods', (): void => {
|
|
|
|
const firstExpectedPeriod = '2020-04';
|
|
|
|
const secondExpectedPeriod = '1999-11';
|
|
|
|
const incomingDataSet = [firstExpectedPeriod, secondExpectedPeriod];
|
|
|
|
|
|
|
|
store.commit(PAYOUT_MUTATIONS.SET_PERIODS, incomingDataSet);
|
|
|
|
|
|
|
|
expect(state.payoutModule.payoutPeriods.length).toBe(2);
|
|
|
|
expect(state.payoutModule.payoutPeriods[0]).toBe(firstExpectedPeriod);
|
|
|
|
expect(state.payoutModule.payoutPeriods[1]).toBe(secondExpectedPeriod);
|
|
|
|
});
|
2020-07-28 11:04:07 +01:00
|
|
|
|
2020-09-25 10:57:08 +01:00
|
|
|
it('sets available payout history periods', (): void => {
|
|
|
|
const firstExpectedPeriod = '2020-08';
|
|
|
|
const incomingDataSet = [firstExpectedPeriod];
|
|
|
|
|
|
|
|
store.commit(PAYOUT_MUTATIONS.SET_PAYOUT_HISTORY_AVAILABLE_PERIODS, incomingDataSet);
|
|
|
|
|
|
|
|
expect(state.payoutModule.payoutHistoryAvailablePeriods.length).toBe(1);
|
|
|
|
expect(state.payoutModule.payoutHistoryAvailablePeriods[0]).toBe(firstExpectedPeriod);
|
|
|
|
});
|
|
|
|
|
2020-07-28 11:04:07 +01:00
|
|
|
it('sets payout history period', (): void => {
|
|
|
|
const expectedPeriod = '2020-04';
|
|
|
|
|
|
|
|
store.commit(PAYOUT_MUTATIONS.SET_PAYOUT_HISTORY_PERIOD, expectedPeriod);
|
|
|
|
|
|
|
|
expect(state.payoutModule.payoutHistoryPeriod).toBe(expectedPeriod);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('sets payout history period', (): void => {
|
|
|
|
const payoutHistory = [
|
2020-09-08 18:39:16 +01:00
|
|
|
new SatellitePayoutForPeriod('1', 'name1', 1, 10, 120, 140,
|
2020-07-28 11:04:07 +01:00
|
|
|
50, 60, 20, 80, 'receipt1', false,
|
|
|
|
),
|
2020-09-08 18:39:16 +01:00
|
|
|
new SatellitePayoutForPeriod('2', 'name2', 16, 10, 120, 140,
|
2020-07-28 11:04:07 +01:00
|
|
|
50, 60, 20, 80, 'receipt2', true,
|
|
|
|
),
|
|
|
|
];
|
|
|
|
store.commit(PAYOUT_MUTATIONS.SET_PAYOUT_HISTORY, payoutHistory);
|
|
|
|
|
|
|
|
expect(state.payoutModule.payoutHistory.length).toBe(payoutHistory.length);
|
|
|
|
expect(state.payoutModule.payoutHistory[0].satelliteID).toBe(payoutHistory[0].satelliteID);
|
|
|
|
expect(state.payoutModule.payoutHistory[1].receipt).toBe(payoutHistory[1].receipt);
|
|
|
|
});
|
2020-04-16 15:18:35 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('actions', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
jest.resetAllMocks();
|
|
|
|
});
|
|
|
|
|
2020-09-08 18:39:16 +01:00
|
|
|
it('success get payout info by month', async (): Promise<void> => {
|
|
|
|
const paystub = new Paystub();
|
|
|
|
paystub.usagePut = 3;
|
|
|
|
paystub.held = 100000;
|
|
|
|
|
|
|
|
jest.spyOn(payoutApi, 'getPaystubsForPeriod').mockReturnValue(
|
|
|
|
Promise.resolve([paystub]),
|
2020-04-16 15:18:35 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
const range = new PayoutInfoRange(null, new PayoutPeriod(2020, 3));
|
|
|
|
|
|
|
|
store.commit(PAYOUT_MUTATIONS.SET_RANGE, range);
|
|
|
|
|
2020-09-08 18:39:16 +01:00
|
|
|
await store.dispatch(PAYOUT_ACTIONS.GET_PAYOUT_INFO);
|
2020-04-16 15:18:35 +01:00
|
|
|
|
2020-09-08 18:39:16 +01:00
|
|
|
expect(state.payoutModule.totalPaystubForPeriod.usagePut).toBe(3);
|
|
|
|
expect(state.payoutModule.totalPaystubForPeriod.held).toBe(10);
|
2020-04-16 15:18:35 +01:00
|
|
|
expect(state.payoutModule.heldPercentage).toBe(getHeldPercentage(new Date()));
|
|
|
|
});
|
|
|
|
|
2020-09-08 18:39:16 +01:00
|
|
|
it('get payout info by month throws an error when api call fails', async (): Promise<void> => {
|
|
|
|
jest.spyOn(payoutApi, 'getPaystubsForPeriod').mockImplementation(() => { throw new Error(); });
|
2020-04-16 15:18:35 +01:00
|
|
|
|
|
|
|
try {
|
2020-09-08 18:39:16 +01:00
|
|
|
await store.dispatch(PAYOUT_ACTIONS.GET_PAYOUT_INFO);
|
2020-04-16 15:18:35 +01:00
|
|
|
expect(true).toBe(false);
|
|
|
|
} catch (error) {
|
2020-09-08 18:39:16 +01:00
|
|
|
expect(state.payoutModule.totalPaystubForPeriod.usagePut).toBe(3);
|
|
|
|
expect(state.payoutModule.totalPaystubForPeriod.held).toBe(10);
|
2020-04-16 15:18:35 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2020-09-08 18:39:16 +01:00
|
|
|
it('success get payout info by period', async (): Promise<void> => {
|
|
|
|
const paystub = new Paystub();
|
|
|
|
paystub.usagePut = 3;
|
|
|
|
paystub.held = 100000;
|
|
|
|
|
|
|
|
jest.spyOn(payoutApi, 'getPaystubsForPeriod').mockReturnValue(
|
|
|
|
Promise.resolve([paystub]),
|
2020-04-16 15:18:35 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
const range = new PayoutInfoRange(new PayoutPeriod(2019, 2), new PayoutPeriod(2020, 3));
|
|
|
|
|
|
|
|
store.commit(PAYOUT_MUTATIONS.SET_RANGE, range);
|
|
|
|
|
2020-09-08 18:39:16 +01:00
|
|
|
await store.dispatch(PAYOUT_ACTIONS.GET_PAYOUT_INFO);
|
2020-04-16 15:18:35 +01:00
|
|
|
|
2020-09-08 18:39:16 +01:00
|
|
|
expect(state.payoutModule.totalPaystubForPeriod.usagePut).toBe(3);
|
|
|
|
expect(state.payoutModule.totalPaystubForPeriod.held).toBe(10);
|
2020-04-16 15:18:35 +01:00
|
|
|
});
|
|
|
|
|
2020-09-08 18:39:16 +01:00
|
|
|
it('get payout info by period throws an error when api call fails', async (): Promise<void> => {
|
|
|
|
jest.spyOn(payoutApi, 'getPaystubsForPeriod').mockImplementation(() => { throw new Error(); });
|
2020-04-16 15:18:35 +01:00
|
|
|
|
|
|
|
try {
|
2020-09-08 18:39:16 +01:00
|
|
|
await store.dispatch(PAYOUT_ACTIONS.GET_PAYOUT_INFO);
|
2020-04-16 15:18:35 +01:00
|
|
|
expect(true).toBe(false);
|
|
|
|
} catch (error) {
|
2020-09-08 18:39:16 +01:00
|
|
|
expect(state.payoutModule.totalPaystubForPeriod.usagePut).toBe(3);
|
|
|
|
expect(state.payoutModule.totalPaystubForPeriod.held).toBe(10);
|
2020-04-16 15:18:35 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2020-06-01 15:42:40 +01:00
|
|
|
it('success get total', async (): Promise<void> => {
|
2020-09-08 18:39:16 +01:00
|
|
|
const paystub = new Paystub();
|
|
|
|
paystub.held = 100000;
|
2020-07-22 16:15:24 +01:00
|
|
|
paystub.disposed = 50000;
|
2020-09-08 18:39:16 +01:00
|
|
|
paystub.paid = 200000;
|
|
|
|
|
|
|
|
jest.spyOn(payoutApi, 'getPaystubsForPeriod').mockReturnValue(
|
|
|
|
Promise.resolve([paystub]),
|
2020-04-16 15:18:35 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
await store.dispatch(PAYOUT_ACTIONS.GET_TOTAL);
|
|
|
|
|
2020-07-22 16:15:24 +01:00
|
|
|
expect(state.payoutModule.totalHeldAndPaid.held).toBe(5);
|
2020-09-08 18:39:16 +01:00
|
|
|
expect(state.payoutModule.totalHeldAndPaid.paid).toBe(20);
|
2020-07-22 16:15:24 +01:00
|
|
|
expect(state.payoutModule.totalHeldAndPaid.disposed).toBe(5);
|
2020-05-20 18:10:15 +01:00
|
|
|
expect(state.payoutModule.currentMonthEarnings).toBe(0);
|
2020-04-16 15:18:35 +01:00
|
|
|
});
|
|
|
|
|
2020-06-01 15:42:40 +01:00
|
|
|
it('get total throws an error when api call fails', async (): Promise<void> => {
|
2020-09-08 18:39:16 +01:00
|
|
|
jest.spyOn(payoutApi, 'getPaystubsForPeriod').mockImplementation(() => { throw new Error(); });
|
2020-04-16 15:18:35 +01:00
|
|
|
|
|
|
|
try {
|
|
|
|
await store.dispatch(PAYOUT_ACTIONS.GET_TOTAL);
|
|
|
|
expect(true).toBe(false);
|
|
|
|
} catch (error) {
|
2020-07-22 16:15:24 +01:00
|
|
|
expect(state.payoutModule.totalHeldAndPaid.held).toBe(5);
|
2020-09-08 18:39:16 +01:00
|
|
|
expect(state.payoutModule.totalHeldAndPaid.paid).toBe(20);
|
2020-05-20 18:10:15 +01:00
|
|
|
expect(state.payoutModule.currentMonthEarnings).toBe(0);
|
2020-04-16 15:18:35 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2020-05-27 19:41:51 +01:00
|
|
|
it('success fetches available periods', async (): Promise<void> => {
|
|
|
|
const firstExpectedPeriod = '2020-04';
|
|
|
|
const secondExpectedPeriod = '1999-11';
|
|
|
|
|
|
|
|
jest.spyOn(payoutApi, 'getPayoutPeriods').mockReturnValue(
|
|
|
|
Promise.resolve([
|
|
|
|
PayoutPeriod.fromString(firstExpectedPeriod),
|
|
|
|
PayoutPeriod.fromString(secondExpectedPeriod),
|
|
|
|
]),
|
2020-04-16 15:18:35 +01:00
|
|
|
);
|
|
|
|
|
2020-09-25 10:57:08 +01:00
|
|
|
await store.dispatch(PAYOUT_ACTIONS.GET_PERIODS, 'id');
|
2020-05-27 19:41:51 +01:00
|
|
|
|
|
|
|
expect(state.payoutModule.payoutPeriods.length).toBe(2);
|
|
|
|
expect(state.payoutModule.payoutPeriods[0].period).toBe(firstExpectedPeriod);
|
|
|
|
expect(state.payoutModule.payoutPeriods[1].period).toBe(secondExpectedPeriod);
|
2020-09-25 10:57:08 +01:00
|
|
|
expect(state.payoutModule.payoutHistoryAvailablePeriods.length).toBe(1);
|
|
|
|
|
|
|
|
await store.dispatch(PAYOUT_ACTIONS.GET_PERIODS);
|
|
|
|
|
|
|
|
expect(state.payoutModule.payoutHistoryAvailablePeriods.length).toBe(2);
|
|
|
|
expect(state.payoutModule.payoutHistoryAvailablePeriods[0].period).toBe(firstExpectedPeriod);
|
2020-05-27 19:41:51 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
it('get available periods throws an error when api call fails', async () => {
|
|
|
|
jest.spyOn(payoutApi, 'getPayoutPeriods').mockImplementation(() => { throw new Error(); });
|
|
|
|
|
|
|
|
try {
|
|
|
|
await store.dispatch(PAYOUT_ACTIONS.GET_PERIODS);
|
|
|
|
expect(true).toBe(false);
|
|
|
|
} catch (error) {
|
|
|
|
expect(state.payoutModule.payoutPeriods.length).toBe(2);
|
|
|
|
}
|
2020-04-16 15:18:35 +01:00
|
|
|
});
|
2020-06-05 10:42:13 +01:00
|
|
|
|
|
|
|
it('success get held history', async (): Promise<void> => {
|
2020-07-02 15:44:41 +01:00
|
|
|
const testJoinAt = new Date(Date.UTC(2020, 0, 30));
|
2020-09-08 18:39:16 +01:00
|
|
|
const testHeldHistory = [
|
|
|
|
new SatelliteHeldHistory('1', 'name1', 1, 50000, 0, 0, 1, testJoinAt),
|
|
|
|
new SatelliteHeldHistory('2', 'name2', 5, 50000, 422280, 0),
|
|
|
|
new SatelliteHeldHistory('3', 'name3', 6, 50000, 7333880, 7852235),
|
|
|
|
];
|
2020-07-02 15:44:41 +01:00
|
|
|
|
2020-06-05 10:42:13 +01:00
|
|
|
jest.spyOn(payoutApi, 'getHeldHistory').mockReturnValue(
|
2020-09-08 18:39:16 +01:00
|
|
|
Promise.resolve(testHeldHistory),
|
2020-06-05 10:42:13 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
await store.dispatch(PAYOUT_ACTIONS.GET_HELD_HISTORY);
|
|
|
|
|
2020-09-08 18:39:16 +01:00
|
|
|
expect(state.payoutModule.heldHistory.length).toBe(3);
|
|
|
|
expect(state.payoutModule.heldHistory[1].satelliteName).toBe('name2');
|
|
|
|
expect(state.payoutModule.heldHistory[0].joinedAt).toBe(testJoinAt);
|
|
|
|
expect(state.payoutModule.heldHistory[2].totalHeld).toBe(785.2235);
|
2020-06-05 10:42:13 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
it('get total throws an error when api call fails', async (): Promise<void> => {
|
|
|
|
jest.spyOn(payoutApi, 'getHeldHistory').mockImplementation(() => { throw new Error(); });
|
|
|
|
|
|
|
|
try {
|
|
|
|
await store.dispatch(PAYOUT_ACTIONS.GET_HELD_HISTORY);
|
|
|
|
expect(true).toBe(false);
|
|
|
|
} catch (error) {
|
2020-09-08 18:39:16 +01:00
|
|
|
expect(state.payoutModule.heldHistory.length).toBe(3);
|
2020-06-05 10:42:13 +01:00
|
|
|
}
|
|
|
|
});
|
2020-07-01 17:34:01 +01:00
|
|
|
|
2020-07-28 11:04:07 +01:00
|
|
|
it('sets payout history period', async (): Promise<void> => {
|
|
|
|
const expectedPeriod = '2020-01';
|
|
|
|
|
|
|
|
await store.dispatch(PAYOUT_ACTIONS.SET_PAYOUT_HISTORY_PERIOD, expectedPeriod);
|
|
|
|
|
|
|
|
expect(state.payoutModule.payoutHistoryPeriod).toBe(expectedPeriod);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('get payout history throws an error when api call fails', async (): Promise<void> => {
|
|
|
|
jest.spyOn(payoutApi, 'getPayoutHistory').mockImplementation(() => { throw new Error(); });
|
|
|
|
|
|
|
|
try {
|
|
|
|
await store.dispatch(PAYOUT_ACTIONS.GET_PAYOUT_HISTORY);
|
|
|
|
expect(true).toBe(false);
|
|
|
|
} catch (error) {
|
|
|
|
expect(state.payoutModule.payoutHistory.length).toBe(2);
|
|
|
|
expect(state.payoutModule.payoutHistory[1].satelliteName).toBe('name2');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
it('success get payout history', async (): Promise<void> => {
|
|
|
|
jest.spyOn(payoutApi, 'getPayoutHistory').mockReturnValue(
|
|
|
|
Promise.resolve([
|
2020-09-08 18:39:16 +01:00
|
|
|
new SatellitePayoutForPeriod('1', 'name1', 1, 100000, 2200000, 140,
|
2020-07-28 11:04:07 +01:00
|
|
|
500000, 600000, 200000, 800000, 'receipt1', false,
|
|
|
|
),
|
|
|
|
]),
|
|
|
|
);
|
|
|
|
|
|
|
|
await store.dispatch(PAYOUT_ACTIONS.GET_PAYOUT_HISTORY);
|
|
|
|
|
|
|
|
expect(state.payoutModule.payoutHistory.length).toBe(1);
|
|
|
|
expect(state.payoutModule.payoutHistory[0].satelliteName).toBe('name1');
|
|
|
|
expect(state.payoutModule.payoutHistory[0].surge).toBe(220);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('getters', () => {
|
|
|
|
it('getter totalPaidForPayoutHistoryPeriod returns correct value', async (): Promise<void> => {
|
|
|
|
jest.spyOn(payoutApi, 'getPayoutHistory').mockReturnValue(
|
|
|
|
Promise.resolve([
|
2020-09-08 18:39:16 +01:00
|
|
|
new SatellitePayoutForPeriod('1', 'name1', 1, 10, 120, 140,
|
2020-07-28 11:04:07 +01:00
|
|
|
50, 60, 20, 1300000, 'receipt1', false,
|
|
|
|
),
|
2020-09-08 18:39:16 +01:00
|
|
|
new SatellitePayoutForPeriod('2', 'name2', 16, 10, 120, 140,
|
2020-07-28 11:04:07 +01:00
|
|
|
50, 60, 20, 1700000, 'receipt2', true,
|
|
|
|
),
|
|
|
|
]),
|
|
|
|
);
|
|
|
|
|
|
|
|
await store.dispatch(PAYOUT_ACTIONS.GET_PAYOUT_HISTORY);
|
|
|
|
|
|
|
|
expect(store.getters.totalPaidForPayoutHistoryPeriod).toBe(300);
|
|
|
|
});
|
|
|
|
|
2020-07-01 17:34:01 +01:00
|
|
|
it('get estimated payout information throws an error when api call fails', async (): Promise<void> => {
|
2020-09-08 18:39:16 +01:00
|
|
|
jest.spyOn(payoutApi, 'getEstimatedPayout').mockImplementation(() => { throw new Error(); });
|
2020-07-01 17:34:01 +01:00
|
|
|
|
|
|
|
try {
|
|
|
|
await store.dispatch(PAYOUT_ACTIONS.GET_ESTIMATION);
|
|
|
|
expect(true).toBe(false);
|
|
|
|
} catch (error) {
|
|
|
|
expect(state.payoutModule.estimation.currentMonth.held).toBe(9);
|
|
|
|
expect(state.payoutModule.estimation.previousMonth.diskSpace).toBe(14);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
it('success get estimated payout information', async (): Promise<void> => {
|
2020-09-08 18:39:16 +01:00
|
|
|
jest.spyOn(payoutApi, 'getEstimatedPayout').mockReturnValue(
|
2020-07-01 17:34:01 +01:00
|
|
|
Promise.resolve(new EstimatedPayout(
|
|
|
|
new PreviousMonthEstimatedPayout(
|
|
|
|
1,
|
|
|
|
2,
|
|
|
|
300,
|
|
|
|
4,
|
|
|
|
5,
|
|
|
|
6,
|
|
|
|
7,
|
|
|
|
8,
|
|
|
|
9,
|
|
|
|
),
|
|
|
|
new PreviousMonthEstimatedPayout(
|
|
|
|
10,
|
|
|
|
11,
|
|
|
|
12,
|
|
|
|
13,
|
|
|
|
700,
|
|
|
|
15,
|
|
|
|
16,
|
|
|
|
17,
|
|
|
|
18,
|
|
|
|
),
|
|
|
|
)),
|
|
|
|
);
|
|
|
|
|
|
|
|
await store.dispatch(PAYOUT_ACTIONS.GET_ESTIMATION);
|
|
|
|
|
|
|
|
expect(state.payoutModule.estimation.currentMonth.egressRepairAudit).toBe(300);
|
|
|
|
expect(state.payoutModule.estimation.previousMonth.diskSpace).toBe(700);
|
|
|
|
});
|
2020-04-16 15:18:35 +01:00
|
|
|
});
|
|
|
|
|
2020-06-01 15:42:40 +01:00
|
|
|
describe('utils functions', (): void => {
|
|
|
|
const _Date = Date;
|
|
|
|
|
|
|
|
// TODO: investigate reset mocks in config
|
|
|
|
beforeEach(() => {
|
|
|
|
jest.resetAllMocks();
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
global.Date = _Date;
|
|
|
|
});
|
|
|
|
|
|
|
|
it('get correct held percentage', (): void => {
|
|
|
|
const testDates: Date[] = [
|
|
|
|
new Date(Date.UTC(2020, 0, 30)),
|
|
|
|
new Date(Date.UTC(2019, 10, 29)),
|
|
|
|
new Date(Date.UTC(2019, 7, 24)),
|
|
|
|
new Date(Date.UTC(2018, 1, 24)),
|
|
|
|
];
|
2020-04-16 15:18:35 +01:00
|
|
|
const expectedHeldPercentages: number[] = [75, 50, 25, 0];
|
|
|
|
|
2020-06-01 15:42:40 +01:00
|
|
|
const mockedDate = new Date(1580522290000); // Sat Feb 01 2020
|
|
|
|
global.Date = jest.fn(() => mockedDate);
|
|
|
|
|
|
|
|
for (let i = 0; i < testDates.length; i++) {
|
|
|
|
const heldPercentage = getHeldPercentage(testDates[i]);
|
2020-04-16 15:18:35 +01:00
|
|
|
|
|
|
|
expect(heldPercentage).toBe(expectedHeldPercentages[i]);
|
|
|
|
}
|
|
|
|
});
|
2020-06-01 15:42:40 +01:00
|
|
|
|
|
|
|
it('get correct months difference', (): void => {
|
|
|
|
const testDates: Date[] = [
|
|
|
|
new Date(Date.UTC(2020, 0, 30)),
|
|
|
|
new Date(Date.UTC(2019, 10, 29)),
|
|
|
|
new Date(Date.UTC(2019, 7, 24)),
|
|
|
|
new Date(Date.UTC(2018, 1, 24)),
|
|
|
|
];
|
|
|
|
const expectedMonthsCount: number[] = [2, 4, 7, 25];
|
|
|
|
|
|
|
|
const mockedDate = new Date(1580522290000); // Sat Feb 01 2020
|
|
|
|
global.Date = jest.fn(() => mockedDate);
|
|
|
|
|
|
|
|
for (let i = 0; i < testDates.length; i++) {
|
|
|
|
const heldPercentage = getMonthsBeforeNow(testDates[i]);
|
|
|
|
|
|
|
|
expect(heldPercentage).toBe(expectedMonthsCount[i]);
|
|
|
|
}
|
|
|
|
});
|
2020-04-16 15:18:35 +01:00
|
|
|
});
|