• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mendersoftware / mender-server / 1593965839

18 Dec 2024 10:58AM UTC coverage: 73.514% (+0.7%) from 72.829%
1593965839

Pull #253

gitlab-ci

mineralsfree
chore(gui): aligned tests with edit billing profile

Ticket: MEN-7466
Changelog: None

Signed-off-by: Mikita Pilinka <mikita.pilinka@northern.tech>
Pull Request #253: MEN-7466-feat: updated billing section in My Organization settings

4257 of 6185 branches covered (68.83%)

Branch coverage included in aggregate %.

53 of 87 new or added lines in 11 files covered. (60.92%)

43 existing lines in 11 files now uncovered.

40083 of 54130 relevant lines covered (74.05%)

22.98 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

73.44
/frontend/src/js/store/monitorSlice/thunks.ts
1
// Copyright 2021 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 storeActions from '@northern.tech/store/actions';
16
import Api from '@northern.tech/store/api/general-api';
17
import { DEVICE_LIST_DEFAULTS, TIMEOUTS, alertChannels, headerNames } from '@northern.tech/store/constants';
18
import { getDeviceFilters, getSearchEndpoint } from '@northern.tech/store/selectors';
19
import { commonErrorFallback, commonErrorHandler } from '@northern.tech/store/store';
20
import { convertDeviceListStateToFilters } from '@northern.tech/store/utils';
21
import { createAsyncThunk } from '@reduxjs/toolkit';
22

23
import { actions, sliceName } from '.';
24
import { monitorApiUrlv1 } from './constants';
25

26
const { page: defaultPage, perPage: defaultPerPage } = DEVICE_LIST_DEFAULTS;
111✔
27

28
const cutoffLength = 75;
111✔
29
const ellipsis = '...';
111✔
30
const longTextTrimmer = text => (text.length >= cutoffLength + ellipsis.length ? `${text.substring(0, cutoffLength + ellipsis.length)}${ellipsis}` : text);
111!
31

32
const sanitizeDeviceAlerts = alerts => alerts.map(alert => ({ ...alert, fullName: alert.name, name: longTextTrimmer(alert.name) }));
111✔
33

34
export const getDeviceAlerts = createAsyncThunk(`${sliceName}/getDeviceAlerts`, ({ id, config = {} }, { dispatch }) => {
111✔
35
  const { page = defaultPage, perPage = defaultPerPage, issuedBefore, issuedAfter, sortAscending = false } = config;
1✔
36
  const issued_after = issuedAfter ? `&issued_after=${issuedAfter}` : '';
1!
37
  const issued_before = issuedBefore ? `&issued_before=${issuedBefore}` : '';
1!
38
  return Api.get(`${monitorApiUrlv1}/devices/${id}/alerts?page=${page}&per_page=${perPage}${issued_after}${issued_before}&sort_ascending=${sortAscending}`)
1✔
39
    .catch(err => commonErrorHandler(err, `Retrieving device alerts for device ${id} failed:`, dispatch))
×
40
    .then(res =>
41
      Promise.all([
1✔
42
        dispatch(actions.receiveDeviceAlerts({ deviceId: id, alerts: sanitizeDeviceAlerts(res.data) })),
43
        dispatch(actions.setAlertListState({ total: Number(res.headers[headerNames.total]) }))
44
      ])
45
    );
46
});
47

48
export const getLatestDeviceAlerts = createAsyncThunk(`${sliceName}/getLatestDeviceAlerts`, ({ id, config = {} }, { dispatch }) => {
111✔
49
  const { page = defaultPage, perPage = 10 } = config;
1✔
50
  return Api.get(`${monitorApiUrlv1}/devices/${id}/alerts/latest?page=${page}&per_page=${perPage}`)
1✔
51
    .catch(err => commonErrorHandler(err, `Retrieving device alerts for device ${id} failed:`, dispatch))
×
52
    .then(res => Promise.resolve(dispatch(actions.receiveLatestDeviceAlerts({ deviceId: id, alerts: sanitizeDeviceAlerts(res.data) }))));
1✔
53
});
54

55
export const getIssueCountsByType = createAsyncThunk(`${sliceName}/getIssueCountsByType`, ({ type, options = {} }, { dispatch, getState }) => {
111✔
56
  const state = getState();
5✔
57
  const { filters = getDeviceFilters(state), group, status, ...remainder } = options;
5✔
58
  const { applicableFilters: nonMonitorFilters, filterTerms } = convertDeviceListStateToFilters({
5✔
59
    ...remainder,
60
    filters,
61
    group,
62
    offlineThreshold: state.app.offlineThreshold,
63
    selectedIssues: [type],
64
    status
65
  });
66
  return Api.post(getSearchEndpoint(getState()), {
1✔
67
    page: 1,
68
    per_page: 1,
69
    filters: filterTerms,
70
    attributes: [{ scope: 'identity', attribute: 'status' }]
71
  })
72
    .catch(err => commonErrorHandler(err, `Retrieving issue counts failed:`, dispatch, commonErrorFallback))
×
73
    .then(res => {
74
      const total = nonMonitorFilters.length ? state.monitor.issueCounts.byType[type].total : Number(res.headers[headerNames.total]);
1!
75
      const filtered = nonMonitorFilters.length ? Number(res.headers[headerNames.total]) : total;
1!
76
      if (total === state.monitor.issueCounts.byType[type].total && filtered === state.monitor.issueCounts.byType[type].filtered) {
1!
UNCOV
77
        return Promise.resolve();
×
78
      }
79
      return Promise.resolve(dispatch(actions.receiveDeviceIssueCounts({ counts: { filtered, total }, issueType: type })));
1✔
80
    });
81
});
82

83
export const getDeviceMonitorConfig = createAsyncThunk(`${sliceName}/getDeviceMonitorConfig`, (id, { dispatch }) =>
111✔
84
  Api.get(`${monitorApiUrlv1}/devices/${id}/config`)
1✔
85
    .catch(err => commonErrorHandler(err, `Retrieving device monitor config for device ${id} failed:`, dispatch))
×
86
    .then(({ data }) => Promise.all([dispatch(storeActions.receivedDevice({ id, monitors: data }), Promise.resolve(data))]))
1✔
87
);
88

89
export const changeNotificationSetting = createAsyncThunk(
111✔
90
  `${sliceName}/changeNotificationSetting`,
91
  ({ enabled, channel = alertChannels.email }, { dispatch }) => {
1✔
92
    return Api.put(`${monitorApiUrlv1}/settings/global/channel/alerts/${channel}/status`, { enabled })
1✔
93
      .catch(err => commonErrorHandler(err, `${enabled ? 'En' : 'Dis'}abling  ${channel} alerts failed:`, dispatch))
×
94
      .then(() =>
95
        Promise.all([
1✔
96
          dispatch(actions.changeAlertChannel({ channel, enabled })),
97
          dispatch(storeActions.setSnackbar(`Successfully ${enabled ? 'en' : 'dis'}abled ${channel} alerts`, TIMEOUTS.fiveSeconds))
1!
98
        ])
99
      );
100
  }
101
);
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc