diff --git a/libs/blockchain-watcher/feature-app/src/lib/Klass/PaymentCreatedEvent.spec.ts b/libs/blockchain-watcher/feature-app/src/lib/Klass/PaymentCreatedEvent.spec.ts index 05ef7dac..c71d7232 100644 --- a/libs/blockchain-watcher/feature-app/src/lib/Klass/PaymentCreatedEvent.spec.ts +++ b/libs/blockchain-watcher/feature-app/src/lib/Klass/PaymentCreatedEvent.spec.ts @@ -2,7 +2,7 @@ import { PaymentCreatedEvent } from './PaymentCreatedEvent' import { v4 } from 'uuid' import _ from 'lodash' import { PaymentCreatedEventType } from '../Enum/PaymentCreatedEventType' -import { stringHelper } from '@solomon/blockchain-watcher/feature-app' +import { stringHelper } from '../helper/stringHelper' describe('PaymentCreatedEvent', () => { it('constructor() with empty props', () => { @@ -12,12 +12,12 @@ describe('PaymentCreatedEvent', () => { }) it('constructor() with valid props', () => { - let id = v4() - let addr1 = stringHelper.generateRandomEthAddr() - let addr2 = stringHelper.generateRandomEthAddr() - let addr3 = stringHelper.generateRandomEthAddr() - let addr4 = stringHelper.generateRandomEthAddr() - let addr5 = stringHelper.generateRandomEthAddr() + const id = v4() + const addr1 = stringHelper.generateRandomEthAddr() + const addr2 = stringHelper.generateRandomEthAddr() + const addr3 = stringHelper.generateRandomEthAddr() + const addr4 = stringHelper.generateRandomEthAddr() + const addr5 = stringHelper.generateRandomEthAddr() let p = new PaymentCreatedEvent({ id: id, @@ -44,15 +44,15 @@ describe('PaymentCreatedEvent', () => { }) it('constructor() with invalid props', () => { - let badId = new PaymentCreatedEvent({ id: '' }) - let badType = new PaymentCreatedEvent({ type: '' as any }) - let badParty1 = new PaymentCreatedEvent({ party1: '' }) - let badParty2 = new PaymentCreatedEvent({ party2: '' }) - let badContract = new PaymentCreatedEvent({ contract: '' }) - let badJudgeContract = new PaymentCreatedEvent({ judgeContract: '' }) - let badToken = new PaymentCreatedEvent({ token: '' }) - let badDiscount = new PaymentCreatedEvent({ discount: -1 }) - let badEthPaid = new PaymentCreatedEvent({ ethPaid: -1 }) + const badId = new PaymentCreatedEvent({ id: '' }) + const badType = new PaymentCreatedEvent({ type: '' as any }) + const badParty1 = new PaymentCreatedEvent({ party1: '' }) + const badParty2 = new PaymentCreatedEvent({ party2: '' }) + const badContract = new PaymentCreatedEvent({ contract: '' }) + const badJudgeContract = new PaymentCreatedEvent({ judgeContract: '' }) + const badToken = new PaymentCreatedEvent({ token: '' }) + const badDiscount = new PaymentCreatedEvent({ discount: -1 }) + const badEthPaid = new PaymentCreatedEvent({ ethPaid: -1 }) expect(badId.isValid()).toEqual(false) expect(badType.isValid()).toEqual(false) @@ -82,7 +82,7 @@ describe('PaymentCreatedEvent', () => { }) it('constructor() assign invalid props', () => { - let p = new PaymentCreatedEvent({ + const p = new PaymentCreatedEvent({ id: v4(), type: PaymentCreatedEventType.chargeback, party1: stringHelper.generateRandomEthAddr(), diff --git a/libs/blockchain-watcher/feature-app/src/lib/helper/stringHelper.ts b/libs/blockchain-watcher/feature-app/src/lib/helper/stringHelper.ts index c42d3309..5c6a3d48 100644 --- a/libs/blockchain-watcher/feature-app/src/lib/helper/stringHelper.ts +++ b/libs/blockchain-watcher/feature-app/src/lib/helper/stringHelper.ts @@ -6,11 +6,11 @@ export class StringHelper { } generateRandomEthAddr(): string { + const chs = '0123456789abcdefABCDEF' let res = '0x' - let chs = '0123456789abcdefABCDEF' for (let i = 1; i <= 40; i++) { - let ri = Math.floor(Math.random() * 22) + const ri = Math.floor(Math.random() * 22) res += chs[ri] } diff --git a/libs/blockchain-watcher/feature-app/src/lib/service/dbService.spec.ts b/libs/blockchain-watcher/feature-app/src/lib/service/dbService.spec.ts index 1500d925..4cf5aa9d 100644 --- a/libs/blockchain-watcher/feature-app/src/lib/service/dbService.spec.ts +++ b/libs/blockchain-watcher/feature-app/src/lib/service/dbService.spec.ts @@ -17,7 +17,7 @@ describe('dbService', () => { test('setLastScanned()', async () => { await dbService.setLastScanned('block1') - let r1 = await dbService.scanLogRepository.findAll() + const r1 = await dbService.scanLogRepository.findAll() expect(r1.length).toEqual(1) expect(r1[0].blockHash).toEqual('block1') @@ -26,30 +26,30 @@ describe('dbService', () => { await dbService.setLastScanned('block2') await dbService.setLastScanned('block3') - let r2 = await dbService.scanLogRepository.findAll() - let hashArr = r2.map((entity) => entity.blockHash).sort() + const r2 = await dbService.scanLogRepository.findAll() + const hashArr = r2.map((entity) => entity.blockHash).sort() expect(r2.length).toEqual(3) expect(hashArr).toEqual(['block1', 'block2', 'block3']) }) test('getLastScanned()', async () => { - let log1 = dbService.scanLogRepository.create({ + const log1 = dbService.scanLogRepository.create({ blockHash: 'block1', lastScanned: 1, }) - let log2 = dbService.scanLogRepository.create({ + const log2 = dbService.scanLogRepository.create({ blockHash: 'block2', lastScanned: 2, }) - let log3 = dbService.scanLogRepository.create({ + const log3 = dbService.scanLogRepository.create({ blockHash: 'block3', lastScanned: 3, }) await dbService.scanLogRepository.persistAndFlush([log1, log2, log3]) - let r1 = await dbService.getLastScanned() + const r1 = await dbService.getLastScanned() expect(r1?.id).toEqual(log3.id) }) diff --git a/libs/blockchain-watcher/feature-app/src/lib/service/dbService.ts b/libs/blockchain-watcher/feature-app/src/lib/service/dbService.ts index 2033bfa9..8afda46f 100644 --- a/libs/blockchain-watcher/feature-app/src/lib/service/dbService.ts +++ b/libs/blockchain-watcher/feature-app/src/lib/service/dbService.ts @@ -51,8 +51,8 @@ export class DbService { } async init() { - let isDbExist = await pathExists(this.sqlitePath) - let orm = await MikroORM.init({ + const isDbExist = await pathExists(this.sqlitePath) + const orm = await MikroORM.init({ entities: [ScanLogEntity], dbName: this.sqlitePath, type: 'sqlite', diff --git a/libs/blockchain-watcher/feature-app/src/lib/service/mailService.spec.ts b/libs/blockchain-watcher/feature-app/src/lib/service/mailService.spec.ts index befae682..5c8bfc02 100644 --- a/libs/blockchain-watcher/feature-app/src/lib/service/mailService.spec.ts +++ b/libs/blockchain-watcher/feature-app/src/lib/service/mailService.spec.ts @@ -20,22 +20,22 @@ describe('mailService', () => { test('send()', async () => {}) test('getTemplateHtml()', async () => { - let templateHtml = await mailService.getTemplateHtml('_test.html') - let finalHtml = templateHtml({ + const templateHtml = await mailService.getTemplateHtml('_test.html') + const finalHtml = templateHtml({ foo: 'foo', bar: 'bar', }) - let dom = new JSDOM(finalHtml) - let r1 = dom.window.document.querySelector('#foo')?.textContent - let r2 = dom.window.document.querySelector('img')?.getAttribute('src') + const dom = new JSDOM(finalHtml) + const r1 = dom.window.document.querySelector('#foo')?.textContent + const r2 = dom.window.document.querySelector('img')?.getAttribute('src') expect(r1).toEqual('foo') expect(r2).toEqual('bar') }) test('sendChargebackCreatedEmail()', async () => { - let realSend = mailService.send + const realSend = mailService.send mailService.send = jest.fn() await mailService.sendChargebackCreatedEmail('foo' as any) @@ -46,7 +46,7 @@ describe('mailService', () => { }) test('sendPreorderCreatedEmail()', async () => { - let realSend = mailService.send + const realSend = mailService.send mailService.send = jest.fn() await mailService.sendPreorderCreatedEmail('foo' as any) @@ -57,7 +57,7 @@ describe('mailService', () => { }) test('sendEscrowCreatedEmail()', async () => { - let realSend = mailService.send + const realSend = mailService.send mailService.send = jest.fn() await mailService.sendEscrowCreatedEmail('foo' as any) diff --git a/libs/blockchain-watcher/feature-app/src/lib/service/mailService.ts b/libs/blockchain-watcher/feature-app/src/lib/service/mailService.ts index e9403224..a589183d 100644 --- a/libs/blockchain-watcher/feature-app/src/lib/service/mailService.ts +++ b/libs/blockchain-watcher/feature-app/src/lib/service/mailService.ts @@ -11,7 +11,7 @@ class MailService { mailer: Transporter = null as any async send(to: string | string[], subject: string, html: string, text: string) { - let info = await this.mailer.sendMail({ + const info = await this.mailer.sendMail({ from: 'solomondefi@gmail.com', to: to, subject: subject, @@ -23,17 +23,17 @@ class MailService { } async getTemplateHtml(htmlName: string): Promise { - let htmlPath = path.resolve(pathStore.mailTemplates, htmlName) - let rawHtml = await readFile(htmlPath, 'utf-8') - let templateHtml = Handlebars.compile(rawHtml) + const htmlPath = path.resolve(pathStore.mailTemplates, htmlName) + const rawHtml = await readFile(htmlPath, 'utf-8') + const templateHtml = Handlebars.compile(rawHtml) return templateHtml } async sendChargebackCreatedEmail(slmChargeback: SlmChargeback) { - let subject = 'Chargeback created' - let templateHtml = await this.getTemplateHtml('chargebackCreated.html') - let finalHtml = templateHtml({ + const subject = 'Chargeback created' + const templateHtml = await this.getTemplateHtml('chargebackCreated.html') + const finalHtml = templateHtml({ // TODO }) let text = '' @@ -42,23 +42,23 @@ class MailService { } async sendPreorderCreatedEmail(slmPreorder: SlmPreorder) { - let subject = 'Preorder created' - let templateHtml = await this.getTemplateHtml('preorderCreated.html') - let finalHtml = templateHtml({ + const subject = 'Preorder created' + const templateHtml = await this.getTemplateHtml('preorderCreated.html') + const finalHtml = templateHtml({ // TODO }) - let text = '' + const text = '' await this.send('to', subject, finalHtml, text) } async sendEscrowCreatedEmail(slmEscrow: SlmEscrow) { - let subject = 'Escrow created' - let templateHtml = await this.getTemplateHtml('escrowCreated.html') - let finalHtml = templateHtml({ + const subject = 'Escrow created' + const templateHtml = await this.getTemplateHtml('escrowCreated.html') + const finalHtml = templateHtml({ // TODO }) - let text = '' + const text = '' await this.send('to', subject, finalHtml, text) }