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

adobe / reactor-turbine-edge / 8443711332

26 Mar 2024 10:27PM UTC coverage: 94.005% (-5.0%) from 98.974%
8443711332

push

github

dompuiu
3.0.1

74 of 84 branches covered (88.1%)

Branch coverage included in aggregate %.

271 of 283 relevant lines covered (95.76%)

9761.78 hits per line

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

66.67
/src/createGetDataElementValue.js
1
/*
2
Copyright 2020 Adobe. All rights reserved.
3
This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
you may not use this file except in compliance with the License. You may obtain a copy
5
of the License at http://www.apache.org/licenses/LICENSE-2.0
6
Unless required by applicable law or agreed to in writing, software distributed under
7
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
8
OF ANY KIND, either express or implied. See the License for the specific language
9
governing permissions and limitations under the License.
10
*/
11

12
const cleanTextFn = require('./cleanText');
2✔
13
const normalizeDelegate = require('./rules/normalizeDelegate');
2✔
14
const getExecuteModulePromise = require('./rules/getExecuteModulePromise');
2✔
15

16
const enhanceErrorMessage = (dataElementName, e) => {
2✔
17
  e.message = `Failed to execute module for data element "${dataElementName}". ${e.message}`;
×
18
};
19

20
module.exports =
2✔
21
  (moduleProvider, getDataElementDefinition) => (dataElementName, context) => {
2✔
22
    const {
23
      dataElementCallStack = [],
1✔
24
      arcAndUtils: {
25
        utils: { logger }
26
      }
27
    } = context;
3✔
28

29
    const dataDef = getDataElementDefinition(dataElementName);
3✔
30

31
    if (!dataDef) {
3!
32
      return Promise.reject(
×
33
        new Error(
34
          `Data element definition for "${dataElementName}" was not found.`
35
        )
36
      );
37
    }
38

39
    if (dataElementCallStack.includes(dataElementName)) {
3!
40
      dataElementCallStack.push(dataElementName);
×
41

42
      return Promise.reject(
×
43
        new Error(
44
          `Data element circular reference detected: ${dataElementCallStack.join(
45
            ' -> '
46
          )}`
47
        )
48
      );
49
    }
50
    dataElementCallStack.push(dataElementName);
3✔
51

52
    const { defaultValue, cleanText, forceLowerCase } = dataDef;
3✔
53

54
    logger.log(`Resolving the data element "${dataElementName}".`);
3✔
55
    return getExecuteModulePromise({
3✔
56
      ...context,
57
      delegateConfig: normalizeDelegate(dataDef, moduleProvider)
58
    })
59
      .then((c) => {
60
        let { moduleOutput: value } = c;
3✔
61

62
        if (value == null && defaultValue != null) {
3!
63
          value = defaultValue;
×
64
        }
65

66
        if (typeof value === 'string') {
3✔
67
          if (cleanText) {
2!
68
            value = cleanTextFn(value);
×
69
          }
70

71
          if (forceLowerCase) {
2!
72
            value = value.toLowerCase();
×
73
          }
74
        }
75

76
        logger.log(
3✔
77
          `The "${dataElementName}" data element value is "${value}".`
78
        );
79
        return value;
3✔
80
      })
81
      .catch((e) => {
82
        enhanceErrorMessage(dataElementName, e);
×
83
        throw e;
×
84
      });
85
  };
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