Skip to content

Commit

Permalink
🚧 [root]: correct let with const #93
Browse files Browse the repository at this point in the history
  • Loading branch information
apolkingg8 committed Nov 5, 2021
1 parent 605862b commit 5e9cb61
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand All @@ -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,
Expand All @@ -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)
Expand Down Expand Up @@ -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(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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)
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down
30 changes: 15 additions & 15 deletions libs/blockchain-watcher/feature-app/src/lib/service/mailService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: '[email protected]',
to: to,
subject: subject,
Expand All @@ -23,17 +23,17 @@ class MailService {
}

async getTemplateHtml(htmlName: string): Promise<HandlebarsTemplateDelegate> {
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 = ''
Expand All @@ -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)
}
Expand Down

0 comments on commit 5e9cb61

Please sign in to comment.