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

GrottoCenter / grottocenter-api / 25556392557

08 May 2026 12:47PM UTC coverage: 86.268% (-0.2%) from 86.497%
25556392557

Pull #1566

github

dawoldo
test(1451): updated tests
Pull Request #1566: 1451 private messaging

3047 of 3681 branches covered (82.78%)

Branch coverage included in aggregate %.

216 of 255 new or added lines in 16 files covered. (84.71%)

8 existing lines in 1 file now uncovered.

6370 of 7235 relevant lines covered (88.04%)

50.64 hits per line

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

90.12
/api/services/DataQualityComputeService.js
1
const CommonService = require('./CommonService');
2✔
2

3
/**
4
 * this service is used to retrieves the elements included
5
 * in the computation of the quality of the data of an entrance.
6
 */
7
const GET_ENTRANCES_WITH_QUALITY_BY_MASSIF = `
2✔
8
  SELECT *
9
  FROM v_data_quality_compute_entrance
10
  WHERE id_massif = $1
11
  LIMIT $2 OFFSET $3
12
`;
13

14
const GET_ENTRANCES_WITH_QUALITY_BY_COUNTRY = `
2✔
15
  SELECT DISTINCT id_entrance, general_latest_date_of_update, general_nb_contributions, location_latest_date_of_update, location_nb_contributions, description_latest_date_of_update, description_nb_contributions, document_latest_date_of_update, document_nb_contributions, rigging_latest_date_of_update, rigging_nb_contributions, history_latest_date_of_update, history_nb_contributions, comment_latest_date_of_update, comment_nb_contributions, entrance_name, id_country, country_name, date_of_update
16
  FROM v_data_quality_compute_entrance
17
  WHERE id_country = $1
18
  LIMIT $2 OFFSET $3
19
`;
20

21
const GET_ENTRANCES_WITH_QUALITY_BY_REGION = `
2✔
22
  SELECT DISTINCT v.id_entrance, v.general_latest_date_of_update, v.general_nb_contributions, v.location_latest_date_of_update, v.location_nb_contributions, v.description_latest_date_of_update, v.description_nb_contributions, v.document_latest_date_of_update, v.document_nb_contributions, v.rigging_latest_date_of_update, v.rigging_nb_contributions, v.history_latest_date_of_update, v.history_nb_contributions, v.comment_latest_date_of_update, v.comment_nb_contributions, v.entrance_name, v.id_country, v.country_name, v.date_of_update
23
  FROM v_data_quality_compute_entrance v
24
  JOIN t_entrance e ON v.id_entrance = e.id
25
  WHERE e.iso_3166_2 = $1
26
  LIMIT $2 OFFSET $3
27
`;
28

29
const COUNT_ENTRANCES_WITH_QUALITY_BY_MASSIF = `
2✔
30
  SELECT COUNT(*)
31
  FROM v_data_quality_compute_entrance
32
  WHERE id_massif = $1
33
`;
34

35
const COUNT_ENTRANCES_WITH_QUALITY_BY_COUNTRY = `
2✔
36
  SELECT COUNT(DISTINCT id_entrance)
37
  FROM v_data_quality_compute_entrance
38
  WHERE id_country = $1
39
`;
40

41
const COUNT_ENTRANCES_WITH_QUALITY_BY_REGION = `
2✔
42
  SELECT COUNT(DISTINCT v.id_entrance)
43
  FROM v_data_quality_compute_entrance v
44
  JOIN t_entrance e ON v.id_entrance = e.id
45
  WHERE e.iso_3166_2 = $1
46
`;
47

48
module.exports = {
2✔
49
  /**
50
   *
51
   * @param {int} massifId
52
   * @param {int} limit
53
   * @param {int} offset
54
   * @returns {Object} the date of the latest update and the number of contributions on all entrances in a massif
55
   *          or null if no result or something went wrong
56
   */
57
  getEntrancesWithQualityByMassif: async (
58
    massifId,
59
    limit = null,
3✔
60
    offset = null
3✔
61
  ) => {
62
    try {
8✔
63
      const params =
64
        limit !== null && offset !== null
8✔
65
          ? [massifId, limit, offset]
66
          : [massifId];
67
      const query =
68
        limit !== null && offset !== null
8✔
69
          ? GET_ENTRANCES_WITH_QUALITY_BY_MASSIF
70
          : GET_ENTRANCES_WITH_QUALITY_BY_MASSIF.replace(
71
              'LIMIT $2 OFFSET $3',
72
              ''
73
            );
74
      const queryResult = await CommonService.query(query, params);
8✔
75
      return queryResult.rows;
7✔
76
    } catch (e) {
77
      sails.log.error(e);
1✔
78
      return null;
1✔
79
    }
80
  },
81

82
  /**
83
   *
84
   * @param {int} massifId
85
   * @returns {int} count of entrances in massif
86
   */
87
  getEntrancesWithQualityByMassifCount: async (massifId) => {
88
    try {
7✔
89
      const queryResult = await CommonService.query(
7✔
90
        COUNT_ENTRANCES_WITH_QUALITY_BY_MASSIF,
91
        [massifId]
92
      );
93
      return parseInt(queryResult.rows[0].count, 10);
7✔
94
    } catch (e) {
UNCOV
95
      sails.log.error(e);
×
UNCOV
96
      return 0;
×
97
    }
98
  },
99

100
  /**
101
   *
102
   * @param {string} countryId alpha-2 code
103
   * @param {int} limit
104
   * @param {int} offset
105
   * @returns {Object} the date of the latest update and the number of contributions on all entrances in a country
106
   *          or null if no result or something went wrong
107
   */
108
  getEntrancesWithQualityByCountry: async (
109
    countryId,
110
    limit = null,
3✔
111
    offset = null
3✔
112
  ) => {
113
    try {
8✔
114
      const params =
115
        limit !== null && offset !== null
8✔
116
          ? [countryId, limit, offset]
117
          : [countryId];
118
      const query =
119
        limit !== null && offset !== null
8✔
120
          ? GET_ENTRANCES_WITH_QUALITY_BY_COUNTRY
121
          : GET_ENTRANCES_WITH_QUALITY_BY_COUNTRY.replace(
122
              'LIMIT $2 OFFSET $3',
123
              ''
124
            );
125
      const queryResult = await CommonService.query(query, params);
8✔
126
      return queryResult.rows;
7✔
127
    } catch (e) {
128
      sails.log.error(e);
1✔
129
      return null;
1✔
130
    }
131
  },
132

133
  /**
134
   *
135
   * @param {string} countryId alpha-2 code
136
   * @returns {int} count of entrances in country
137
   */
138
  getEntrancesWithQualityByCountryCount: async (countryId) => {
139
    try {
6✔
140
      const queryResult = await CommonService.query(
6✔
141
        COUNT_ENTRANCES_WITH_QUALITY_BY_COUNTRY,
142
        [countryId]
143
      );
144
      return parseInt(queryResult.rows[0].count, 10);
6✔
145
    } catch (e) {
UNCOV
146
      sails.log.error(e);
×
UNCOV
147
      return 0;
×
148
    }
149
  },
150

151
  /**
152
   *
153
   * @param {string} regionId ISO 3166-2 code (e.g., 'US-TN')
154
   * @param {int} limit
155
   * @param {int} offset
156
   * @returns {Object} the date of the latest update and the number of contributions on all entrances in a region
157
   *          or null if no result or something went wrong
158
   */
159
  getEntrancesWithQualityByRegion: async (
160
    regionId,
161
    limit = null,
3✔
162
    offset = null
3✔
163
  ) => {
164
    try {
12✔
165
      const params =
166
        limit !== null && offset !== null
12✔
167
          ? [regionId, limit, offset]
168
          : [regionId];
169
      const query =
170
        limit !== null && offset !== null
12✔
171
          ? GET_ENTRANCES_WITH_QUALITY_BY_REGION
172
          : GET_ENTRANCES_WITH_QUALITY_BY_REGION.replace(
173
              'LIMIT $2 OFFSET $3',
174
              ''
175
            );
176
      const queryResult = await CommonService.query(query, params);
12✔
177
      return queryResult.rows;
9✔
178
    } catch (e) {
179
      sails.log.error(e);
3✔
180
      return null;
3✔
181
    }
182
  },
183

184
  /**
185
   *
186
   * @param {string} regionId ISO 3166-2 code (e.g., 'US-TN')
187
   * @returns {int} count of entrances in region
188
   */
189
  getEntrancesWithQualityByRegionCount: async (regionId) => {
190
    try {
10✔
191
      const queryResult = await CommonService.query(
10✔
192
        COUNT_ENTRANCES_WITH_QUALITY_BY_REGION,
193
        [regionId]
194
      );
195
      return parseInt(queryResult.rows[0].count, 10);
10✔
196
    } catch (e) {
UNCOV
197
      sails.log.error(e);
×
UNCOV
198
      return 0;
×
199
    }
200
  },
201

202
  /**
203
   *
204
   * @param {number} entranceId
205
   * @returns {Object|null} the materialized view row, or null if not found
206
   */
207
  getEntranceQualityById: async (entranceId) => {
208
    try {
5✔
209
      const queryResult = await CommonService.query(
5✔
210
        'SELECT * FROM v_data_quality_compute_entrance WHERE id_entrance = $1 ORDER BY id_massif NULLS LAST LIMIT 1',
211
        [entranceId]
212
      );
213
      return queryResult.rows[0] || null;
5✔
214
    } catch (e) {
UNCOV
215
      sails.log.error(e);
×
UNCOV
216
      return null;
×
217
    }
218
  },
219
};
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

© 2026 Coveralls, Inc