From 99c59d87a593a131e1a486dad5149116b5de2901 Mon Sep 17 00:00:00 2001 From: Mykola Date: Tue, 21 Jan 2020 01:20:02 -0800 Subject: [PATCH] Update test --- src/test/helpers.ts | 11 +++++++++-- src/test/index.test.ts | 16 +++++----------- src/test/models.ts | 6 ++++++ 3 files changed, 20 insertions(+), 13 deletions(-) create mode 100644 src/test/models.ts diff --git a/src/test/helpers.ts b/src/test/helpers.ts index 0b8dc1be6..8cce91228 100644 --- a/src/test/helpers.ts +++ b/src/test/helpers.ts @@ -1,6 +1,6 @@ import * as fs from "fs" import * as path from "path" - +import { ValidatorModel } from "./models"; const axios = require('axios') const Web3 = require('web3') const web3 = new Web3('ws://localhost:8546'); @@ -125,4 +125,11 @@ export const calculateAspectRatioFit = (srcWidth: number, srcHeight: number, max } catch { return false } - } \ No newline at end of file + } + +export const isValidatorHasAllKeys = (val: ValidatorModel): boolean => { + return typeof val.id === "string" + && typeof val.name === "string" + && typeof val.description === "string" + && typeof val.website === "string" +} diff --git a/src/test/index.test.ts b/src/test/index.test.ts index 186b55236..93f3bb80e 100644 --- a/src/test/index.test.ts +++ b/src/test/index.test.ts @@ -23,9 +23,10 @@ import { getChainBlacklistPath, mapList, findFiles, - isValidJSON + isValidJSON, + isValidatorHasAllKeys } from "./helpers" - +import { ValidatorModel } from "./models"; enum TickerType { Token = "token", Coin = "coin" @@ -135,16 +136,9 @@ describe(`Test "blockchains" folder`, () => { stakingChains.forEach(chain => { const validatorsList = JSON.parse(readFileSync(getChainValidatorsListPath(chain))) - test(`Make sure ${chain} validators list has correct structure`, () => { - validatorsList.forEach(val => { - const keys = Object.keys(val) - expect(keys.length, `Wrong keys amount`).toBeGreaterThanOrEqual(4) - - keys.forEach(key => { - const type = typeof key - expect(type, `Wrong key type`).toBe("string") - }) + validatorsList.forEach((val: ValidatorModel) => { + expect(isValidatorHasAllKeys(val), `Come key and/or type missing for validator ${JSON.stringify(val)}`).toBe(true) }) }) diff --git a/src/test/models.ts b/src/test/models.ts new file mode 100644 index 000000000..c4c4f79ad --- /dev/null +++ b/src/test/models.ts @@ -0,0 +1,6 @@ +export interface ValidatorModel { + id: string, + name: string, + description: string, + website: string, +} \ No newline at end of file