Update test

This commit is contained in:
Mykola 2020-01-21 01:20:02 -08:00
parent 0f2a2b997b
commit 99c59d87a5
3 changed files with 20 additions and 13 deletions

View File

@ -1,6 +1,6 @@
import * as fs from "fs" import * as fs from "fs"
import * as path from "path" import * as path from "path"
import { ValidatorModel } from "./models";
const axios = require('axios') const axios = require('axios')
const Web3 = require('web3') const Web3 = require('web3')
const web3 = new Web3('ws://localhost:8546'); const web3 = new Web3('ws://localhost:8546');
@ -126,3 +126,10 @@ export const calculateAspectRatioFit = (srcWidth: number, srcHeight: number, max
return false return false
} }
} }
export const isValidatorHasAllKeys = (val: ValidatorModel): boolean => {
return typeof val.id === "string"
&& typeof val.name === "string"
&& typeof val.description === "string"
&& typeof val.website === "string"
}

View File

@ -23,9 +23,10 @@ import {
getChainBlacklistPath, getChainBlacklistPath,
mapList, mapList,
findFiles, findFiles,
isValidJSON isValidJSON,
isValidatorHasAllKeys
} from "./helpers" } from "./helpers"
import { ValidatorModel } from "./models";
enum TickerType { enum TickerType {
Token = "token", Token = "token",
Coin = "coin" Coin = "coin"
@ -135,16 +136,9 @@ describe(`Test "blockchains" folder`, () => {
stakingChains.forEach(chain => { stakingChains.forEach(chain => {
const validatorsList = JSON.parse(readFileSync(getChainValidatorsListPath(chain))) const validatorsList = JSON.parse(readFileSync(getChainValidatorsListPath(chain)))
test(`Make sure ${chain} validators list has correct structure`, () => { test(`Make sure ${chain} validators list has correct structure`, () => {
validatorsList.forEach(val => { validatorsList.forEach((val: ValidatorModel) => {
const keys = Object.keys(val) expect(isValidatorHasAllKeys(val), `Come key and/or type missing for validator ${JSON.stringify(val)}`).toBe(true)
expect(keys.length, `Wrong keys amount`).toBeGreaterThanOrEqual(4)
keys.forEach(key => {
const type = typeof key
expect(type, `Wrong key type`).toBe("string")
})
}) })
}) })

6
src/test/models.ts Normal file
View File

@ -0,0 +1,6 @@
export interface ValidatorModel {
id: string,
name: string,
description: string,
website: string,
}