Feat: code refactoring and jest tests
chore: More refactoring chore: More tests and refactors fix: Fixed age not getting calculated properly chore: Implemented mocking in jest chore: More mock tests chore: checkStuckScreen tests
This commit is contained in:
parent
65165b943b
commit
04fd82454d
12 changed files with 1047 additions and 66 deletions
53
lib/notifier/sms.js
Normal file
53
lib/notifier/sms.js
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
const _ = require('lodash/fp')
|
||||
const utils = require('./utils')
|
||||
|
||||
function printSmsAlerts(alertRec, config) {
|
||||
let alerts = []
|
||||
|
||||
if (config.balance) {
|
||||
alerts = _.concat(alerts, alertRec.general)
|
||||
}
|
||||
|
||||
_.keys(alertRec.devices).forEach(function (device) {
|
||||
if (config.balance) {
|
||||
alerts = _.concat(alerts, alertRec.devices[device].balanceAlerts)
|
||||
}
|
||||
|
||||
if (config.errors) {
|
||||
alerts = _.concat(alerts, alertRec.devices[device].deviceAlerts)
|
||||
}
|
||||
})
|
||||
|
||||
if (alerts.length === 0) return null
|
||||
|
||||
const alertsMap = _.groupBy('code', alerts)
|
||||
|
||||
const alertTypes = _.map(entry => {
|
||||
const code = entry[0]
|
||||
const machineNames = _.filter(
|
||||
_.negate(_.isEmpty),
|
||||
_.map('machineName', entry[1])
|
||||
)
|
||||
|
||||
return {
|
||||
codeDisplay: utils.codeDisplay(code),
|
||||
machineNames
|
||||
}
|
||||
}, _.toPairs(alertsMap))
|
||||
|
||||
const mapByCodeDisplay = _.map(it =>
|
||||
_.isEmpty(it.machineNames)
|
||||
? it.codeDisplay
|
||||
: `${it.codeDisplay} (${it.machineNames.join(', ')})`
|
||||
)
|
||||
|
||||
const displayAlertTypes = _.compose(
|
||||
_.uniq,
|
||||
mapByCodeDisplay,
|
||||
_.sortBy('codeDisplay')
|
||||
)(alertTypes)
|
||||
|
||||
return '[Lamassu] Errors reported: ' + displayAlertTypes.join(', ')
|
||||
}
|
||||
|
||||
module.exports = { printSmsAlerts }
|
||||
Loading…
Add table
Add a link
Reference in a new issue