1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
import cloneDeep from 'lodash/cloneDeep';
import { PROJECT_STORAGE_TYPES } from '~/usage_quotas/storage/constants';
import {
parseGetProjectStorageResults,
getStorageTypesFromProjectStatistics,
descendingStorageUsageSort,
} from '~/usage_quotas/storage/utils';
import {
mockGetProjectStorageStatisticsGraphQLResponse,
defaultProjectProvideValues,
projectData,
} from './mock_data';
describe('getStorageTypesFromProjectStatistics', () => {
const {
statistics: projectStatistics,
statisticsDetailsPaths,
} = mockGetProjectStorageStatisticsGraphQLResponse.data.project;
describe('matches project statistics value with matching storage type', () => {
const typesWithStats = getStorageTypesFromProjectStatistics(projectStatistics);
it.each(PROJECT_STORAGE_TYPES)('storage type: $id', ({ id }) => {
expect(typesWithStats).toContainEqual({
storageType: expect.objectContaining({
id,
}),
value: projectStatistics[`${id}Size`],
});
});
});
it('adds helpPath to a relevant type', () => {
const helpLinks = PROJECT_STORAGE_TYPES.reduce((acc, { id }) => {
return {
...acc,
[id]: `url://${id}`,
};
}, {});
const typesWithStats = getStorageTypesFromProjectStatistics(projectStatistics, helpLinks);
typesWithStats.forEach((type) => {
const key = type.storageType.id;
expect(type.storageType.helpPath).toBe(helpLinks[key]);
});
});
it('adds details page path', () => {
const typesWithStats = getStorageTypesFromProjectStatistics(
projectStatistics,
{},
statisticsDetailsPaths,
);
typesWithStats.forEach((type) => {
expect(type.storageType.detailsPath).toBe(statisticsDetailsPaths[type.storageType.id]);
});
});
});
describe('parseGetProjectStorageResults', () => {
it('parses project statistics correctly', () => {
expect(
parseGetProjectStorageResults(
mockGetProjectStorageStatisticsGraphQLResponse.data,
defaultProjectProvideValues.helpLinks,
),
).toMatchObject(projectData);
});
it('includes storage type with size of 0 in returned value', () => {
const mockedResponse = cloneDeep(mockGetProjectStorageStatisticsGraphQLResponse.data);
// ensuring a specific storage type item has size of 0
mockedResponse.project.statistics.repositorySize = 0;
const response = parseGetProjectStorageResults(
mockedResponse,
defaultProjectProvideValues.helpLinks,
);
expect(response.storage.storageTypes).toEqual(
expect.arrayContaining([
{
storageType: expect.any(Object),
value: 0,
},
]),
);
});
});
describe('descendingStorageUsageSort', () => {
it('sorts items by a given key in descending order', () => {
const items = [{ k: 1 }, { k: 3 }, { k: 2 }];
const sorted = [...items].sort(descendingStorageUsageSort('k'));
const expectedSorted = [{ k: 3 }, { k: 2 }, { k: 1 }];
expect(sorted).toEqual(expectedSorted);
});
});
|