storj/web/storagenode/tests/unit/components/payments/TotalHeldArea.spec.ts
Clement Sam 7461ffe148 {storagenode,web/multinode}: fix storage usage db/cache retrieval queries
The query changes we did while fixing the usage graph led to wrong
payout calculations directly linked to disk space.

This change:

- avoids converting from Bh to B directly in the query
- returns the at_rest_total in the original bytes*hour value
- returns at_rest_total_bytes as the calculated disk spaced used in bytes
- uses the at_rest_total_bytes only for the disk space graph
- return summary_bytes as the average disk space used within the specified date
- updates the disk space graph header to "average disk space used this month"

The total disk used in the month is also displayed in B not B*day

Resolves https://github.com/storj/storj/issues/5355

Change-Id: I2cfefb0fe711f9c59de2adb547c4ab50b05c7cbb
2022-12-09 11:07:33 +00:00

80 lines
2.5 KiB
TypeScript

// Copyright (C) 2020 Storj Labs, Inc.
// See LICENSE for copying information.
import Vuex from 'vuex';
import { createLocalVue, shallowMount } from '@vue/test-utils';
import { newNodeModule, NODE_MUTATIONS } from '@/app/store/modules/node';
import { newPayoutModule, PAYOUT_MUTATIONS } from '@/app/store/modules/payout';
import { PayoutHttpApi } from '@/storagenode/api/payout';
import { StorageNodeApi } from '@/storagenode/api/storagenode';
import { Paystub, TotalPayments } from '@/storagenode/payouts/payouts';
import { PayoutService } from '@/storagenode/payouts/service';
import { StorageNodeService } from '@/storagenode/sno/service';
import { Satellite, SatelliteScores, Stamp } from '@/storagenode/sno/sno';
import TotalHeldArea from '@/app/components/payments/TotalHeldArea.vue';
const localVue = createLocalVue();
localVue.use(Vuex);
localVue.filter('centsToDollars', (cents: number): string => {
return `$${(cents / 100).toFixed(2)}`;
});
const payoutApi = new PayoutHttpApi();
const payoutService = new PayoutService(payoutApi);
const payoutModule = newPayoutModule(payoutService);
const nodeApi = new StorageNodeApi();
const nodeService = new StorageNodeService(nodeApi);
const nodeModule = newNodeModule(nodeService);
const store = new Vuex.Store({ modules: { payoutModule, node: nodeModule } });
describe('TotalHeldArea', (): void => {
it('renders correctly', (): void => {
const wrapper = shallowMount(TotalHeldArea, {
store,
localVue,
});
expect(wrapper).toMatchSnapshot();
});
it('renders correctly with actual values', async (): Promise<void> => {
const wrapper = shallowMount(TotalHeldArea, {
store,
localVue,
});
const testJoinAt = new Date(Date.UTC(2018, 0, 30));
const satelliteInfo = new Satellite(
'3',
[new Stamp()],
[],
[],
[],
111,
11,
222,
50,
70,
new SatelliteScores('', 1, 0, 0),
testJoinAt,
);
const paystub = new Paystub();
paystub.held = 600000;
paystub.disposed = 100000;
paystub.paid = 1000000;
const totalPayments = new TotalPayments([paystub]);
await store.commit(NODE_MUTATIONS.SELECT_SATELLITE, satelliteInfo);
await store.commit(PAYOUT_MUTATIONS.SET_TOTAL, totalPayments);
expect(wrapper).toMatchSnapshot();
});
});