chore: server code formatting

This commit is contained in:
Rafael Taranto 2025-05-12 15:35:00 +01:00
parent aedabcbdee
commit 68517170e2
234 changed files with 9824 additions and 6195 deletions

View file

@ -5,14 +5,14 @@ const alertRec = {
f02af604ca9010bd9ae04c427a24da90130da10d355f0a9b235886a89008fc05: {
balanceAlerts: [],
deviceAlerts: [
{ code: 'PING', age: 602784301.446, machineName: 'Abc123' }
]
}
{ code: 'PING', age: 602784301.446, machineName: 'Abc123' },
],
},
},
deviceNames: {
f02af604ca9010bd9ae04c427a24da90130da10d355f0a9b235886a89008fc05: 'Abc123'
f02af604ca9010bd9ae04c427a24da90130da10d355f0a9b235886a89008fc05: 'Abc123',
},
general: []
general: [],
}
const printEmailMsg = `Errors were reported by your Lamassu Machines.
@ -23,6 +23,6 @@ Machine down for ~6 days
test('Print Email Alers', () => {
expect(email.printEmailAlerts(alertRec, { active: true, errors: true })).toBe(
printEmailMsg
printEmailMsg,
)
})

View file

@ -20,7 +20,7 @@ const plugins = {
email_errors: false,
sms_errors: true,
sms: { active: true, errors: true },
email: { active: false, errors: false }
email: { active: false, errors: false },
}),
getMachineNames: () => [
{
@ -36,16 +36,15 @@ const plugins = {
name: 'Abc123',
paired: true,
cashOut: true,
statuses: [{ label: 'Unresponsive', type: 'error' }]
}
statuses: [{ label: 'Unresponsive', type: 'error' }],
},
],
checkBalances: () => []
checkBalances: () => [],
}
const tx = {
id: 'bec8d452-9ea2-4846-841b-55a9df8bbd00',
deviceId:
'490ab16ee0c124512dc769be1f3e7ee3894ce1e5b4b8b975e134fb326e551e88',
deviceId: '490ab16ee0c124512dc769be1f3e7ee3894ce1e5b4b8b975e134fb326e551e88',
toAddress: 'bc1q7s4yy5n9vp6zhlf6mrw3cttdgx5l3ysr2mhc4v',
cryptoAtoms: new BN(252100),
cryptoCode: 'BTC',
@ -71,7 +70,7 @@ const tx = {
commissionPercentage: new BN(0.11),
rawTickerPrice: new BN(18937.4),
isPaperWallet: false,
direction: 'cashIn'
direction: 'cashIn',
}
const notifSettings = {
@ -84,13 +83,13 @@ const notifSettings = {
sms: {
active: true,
errors: true,
transactions: false // force early return
transactions: false, // force early return
},
email: {
active: false,
errors: false,
transactions: false // force early return
}
transactions: false, // force early return
},
}
test('Exits checkNotifications with Promise.resolve() if SMS and Email are disabled', async () => {
@ -99,9 +98,9 @@ test('Exits checkNotifications with Promise.resolve() if SMS and Email are disab
notifier.checkNotification({
getNotificationConfig: () => ({
sms: { active: false, errors: false },
email: { active: false, errors: false }
})
})
email: { active: false, errors: false },
}),
}),
).resolves.toBe(undefined)
})
@ -111,9 +110,9 @@ test('Exits checkNotifications with Promise.resolve() if SMS and Email are disab
notifier.checkNotification({
getNotificationConfig: () => ({
sms: { active: false, errors: true, balance: true },
email: { active: false, errors: true, balance: true }
})
})
email: { active: false, errors: true, balance: true },
}),
}),
).resolves.toBe(undefined)
})
@ -124,13 +123,13 @@ test("Check Pings should return code PING for devices that haven't been pinged r
deviceId:
'7e531a2666987aa27b9917ca17df7998f72771c57fdb21c90bc033999edd17e4',
lastPing: '2020-11-16T13:11:03.169Z',
name: 'Abc123'
}
])
name: 'Abc123',
},
]),
).toMatchObject({
'7e531a2666987aa27b9917ca17df7998f72771c57fdb21c90bc033999edd17e4': [
{ code: 'PING', machineName: 'Abc123' }
]
{ code: 'PING', machineName: 'Abc123' },
],
})
})
@ -141,11 +140,11 @@ test('Checkpings returns empty array as the value for the id prop, if the lastPi
deviceId:
'7a531a2666987aa27b9917ca17df7998f72771c57fdb21c90bc033999edd17e4',
lastPing: new Date(),
name: 'Abc123'
}
])
name: 'Abc123',
},
]),
).toMatchObject({
'7a531a2666987aa27b9917ca17df7998f72771c57fdb21c90bc033999edd17e4': []
'7a531a2666987aa27b9917ca17df7998f72771c57fdb21c90bc033999edd17e4': [],
})
})
@ -203,7 +202,7 @@ test('checkStuckScreen returns [] if most recent event is idle', () => {
note: '{"state":"chooseCoin","isIdle":false}',
created: '2020-11-23T19:30:29.209Z',
device_time: '1999-11-23T19:30:29.177Z',
age: 157352628.123
age: 157352628.123,
},
{
id: '48ae51c6-c5b4-485e-b81d-aa337fc025e2',
@ -213,9 +212,9 @@ test('checkStuckScreen returns [] if most recent event is idle', () => {
note: '{"state":"chooseCoin","isIdle":true}',
created: '2020-11-23T19:30:29.209Z',
device_time: '2020-11-23T19:30:29.177Z',
age: 157352628.123
}
])
age: 157352628.123,
},
]),
).toEqual([])
})
@ -230,7 +229,7 @@ test('checkStuckScreen returns object array of length 1 with prop code: "STALE"
note: '{"state":"chooseCoin","isIdle":true}',
created: '2020-11-23T19:30:29.209Z',
device_time: '1999-11-23T19:30:29.177Z',
age: 0
age: 0,
},
{
id: '48ae51c6-c5b4-485e-b81d-aa337fc025e2',
@ -240,8 +239,8 @@ test('checkStuckScreen returns object array of length 1 with prop code: "STALE"
note: '{"state":"chooseCoin","isIdle":false}',
created: '2020-11-23T19:30:29.209Z',
device_time: '2020-11-23T19:30:29.177Z',
age: 157352628.123
}
age: 157352628.123,
},
])
expect(result[0]).toMatchObject({ code: 'STALE' })
})
@ -257,8 +256,8 @@ test('checkStuckScreen returns empty array if age < STALE_STATE', () => {
note: '{"state":"chooseCoin","isIdle":false}',
created: '2020-11-23T19:30:29.209Z',
device_time: '2020-11-23T19:30:29.177Z',
age: 0
}
age: 0,
},
])
const result2 = notifier.checkStuckScreen([
{
@ -269,8 +268,8 @@ test('checkStuckScreen returns empty array if age < STALE_STATE', () => {
note: '{"state":"chooseCoin","isIdle":false}',
created: '2020-11-23T19:30:29.209Z',
device_time: '2020-11-23T19:30:29.177Z',
age: STALE_STATE
}
age: STALE_STATE,
},
])
expect(result1).toEqual([])
expect(result2).toEqual([])
@ -281,7 +280,10 @@ test('calls sendRedemptionMessage if !zeroConf and rec.isRedemption', async () =
const settingsLoader = require('../../new-settings-loader')
const loadLatest = jest.spyOn(settingsLoader, 'loadLatest')
const getGlobalNotifications = jest.spyOn(configManager, 'getGlobalNotifications')
const getGlobalNotifications = jest.spyOn(
configManager,
'getGlobalNotifications',
)
const getWalletSettings = jest.spyOn(configManager, 'getWalletSettings')
// sendRedemptionMessage will cause this func to be called
@ -289,19 +291,24 @@ test('calls sendRedemptionMessage if !zeroConf and rec.isRedemption', async () =
getWalletSettings.mockReturnValue({ zeroConfLimit: -Infinity })
loadLatest.mockReturnValue(Promise.resolve({}))
getGlobalNotifications.mockReturnValue({ ...notifSettings, sms: { active: true, errors: true, transactions: true }, notificationCenter: { active: true } })
getGlobalNotifications.mockReturnValue({
...notifSettings,
sms: { active: true, errors: true, transactions: true },
notificationCenter: { active: true },
})
const response = await notifier.transactionNotify(tx, { isRedemption: true })
// this type of response implies sendRedemptionMessage was called
expect(response[0]).toMatchObject({
sms: {
body: "Here's an update on transaction bec8d452-9ea2-4846-841b-55a9df8bbd00 - It was just dispensed successfully"
body: "Here's an update on transaction bec8d452-9ea2-4846-841b-55a9df8bbd00 - It was just dispensed successfully",
},
email: {
subject: "Here's an update on transaction bec8d452-9ea2-4846-841b-55a9df8bbd00",
body: 'It was just dispensed successfully'
}
subject:
"Here's an update on transaction bec8d452-9ea2-4846-841b-55a9df8bbd00",
body: 'It was just dispensed successfully',
},
})
})
@ -310,23 +317,32 @@ test('calls sendTransactionMessage if !zeroConf and !rec.isRedemption', async ()
const settingsLoader = require('../../new-settings-loader')
const queries = require('../queries')
const loadLatest = jest.spyOn(settingsLoader, 'loadLatest')
const getGlobalNotifications = jest.spyOn(configManager, 'getGlobalNotifications')
const getGlobalNotifications = jest.spyOn(
configManager,
'getGlobalNotifications',
)
const getWalletSettings = jest.spyOn(configManager, 'getWalletSettings')
const getMachineName = jest.spyOn(queries, 'getMachineName')
const buildTransactionMessage = jest.spyOn(utils, 'buildTransactionMessage')
// sendMessage on emailFuncs isn't called because it is disabled in getGlobalNotifications.mockReturnValue
jest.spyOn(smsFuncs, 'sendMessage').mockImplementation((_, rec) => ({ prop: rec }))
jest
.spyOn(smsFuncs, 'sendMessage')
.mockImplementation((_, rec) => ({ prop: rec }))
buildTransactionMessage.mockImplementation(() => ['mock message', false])
getMachineName.mockResolvedValue('mockMachineName')
getWalletSettings.mockReturnValue({ zeroConfLimit: -Infinity })
loadLatest.mockReturnValue(Promise.resolve({}))
getGlobalNotifications.mockReturnValue({ ...notifSettings, sms: { active: true, errors: true, transactions: true }, notificationCenter: { active: true } })
getGlobalNotifications.mockReturnValue({
...notifSettings,
sms: { active: true, errors: true, transactions: true },
notificationCenter: { active: true },
})
const response = await notifier.transactionNotify(tx, { isRedemption: false })
// If the return object is this, it means the code went through all the functions expected to go through if
// getMachineName, buildTransactionMessage and sendTransactionMessage were called, in this order
expect(response).toEqual([{prop: 'mock message'}])
expect(response).toEqual([{ prop: 'mock message' }])
})

View file

@ -5,18 +5,18 @@ const alertRec = {
f02af604ca9010bd9ae04c427a24da90130da10d355f0a9b235886a89008fc05: {
balanceAlerts: [],
deviceAlerts: [
{ code: 'PING', age: 602784301.446, machineName: 'Abc123' }
]
}
{ code: 'PING', age: 602784301.446, machineName: 'Abc123' },
],
},
},
deviceNames: {
f02af604ca9010bd9ae04c427a24da90130da10d355f0a9b235886a89008fc05: 'Abc123'
f02af604ca9010bd9ae04c427a24da90130da10d355f0a9b235886a89008fc05: 'Abc123',
},
general: []
general: [],
}
test('Print SMS alerts', () => {
expect(sms.printSmsAlerts(alertRec, { active: true, errors: true })).toBe(
'[Lamassu] Errors reported: Machine Down (Abc123)'
'[Lamassu] Errors reported: Machine Down (Abc123)',
)
})

View file

@ -3,7 +3,7 @@ const utils = require('../utils')
const plugins = {
sendMessage: rec => {
return rec
}
},
}
const alertRec = {
@ -11,19 +11,19 @@ const alertRec = {
f02af604ca9010bd9ae04c427a24da90130da10d355f0a9b235886a89008fc05: {
balanceAlerts: [],
deviceAlerts: [
{ code: 'PING', age: 1605532263169, machineName: 'Abc123' }
]
}
{ code: 'PING', age: 1605532263169, machineName: 'Abc123' },
],
},
},
deviceNames: {
f02af604ca9010bd9ae04c427a24da90130da10d355f0a9b235886a89008fc05: 'Abc123'
f02af604ca9010bd9ae04c427a24da90130da10d355f0a9b235886a89008fc05: 'Abc123',
},
general: []
general: [],
}
const notifications = {
sms: { active: true, errors: true },
email: { active: false, errors: false }
email: { active: false, errors: false },
}
describe('buildAlertFingerprint', () => {
@ -33,37 +33,37 @@ describe('buildAlertFingerprint', () => {
{
devices: {},
deviceNames: {},
general: []
general: [],
},
notifications
)
notifications,
),
).toBe(null)
})
test('Build alert fingerprint returns null if sms and email are disabled', () => {
expect(
utils.buildAlertFingerprint(alertRec, {
sms: { active: false, errors: true },
email: { active: false, errors: false }
})
email: { active: false, errors: false },
}),
).toBe(null)
})
test('Build alert fingerprint returns hash if email or [sms] are enabled and there are alerts in alertrec', () => {
expect(
typeof utils.buildAlertFingerprint(alertRec, {
sms: { active: true, errors: true },
email: { active: false, errors: false }
})
email: { active: false, errors: false },
}),
).toBe('string')
})
test('Build alert fingerprint returns hash if [email] or sms are enabled and there are alerts in alertrec', () => {
expect(
typeof utils.buildAlertFingerprint(alertRec, {
sms: { active: false, errors: false },
email: { active: true, errors: true }
})
email: { active: true, errors: true },
}),
).toBe('string')
})
})
@ -76,8 +76,8 @@ describe('sendNoAlerts', () => {
test('Send no alerts returns object with sms prop with sms only enabled', () => {
expect(utils.sendNoAlerts(plugins, true, false)).toEqual({
sms: {
body: '[Lamassu] All clear'
}
body: '[Lamassu] All clear',
},
})
})
@ -85,11 +85,11 @@ describe('sendNoAlerts', () => {
expect(utils.sendNoAlerts(plugins, true, true)).toEqual({
email: {
body: 'No errors are reported for your machines.',
subject: '[Lamassu] All clear'
subject: '[Lamassu] All clear',
},
sms: {
body: '[Lamassu] All clear'
}
body: '[Lamassu] All clear',
},
})
})
@ -97,8 +97,8 @@ describe('sendNoAlerts', () => {
expect(utils.sendNoAlerts(plugins, false, true)).toEqual({
email: {
body: 'No errors are reported for your machines.',
subject: '[Lamassu] All clear'
}
subject: '[Lamassu] All clear',
},
})
})
})