@northern.tech/store 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.cjs +9 -0
- package/.prettierignore +1 -0
- package/CHANGELOG.md +12 -0
- package/actions.ts +32 -0
- package/api/general-api.test.ts +51 -0
- package/api/general-api.ts +60 -0
- package/api/types/AWSCredentials.ts +16 -0
- package/api/types/Actor.ts +35 -0
- package/api/types/Addon.ts +17 -0
- package/api/types/AddonTenantadm.ts +17 -0
- package/api/types/Alert.ts +34 -0
- package/api/types/AlertDetails.ts +23 -0
- package/api/types/AlertSubject.ts +23 -0
- package/api/types/ApiBurst.ts +21 -0
- package/api/types/ApiBurstTenantadm.ts +21 -0
- package/api/types/ApiLimits.ts +16 -0
- package/api/types/ApiLimitsTenantadm.ts +16 -0
- package/api/types/ApiQuota.ts +17 -0
- package/api/types/ApiQuotaTenantadm.ts +17 -0
- package/api/types/Artifact.ts +48 -0
- package/api/types/ArtifactDeployments.ts +48 -0
- package/api/types/ArtifactInfo.ts +11 -0
- package/api/types/ArtifactInfoDeployments.ts +11 -0
- package/api/types/ArtifactLink.ts +11 -0
- package/api/types/ArtifactTypeInfo.ts +13 -0
- package/api/types/ArtifactTypeInfoDeployments.ts +13 -0
- package/api/types/ArtifactUpdate.ts +10 -0
- package/api/types/ArtifactUploadLink.ts +15 -0
- package/api/types/Attribute.ts +36 -0
- package/api/types/AttributeInventory.ts +32 -0
- package/api/types/AuditLog.ts +26 -0
- package/api/types/AuthSet.ts +33 -0
- package/api/types/AuthSetDeviceauth.ts +37 -0
- package/api/types/AutoAuthRequest.ts +23 -0
- package/api/types/AzureSharedAccessSecret.ts +11 -0
- package/api/types/BillingInfo.ts +13 -0
- package/api/types/BinaryDeltaConfiguration.ts +15 -0
- package/api/types/BinaryDeltaConfigurationDeployments.ts +15 -0
- package/api/types/BinaryDeltaLimits.ts +15 -0
- package/api/types/BinaryDeltaLimitsDeployments.ts +15 -0
- package/api/types/BoundingBox.ts +11 -0
- package/api/types/CancelRequest.ts +10 -0
- package/api/types/CardData.ts +49 -0
- package/api/types/CardSetupData.ts +17 -0
- package/api/types/CheckoutData.ts +13 -0
- package/api/types/Configuration.ts +11 -0
- package/api/types/Count.ts +13 -0
- package/api/types/Credentials.ts +23 -0
- package/api/types/DBusSubsystem.ts +27 -0
- package/api/types/DeltaConfiguration.ts +14 -0
- package/api/types/DeltaConfigurationDeployments.ts +14 -0
- package/api/types/Deployment.ts +95 -0
- package/api/types/DeploymentAggregation.ts +18 -0
- package/api/types/DeploymentAggregationItem.ts +18 -0
- package/api/types/DeploymentAggregationTerm.ts +23 -0
- package/api/types/DeploymentAggregationTerms.ts +18 -0
- package/api/types/DeploymentAttributeProjection.ts +11 -0
- package/api/types/DeploymentAuditlogs.ts +11 -0
- package/api/types/DeploymentDeployments.ts +99 -0
- package/api/types/DeploymentFilterTerm.ts +37 -0
- package/api/types/DeploymentIdentifier.ts +10 -0
- package/api/types/DeploymentPhase.ts +23 -0
- package/api/types/DeploymentReporting.ts +46 -0
- package/api/types/DeploymentSearchTerms.ts +39 -0
- package/api/types/DeploymentSortTerm.ts +25 -0
- package/api/types/DeploymentStatistics.ts +15 -0
- package/api/types/DeploymentStatusStatistics.ts +54 -0
- package/api/types/Device.ts +29 -0
- package/api/types/DeviceAggregation.ts +18 -0
- package/api/types/DeviceAggregationItem.ts +18 -0
- package/api/types/DeviceAggregationTerm.ts +27 -0
- package/api/types/DeviceAggregationTerms.ts +22 -0
- package/api/types/DeviceAttribute.ts +23 -0
- package/api/types/DeviceAttributeProjection.ts +15 -0
- package/api/types/DeviceAuditlogs.ts +17 -0
- package/api/types/DeviceAuthEvent.ts +23 -0
- package/api/types/DeviceConfiguration.ts +16 -0
- package/api/types/DeviceDeployment.ts +11 -0
- package/api/types/DeviceDeployments.ts +31 -0
- package/api/types/DeviceDeviceauth.ts +42 -0
- package/api/types/DeviceFilterAttribute.ts +22 -0
- package/api/types/DeviceFilterTerm.ts +41 -0
- package/api/types/DeviceInventory.ts +19 -0
- package/api/types/DeviceInventoryInventory.ts +19 -0
- package/api/types/DeviceReporting.ts +22 -0
- package/api/types/DeviceSearchTerms.ts +39 -0
- package/api/types/DeviceSortTerm.ts +29 -0
- package/api/types/DeviceState.ts +32 -0
- package/api/types/DeviceStateDeviceconnect.ts +33 -0
- package/api/types/DeviceStateIot_manager.ts +14 -0
- package/api/types/DeviceStatus.ts +19 -0
- package/api/types/DeviceWithImage.ts +80 -0
- package/api/types/DirectUploadMetadata.ts +18 -0
- package/api/types/EmailVerificationCompletion.ts +13 -0
- package/api/types/EmailVerificationRequest.ts +13 -0
- package/api/types/Error.ts +17 -0
- package/api/types/ErrorAuditlogs.ts +13 -0
- package/api/types/ErrorDeployments.ts +17 -0
- package/api/types/ErrorDeviceauth.ts +13 -0
- package/api/types/ErrorDeviceconfig.ts +17 -0
- package/api/types/ErrorDeviceconnect.ts +17 -0
- package/api/types/ErrorDevicemonitor.ts +17 -0
- package/api/types/ErrorExt.ts +18 -0
- package/api/types/ErrorInventory.ts +17 -0
- package/api/types/ErrorIot_manager.ts +17 -0
- package/api/types/ErrorNotFound.ts +17 -0
- package/api/types/ErrorReporting.ts +18 -0
- package/api/types/ErrorTenantadm.ts +13 -0
- package/api/types/ErrorUseradm.ts +17 -0
- package/api/types/Event.ts +48 -0
- package/api/types/ExternalIdentity.ts +17 -0
- package/api/types/Features.ts +17 -0
- package/api/types/FileUpload.ts +23 -0
- package/api/types/Filter.ts +19 -0
- package/api/types/FilterAttribute.ts +21 -0
- package/api/types/FilterDefinition.ts +18 -0
- package/api/types/FilterDeployments.ts +19 -0
- package/api/types/FilterInventory.ts +20 -0
- package/api/types/FilterPredicate.ts +78 -0
- package/api/types/FilterPredicateDeployments.ts +48 -0
- package/api/types/FilterPredicateInventory.ts +76 -0
- package/api/types/GeoBoundingBox.ts +10 -0
- package/api/types/GeoBoundingBoxFilter.ts +6 -0
- package/api/types/GeoDistance.ts +17 -0
- package/api/types/GeoDistanceFilter.ts +10 -0
- package/api/types/GeoPoint.ts +15 -0
- package/api/types/Group.ts +10 -0
- package/api/types/HTTP.ts +19 -0
- package/api/types/IdentityData.ts +25 -0
- package/api/types/InputParameter.ts +8 -0
- package/api/types/Integration.ts +24 -0
- package/api/types/JobStatus.ts +13 -0
- package/api/types/Limit.ts +21 -0
- package/api/types/LimitDeployments.ts +21 -0
- package/api/types/LimitDeviceauth.ts +10 -0
- package/api/types/LimitUseradm.ts +11 -0
- package/api/types/Limits.ts +11 -0
- package/api/types/LineDescriptor.ts +11 -0
- package/api/types/LogSubsystem.ts +23 -0
- package/api/types/LoginOptions.ts +18 -0
- package/api/types/ManagementAPIConfiguration.ts +5 -0
- package/api/types/MenderTypes.ts +183 -0
- package/api/types/MonitorConfiguration.ts +22 -0
- package/api/types/NewConfigurationDeployment.ts +15 -0
- package/api/types/NewConfigurationDeploymentResponse.ts +10 -0
- package/api/types/NewDeployment.ts +42 -0
- package/api/types/NewDeploymentForGroup.ts +33 -0
- package/api/types/NewDeploymentPhase.ts +37 -0
- package/api/types/NewDeploymentPhaseDeployments.ts +20 -0
- package/api/types/NewDeploymentV2.ts +31 -0
- package/api/types/NewTenant.ts +41 -0
- package/api/types/Object.ts +35 -0
- package/api/types/OwnUserUpdate.ts +21 -0
- package/api/types/PasswordResetCompletion.ts +17 -0
- package/api/types/PasswordResetRequest.ts +13 -0
- package/api/types/Permission.ts +21 -0
- package/api/types/PermissionObject.ts +14 -0
- package/api/types/PermissionSet.ts +22 -0
- package/api/types/PermissionSetWithScope.ts +15 -0
- package/api/types/PersonalAccessToken.ts +29 -0
- package/api/types/PersonalAccessTokenRequest.ts +18 -0
- package/api/types/Plan.ts +19 -0
- package/api/types/PlanBindingDetails.ts +13 -0
- package/api/types/PlanChangeRequest.ts +14 -0
- package/api/types/PlanLimits.ts +12 -0
- package/api/types/PreAuthSet.ts +16 -0
- package/api/types/Release.ts +32 -0
- package/api/types/ReleaseDeployments.ts +32 -0
- package/api/types/ReleaseUpdate.ts +13 -0
- package/api/types/Releases.ts +9 -0
- package/api/types/ReleasesDeleteError.ts +21 -0
- package/api/types/ReleasesDeployments.ts +9 -0
- package/api/types/Role.ts +19 -0
- package/api/types/RolePermission.ts +25 -0
- package/api/types/RolePermissionObject.ts +17 -0
- package/api/types/RoleUseradm.ts +19 -0
- package/api/types/SAMLMetadata.ts +21 -0
- package/api/types/Scope.ts +19 -0
- package/api/types/SelectAttribute.ts +17 -0
- package/api/types/ServiceSubsystem.ts +19 -0
- package/api/types/Settings.ts +23 -0
- package/api/types/SortCriteria.ts +30 -0
- package/api/types/SsoObject.ts +21 -0
- package/api/types/Status.ts +17 -0
- package/api/types/StatusDeviceauth.ts +18 -0
- package/api/types/StatusTenantadm.ts +19 -0
- package/api/types/StorageLimit.ts +17 -0
- package/api/types/SubscriptionData.ts +8 -0
- package/api/types/SupportRequest.ts +17 -0
- package/api/types/Tag.ts +27 -0
- package/api/types/Tags.ts +10 -0
- package/api/types/TaskResult.ts +13 -0
- package/api/types/TaskResultCLI.ts +10 -0
- package/api/types/TaskResultHTTPRequest.ts +8 -0
- package/api/types/TaskResultHTTPResponse.ts +10 -0
- package/api/types/Tenant.ts +38 -0
- package/api/types/TenantApiLimits.ts +12 -0
- package/api/types/TenantApiLimitsTenantadm.ts +12 -0
- package/api/types/TenantIdName.ts +14 -0
- package/api/types/TenantIdsData.ts +10 -0
- package/api/types/TenantInfo.ts +14 -0
- package/api/types/TenantShortInfo.ts +21 -0
- package/api/types/TenantTenantadm.ts +38 -0
- package/api/types/TenantsIdName.ts +6 -0
- package/api/types/Update.ts +17 -0
- package/api/types/UpdateDeployments.ts +18 -0
- package/api/types/UpdateFile.ts +13 -0
- package/api/types/UpdateFileDeployments.ts +13 -0
- package/api/types/UpdateTypes.ts +8 -0
- package/api/types/UpgradeCompleteRequest.ts +23 -0
- package/api/types/User.ts +13 -0
- package/api/types/UserAuditlogs.ts +13 -0
- package/api/types/UserNew.ts +26 -0
- package/api/types/UserUpdate.ts +25 -0
- package/api/types/UserUseradm.ts +45 -0
- package/api/types/UserWithTenantInfo.ts +8 -0
- package/api/types/XDeltaArgs.ts +9 -0
- package/api/types/XDeltaArgsDeployments.ts +9 -0
- package/api/types/XDeltaArgsLimits.ts +10 -0
- package/api/types/XDeltaArgsLimitsDeployments.ts +10 -0
- package/api/users-api.ts +34 -0
- package/appSlice/constants.ts +166 -0
- package/appSlice/index.ts +159 -0
- package/appSlice/reducer.test.ts +97 -0
- package/appSlice/selectors.ts +33 -0
- package/appSlice/thunks.test.ts +118 -0
- package/appSlice/thunks.ts +148 -0
- package/auth.test.ts +36 -0
- package/auth.ts +82 -0
- package/commonConstants.tsx +252 -0
- package/commonSelectors.ts +255 -0
- package/constants.ts +22 -0
- package/deploymentsSlice/constants.ts +175 -0
- package/deploymentsSlice/index.ts +145 -0
- package/deploymentsSlice/reducer.test.ts +108 -0
- package/deploymentsSlice/selectors.ts +58 -0
- package/deploymentsSlice/thunks.test.ts +425 -0
- package/deploymentsSlice/thunks.ts +382 -0
- package/devicesSlice/constants.ts +56 -0
- package/devicesSlice/index.ts +207 -0
- package/devicesSlice/reducer.test.ts +194 -0
- package/devicesSlice/selectors.ts +127 -0
- package/devicesSlice/thunks.test.tsx +1245 -0
- package/devicesSlice/thunks.tsx +1098 -0
- package/monitorSlice/constants.ts +17 -0
- package/monitorSlice/index.ts +65 -0
- package/monitorSlice/reducer.test.ts +79 -0
- package/monitorSlice/selectors.ts +15 -0
- package/monitorSlice/thunks.test.ts +112 -0
- package/monitorSlice/thunks.ts +101 -0
- package/onboardingSlice/constants.ts +53 -0
- package/onboardingSlice/index.ts +60 -0
- package/onboardingSlice/reducer.test.ts +45 -0
- package/onboardingSlice/selectors.ts +15 -0
- package/onboardingSlice/thunks.test.ts +235 -0
- package/onboardingSlice/thunks.ts +142 -0
- package/organizationSlice/constants.ts +82 -0
- package/organizationSlice/index.ts +111 -0
- package/organizationSlice/reducer.test.ts +78 -0
- package/organizationSlice/selectors.ts +45 -0
- package/organizationSlice/thunks.test.ts +619 -0
- package/organizationSlice/thunks.ts +383 -0
- package/package.json +38 -0
- package/releasesSlice/constants.ts +18 -0
- package/releasesSlice/index.ts +116 -0
- package/releasesSlice/reducer.test.ts +78 -0
- package/releasesSlice/selectors.ts +33 -0
- package/releasesSlice/thunks.test.ts +389 -0
- package/releasesSlice/thunks.ts +379 -0
- package/selectors.ts +22 -0
- package/store.ts +89 -0
- package/storehooks.test.tsx +386 -0
- package/storehooks.ts +250 -0
- package/thunks.ts +21 -0
- package/tsconfig.json +11 -0
- package/tsup.config.ts +11 -0
- package/usersSlice/constants.ts +374 -0
- package/usersSlice/index.ts +151 -0
- package/usersSlice/reducer.test.ts +141 -0
- package/usersSlice/selectors.ts +60 -0
- package/usersSlice/thunks.test.ts +660 -0
- package/usersSlice/thunks.ts +773 -0
- package/utils.test.ts +187 -0
- package/utils.ts +249 -0
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
// Copyright 2024 Northern.tech AS
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
14
|
+
// @ts-nocheck
|
|
15
|
+
|
|
16
|
+
/*eslint import/namespace: ['error', { allowComputed: true }]*/
|
|
17
|
+
import reducer, { actions, initialState } from '.';
|
|
18
|
+
import { defaultState } from '../../../../tests/mockData';
|
|
19
|
+
import { DEVICE_STATES } from './constants';
|
|
20
|
+
|
|
21
|
+
describe('device reducer', () => {
|
|
22
|
+
it('should return the initial state', async () => {
|
|
23
|
+
expect(reducer(undefined, {})).toEqual(initialState);
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it('should handle RECEIVE_GROUPS', async () => {
|
|
27
|
+
expect(reducer(undefined, { type: actions.receivedGroups, payload: defaultState.devices.groups.byId }).groups.byId).toEqual(
|
|
28
|
+
defaultState.devices.groups.byId
|
|
29
|
+
);
|
|
30
|
+
expect(reducer(initialState, { type: actions.receivedGroups, payload: defaultState.devices.groups.byId }).groups.byId).toEqual(
|
|
31
|
+
defaultState.devices.groups.byId
|
|
32
|
+
);
|
|
33
|
+
expect(
|
|
34
|
+
reducer(initialState, { type: actions.receivedGroups, payload: { testExtra: { deviceIds: [], total: 0, filters: [] } } }).groups.byId.testExtra
|
|
35
|
+
).toEqual({
|
|
36
|
+
deviceIds: [],
|
|
37
|
+
total: 0,
|
|
38
|
+
filters: []
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
it('should handle RECEIVE_GROUP_DEVICES', async () => {
|
|
42
|
+
expect(
|
|
43
|
+
reducer(undefined, {
|
|
44
|
+
type: actions.addGroup,
|
|
45
|
+
payload: {
|
|
46
|
+
groupName: 'testGroupDynamic',
|
|
47
|
+
group: defaultState.devices.groups.byId.testGroupDynamic
|
|
48
|
+
}
|
|
49
|
+
}).groups.byId.testGroupDynamic
|
|
50
|
+
).toEqual(defaultState.devices.groups.byId.testGroupDynamic);
|
|
51
|
+
expect(
|
|
52
|
+
reducer(initialState, {
|
|
53
|
+
type: actions.addGroup,
|
|
54
|
+
payload: {
|
|
55
|
+
groupName: 'testGroupDynamic',
|
|
56
|
+
group: defaultState.devices.groups.byId.testGroupDynamic
|
|
57
|
+
}
|
|
58
|
+
}).groups.byId.testGroupDynamic
|
|
59
|
+
).toEqual(defaultState.devices.groups.byId.testGroupDynamic);
|
|
60
|
+
});
|
|
61
|
+
it('should handle RECEIVE_DYNAMIC_GROUPS', async () => {
|
|
62
|
+
expect(reducer(undefined, { type: actions.receivedGroups, payload: defaultState.devices.groups.byId }).groups.byId).toEqual(
|
|
63
|
+
defaultState.devices.groups.byId
|
|
64
|
+
);
|
|
65
|
+
expect(reducer(initialState, { type: actions.receivedGroups, payload: defaultState.devices.groups.byId }).groups.byId).toEqual(
|
|
66
|
+
defaultState.devices.groups.byId
|
|
67
|
+
);
|
|
68
|
+
expect(
|
|
69
|
+
reducer(initialState, { type: actions.receivedGroups, payload: { testExtra: { deviceIds: [], total: 0, filters: [] } } }).groups.byId.testExtra
|
|
70
|
+
).toEqual({ deviceIds: [], total: 0, filters: [] });
|
|
71
|
+
});
|
|
72
|
+
it('should handle ADD_TO_GROUP', async () => {
|
|
73
|
+
let state = reducer(undefined, { type: actions.receivedGroups, payload: defaultState.devices.groups.byId });
|
|
74
|
+
expect(reducer(state, { type: actions.addToGroup, payload: { group: 'testExtra', deviceIds: ['d1'] } }).groups.byId.testExtra.deviceIds).toHaveLength(1);
|
|
75
|
+
expect(
|
|
76
|
+
reducer(initialState, { type: actions.addToGroup, payload: { group: 'testGroup', deviceIds: ['123', '1243'] } }).groups.byId.testGroup.deviceIds
|
|
77
|
+
).toHaveLength(2);
|
|
78
|
+
});
|
|
79
|
+
it('should handle REMOVE_FROM_GROUP', async () => {
|
|
80
|
+
let state = reducer(undefined, { type: actions.receivedGroups, payload: defaultState.devices.groups.byId });
|
|
81
|
+
state = reducer(state, { type: actions.selectGroup, payload: 'testGroup' });
|
|
82
|
+
expect(
|
|
83
|
+
reducer(state, { type: actions.removeFromGroup, payload: { group: 'testGroup', deviceIds: [defaultState.devices.groups.byId.testGroup.deviceIds[0]] } })
|
|
84
|
+
.groups.byId.testGroup.deviceIds
|
|
85
|
+
).toHaveLength(defaultState.devices.groups.byId.testGroup.deviceIds.length - 1);
|
|
86
|
+
expect(
|
|
87
|
+
reducer(state, { type: actions.removeFromGroup, payload: { group: 'testGroup', deviceIds: defaultState.devices.groups.byId.testGroup.deviceIds } }).groups
|
|
88
|
+
.byId.testGroup
|
|
89
|
+
).toBeFalsy();
|
|
90
|
+
expect(
|
|
91
|
+
reducer(initialState, { type: actions.removeFromGroup, payload: { group: 'testExtra', deviceIds: ['123', '1243'] } }).groups.byId.testExtra
|
|
92
|
+
).toBeFalsy();
|
|
93
|
+
});
|
|
94
|
+
it('should handle ADD_DYNAMIC_GROUP', async () => {
|
|
95
|
+
expect(
|
|
96
|
+
reducer(undefined, { type: actions.addGroup, payload: { groupName: 'test', group: { something: 'test' } } }).groups.byId.test.something
|
|
97
|
+
).toBeTruthy();
|
|
98
|
+
expect(
|
|
99
|
+
reducer(initialState, { type: actions.addGroup, payload: { groupName: 'test', group: { something: 'test' } } }).groups.byId.test.something
|
|
100
|
+
).toBeTruthy();
|
|
101
|
+
});
|
|
102
|
+
it('should handle ADD_STATIC_GROUP', async () => {
|
|
103
|
+
expect(
|
|
104
|
+
reducer(undefined, { type: actions.addGroup, payload: { groupName: 'test', group: { something: 'test' } } }).groups.byId.test.something
|
|
105
|
+
).toBeTruthy();
|
|
106
|
+
expect(
|
|
107
|
+
reducer(initialState, { type: actions.addGroup, payload: { groupName: 'test', group: { something: 'test' } } }).groups.byId.test.something
|
|
108
|
+
).toBeTruthy();
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
it('should handle REMOVE_DYNAMIC_GROUP', async () => {
|
|
112
|
+
let state = reducer(undefined, { type: actions.receivedGroups, payload: defaultState.devices.groups.byId });
|
|
113
|
+
expect(Object.keys(reducer(state, { type: actions.removeGroup, payload: 'testGroupDynamic' }).groups.byId)).toHaveLength(
|
|
114
|
+
Object.keys(defaultState.devices.groups.byId).length - 1
|
|
115
|
+
);
|
|
116
|
+
expect(Object.keys(reducer(initialState, { type: actions.removeGroup, payload: 'testGroupDynamic' }).groups.byId)).toHaveLength(0);
|
|
117
|
+
});
|
|
118
|
+
it('should handle REMOVE_STATIC_GROUP', async () => {
|
|
119
|
+
let state = reducer(undefined, { type: actions.receivedGroups, payload: defaultState.devices.groups.byId });
|
|
120
|
+
expect(Object.keys(reducer(state, { type: actions.removeGroup, payload: 'testGroup' }).groups.byId)).toHaveLength(
|
|
121
|
+
Object.keys(defaultState.devices.groups.byId).length - 1
|
|
122
|
+
);
|
|
123
|
+
expect(Object.keys(reducer(initialState, { type: actions.removeGroup, payload: 'testGroup' }).groups.byId)).toHaveLength(0);
|
|
124
|
+
});
|
|
125
|
+
it('should handle SET_DEVICE_LIST_STATE', async () => {
|
|
126
|
+
expect(reducer(undefined, { type: actions.setDeviceListState, payload: { deviceIds: ['test'] } }).deviceList.deviceIds).toEqual(['test']);
|
|
127
|
+
expect(reducer(initialState, { type: actions.setDeviceListState, payload: { deviceIds: ['test'] } }).deviceList.deviceIds).toEqual(['test']);
|
|
128
|
+
});
|
|
129
|
+
it('should handle SET_DEVICE_FILTERS', async () => {
|
|
130
|
+
expect(reducer(undefined, { type: actions.setDeviceFilters, payload: defaultState.devices.groups.byId.testGroupDynamic.filters }).filters).toHaveLength(1);
|
|
131
|
+
expect(reducer(initialState, { type: actions.setDeviceFilters, payload: [{ key: 'test', operator: 'test' }] }).filters).toHaveLength(0);
|
|
132
|
+
});
|
|
133
|
+
it('should handle SET_FILTERABLES_CONFIG', async () => {
|
|
134
|
+
expect(reducer(undefined, { type: actions.setFilterablesConfig, payload: { attributes: { asd: true } } }).filteringAttributesConfig).toEqual({
|
|
135
|
+
attributes: { asd: true },
|
|
136
|
+
count: undefined,
|
|
137
|
+
limit: undefined
|
|
138
|
+
});
|
|
139
|
+
expect(
|
|
140
|
+
reducer(initialState, { type: actions.setFilterablesConfig, payload: { attributes: { asd: true }, count: 1, limit: 10 } }).filteringAttributesConfig
|
|
141
|
+
).toEqual({ attributes: { asd: true }, count: 1, limit: 10 });
|
|
142
|
+
});
|
|
143
|
+
it('should handle SET_FILTER_ATTRIBUTES', async () => {
|
|
144
|
+
expect(reducer(undefined, { type: actions.setFilterAttributes, payload: { things: '12' } }).filteringAttributes).toEqual({ things: '12' });
|
|
145
|
+
expect(reducer(initialState, { type: actions.setFilterAttributes, payload: { things: '12' } }).filteringAttributes).toEqual({ things: '12' });
|
|
146
|
+
});
|
|
147
|
+
it('should handle SET_TOTAL_DEVICES', async () => {
|
|
148
|
+
expect(reducer(undefined, { type: actions.setTotalDevices, payload: 2 }).total).toEqual(2);
|
|
149
|
+
expect(reducer(initialState, { type: actions.setTotalDevices, payload: 4 }).total).toEqual(4);
|
|
150
|
+
});
|
|
151
|
+
it('should handle SET_DEVICE_LIMIT', async () => {
|
|
152
|
+
expect(reducer(undefined, { type: actions.setDeviceLimit, payload: 500 }).limit).toEqual(500);
|
|
153
|
+
expect(reducer(initialState, { type: actions.setDeviceLimit, payload: 200 }).limit).toEqual(200);
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
it('should handle RECEIVE_DEVICE', async () => {
|
|
157
|
+
expect(reducer(undefined, { type: actions.receivedDevice, payload: defaultState.devices.byId.b1 }).byId.b1).toEqual(defaultState.devices.byId.b1);
|
|
158
|
+
expect(reducer(initialState, { type: actions.receivedDevice, payload: defaultState.devices.byId.b1 }).byId).not.toBe({});
|
|
159
|
+
});
|
|
160
|
+
it('should handle RECEIVE_DEVICES', async () => {
|
|
161
|
+
expect(reducer(undefined, { type: actions.receivedDevices, payload: defaultState.devices.byId }).byId).toEqual(defaultState.devices.byId);
|
|
162
|
+
expect(reducer(initialState, { type: actions.receivedDevices, payload: defaultState.devices.byId }).byId).toEqual(defaultState.devices.byId);
|
|
163
|
+
});
|
|
164
|
+
it('should handle SET_INACTIVE_DEVICES', async () => {
|
|
165
|
+
expect(
|
|
166
|
+
reducer(undefined, { type: actions.setInactiveDevices, payload: { activeDeviceTotal: 1, inactiveDeviceTotal: 1 } }).byStatus.active.total
|
|
167
|
+
).toBeTruthy();
|
|
168
|
+
expect(
|
|
169
|
+
reducer(initialState, { type: actions.setInactiveDevices, payload: { activeDeviceTotal: 1, inactiveDeviceTotal: 1 } }).byStatus.inactive.total
|
|
170
|
+
).toEqual(1);
|
|
171
|
+
});
|
|
172
|
+
it('should handle SET_DEVICE_REPORTS', async () => {
|
|
173
|
+
expect(reducer(undefined, { type: actions.setDeviceReports, payload: [1, 2, 3] }).reports).toHaveLength(3);
|
|
174
|
+
expect(reducer(initialState, { type: actions.setDeviceReports, payload: [{ something: 'here' }] }).reports).toEqual([{ something: 'here' }]);
|
|
175
|
+
});
|
|
176
|
+
it('should handle SET_<authstatus>_DEVICES', async () => {
|
|
177
|
+
Object.values(DEVICE_STATES).forEach(status => {
|
|
178
|
+
expect(reducer(undefined, { type: actions.setDevicesByStatus, payload: { deviceIds: ['a1'], total: 1, status } }).byStatus[status]).toEqual({
|
|
179
|
+
deviceIds: ['a1'],
|
|
180
|
+
total: 1
|
|
181
|
+
});
|
|
182
|
+
expect(reducer(initialState, { type: actions.setDevicesByStatus, payload: { deviceIds: ['a1'], status } }).byStatus[status]).toEqual({
|
|
183
|
+
deviceIds: [],
|
|
184
|
+
total: 0
|
|
185
|
+
});
|
|
186
|
+
});
|
|
187
|
+
});
|
|
188
|
+
it('should handle SET_<authstatus>_DEVICES_COUNT', async () => {
|
|
189
|
+
Object.values(DEVICE_STATES).forEach(status => {
|
|
190
|
+
expect(reducer(undefined, { type: actions.setDevicesCountByStatus, payload: { count: 1, status } }).byStatus[status].total).toEqual(1);
|
|
191
|
+
expect(reducer(initialState, { type: actions.setDevicesCountByStatus, payload: { count: 1, status } }).byStatus[status].total).toEqual(1);
|
|
192
|
+
});
|
|
193
|
+
});
|
|
194
|
+
});
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
// Copyright 2023 Northern.tech AS
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
14
|
+
// @ts-nocheck
|
|
15
|
+
import { DEVICE_STATES, UNGROUPED_GROUP } from '@northern.tech/store/constants';
|
|
16
|
+
import { duplicateFilter } from '@northern.tech/utils/helpers';
|
|
17
|
+
import { createSelector } from '@reduxjs/toolkit';
|
|
18
|
+
|
|
19
|
+
export const getAcceptedDevices = state => state.devices.byStatus.accepted;
|
|
20
|
+
export const getDevicesByStatus = state => state.devices.byStatus;
|
|
21
|
+
export const getDevicesById = state => state.devices.byId;
|
|
22
|
+
export const getDeviceReports = state => state.devices.reports;
|
|
23
|
+
export const getGroupsById = state => state.devices.groups.byId;
|
|
24
|
+
export const getSelectedGroup = state => state.devices.groups.selectedGroup;
|
|
25
|
+
|
|
26
|
+
export const getDeviceListState = state => state.devices.deviceList;
|
|
27
|
+
export const getListedDevices = state => state.devices.deviceList.deviceIds;
|
|
28
|
+
export const getFilteringAttributes = state => state.devices.filteringAttributes;
|
|
29
|
+
export const getDeviceFilters = state => state.devices.filters || [];
|
|
30
|
+
const getFilteringAttributesFromConfig = state => state.devices.filteringAttributesConfig.attributes;
|
|
31
|
+
export const getSortedFilteringAttributes = createSelector([getFilteringAttributes], filteringAttributes => ({
|
|
32
|
+
...filteringAttributes,
|
|
33
|
+
identityAttributes: [...filteringAttributes.identityAttributes, 'id']
|
|
34
|
+
}));
|
|
35
|
+
export const getDeviceLimit = state => state.devices.limit;
|
|
36
|
+
const getFilteringAttributesLimit = state => state.devices.filteringAttributesLimit;
|
|
37
|
+
|
|
38
|
+
export const getDeviceIdentityAttributes = createSelector(
|
|
39
|
+
[getFilteringAttributes, getFilteringAttributesLimit],
|
|
40
|
+
({ identityAttributes }, filteringAttributesLimit) => {
|
|
41
|
+
// limit the selection of the available attribute to AVAILABLE_ATTRIBUTE_LIMIT
|
|
42
|
+
const attributes = identityAttributes.slice(0, filteringAttributesLimit);
|
|
43
|
+
return attributes.reduce(
|
|
44
|
+
(accu, value) => {
|
|
45
|
+
accu.push({ value, label: value, scope: 'identity' });
|
|
46
|
+
return accu;
|
|
47
|
+
},
|
|
48
|
+
[
|
|
49
|
+
{ value: 'name', label: 'Name', scope: 'tags' },
|
|
50
|
+
{ value: 'id', label: 'Device ID', scope: 'identity' }
|
|
51
|
+
]
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
);
|
|
55
|
+
|
|
56
|
+
export const getDeviceCountsByStatus = createSelector([getDevicesByStatus], byStatus =>
|
|
57
|
+
Object.values(DEVICE_STATES).reduce((accu, state) => {
|
|
58
|
+
accu[state] = byStatus[state].total || 0;
|
|
59
|
+
return accu;
|
|
60
|
+
}, {})
|
|
61
|
+
);
|
|
62
|
+
|
|
63
|
+
export const getDeviceById = createSelector([getDevicesById, (_, deviceId) => deviceId], (devicesById, deviceId = '') => devicesById[deviceId] ?? {});
|
|
64
|
+
|
|
65
|
+
export const getSelectedGroupInfo = createSelector(
|
|
66
|
+
[getAcceptedDevices, getGroupsById, getSelectedGroup],
|
|
67
|
+
({ total: acceptedDeviceTotal }, groupsById, selectedGroup) => {
|
|
68
|
+
let groupCount = acceptedDeviceTotal;
|
|
69
|
+
let groupFilters = [];
|
|
70
|
+
if (selectedGroup && groupsById[selectedGroup]) {
|
|
71
|
+
groupCount = groupsById[selectedGroup].total;
|
|
72
|
+
groupFilters = groupsById[selectedGroup].filters || [];
|
|
73
|
+
}
|
|
74
|
+
return { groupCount, selectedGroup, groupFilters };
|
|
75
|
+
}
|
|
76
|
+
);
|
|
77
|
+
|
|
78
|
+
export const getLimitMaxed = createSelector([getAcceptedDevices, getDeviceLimit], ({ total: acceptedDevices = 0 }, deviceLimit) =>
|
|
79
|
+
Boolean(deviceLimit && deviceLimit <= acceptedDevices)
|
|
80
|
+
);
|
|
81
|
+
|
|
82
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
83
|
+
export const getGroupsByIdWithoutUngrouped = createSelector([getGroupsById], ({ [UNGROUPED_GROUP.id]: ungrouped, ...groups }) => groups);
|
|
84
|
+
|
|
85
|
+
export const getGroups = createSelector([getGroupsById], groupsById => {
|
|
86
|
+
const groupNames = Object.keys(groupsById).sort();
|
|
87
|
+
const groupedGroups = Object.entries(groupsById)
|
|
88
|
+
.sort((a, b) => a[0].localeCompare(b[0]))
|
|
89
|
+
.reduce(
|
|
90
|
+
(accu, [groupname, group]) => {
|
|
91
|
+
const name = groupname === UNGROUPED_GROUP.id ? UNGROUPED_GROUP.name : groupname;
|
|
92
|
+
const groupItem = { ...group, groupId: name, name: groupname };
|
|
93
|
+
if (group.filters.length > 0) {
|
|
94
|
+
if (groupname !== UNGROUPED_GROUP.id) {
|
|
95
|
+
accu.dynamic.push(groupItem);
|
|
96
|
+
} else {
|
|
97
|
+
accu.ungrouped.push(groupItem);
|
|
98
|
+
}
|
|
99
|
+
} else {
|
|
100
|
+
accu.static.push(groupItem);
|
|
101
|
+
}
|
|
102
|
+
return accu;
|
|
103
|
+
},
|
|
104
|
+
{ dynamic: [], static: [], ungrouped: [] }
|
|
105
|
+
);
|
|
106
|
+
return { groupNames, ...groupedGroups };
|
|
107
|
+
});
|
|
108
|
+
export const getAttributesList = createSelector(
|
|
109
|
+
[getFilteringAttributes, getFilteringAttributesFromConfig],
|
|
110
|
+
({ identityAttributes = [], inventoryAttributes = [] }, { identity = [], inventory = [] }) =>
|
|
111
|
+
[...identityAttributes, ...inventoryAttributes, ...identity, ...inventory].filter(duplicateFilter)
|
|
112
|
+
);
|
|
113
|
+
|
|
114
|
+
export const getDeviceTypes = createSelector([getAcceptedDevices, getDevicesById], ({ deviceIds = [] }, devicesById) =>
|
|
115
|
+
Object.keys(
|
|
116
|
+
deviceIds.slice(0, 200).reduce((accu, item) => {
|
|
117
|
+
const { device_type: deviceTypes = [] } = devicesById[item] ? devicesById[item].attributes : {};
|
|
118
|
+
accu = deviceTypes.reduce((deviceTypeAccu, deviceType) => {
|
|
119
|
+
if (deviceType.length > 1) {
|
|
120
|
+
deviceTypeAccu[deviceType] = deviceTypeAccu[deviceType] ? deviceTypeAccu[deviceType] + 1 : 1;
|
|
121
|
+
}
|
|
122
|
+
return deviceTypeAccu;
|
|
123
|
+
}, accu);
|
|
124
|
+
return accu;
|
|
125
|
+
}, {})
|
|
126
|
+
)
|
|
127
|
+
);
|