From c227fa0b81dd34618b383568bcbe06bd345f6210 Mon Sep 17 00:00:00 2001 From: deveshsangwan Date: Sun, 10 Mar 2024 21:52:58 +0530 Subject: [PATCH] added eslint --- .eslintrc.json | 24 +++++++++++++++ Dockerfile | 17 ++++++++--- app/app.js | 46 ++++++++++++++--------------- app/core/baseModel.js | 4 +-- app/core/logger.js | 24 +++++++-------- app/route.js | 2 +- app/src/LiveMatches/index.js | 4 +-- app/src/MatchStats/MatchUtils.js | 4 +-- app/src/MatchStats/index.js | 23 ++++++++------- app/src/controller.js | 2 +- app/src/errors/CustomErro.js | 10 ------- app/ts_src/LiveMatches/index.ts | 6 ++-- app/ts_src/MatchStats/MatchUtils.ts | 4 +-- app/ts_src/MatchStats/index.ts | 24 +++++++-------- app/ts_src/Utils.ts | 4 +-- app/ts_src/controller.ts | 10 +++---- build/index.js | 18 +++++------ functions/lib/index.js | 4 +-- package.json | 10 +++++-- unitTest/LiveMatches.test.ts | 2 +- unitTest/MatchStats.test.ts | 12 ++++---- unitTest/TestData/Generic.ts | 2 +- unitTest/TestData/MatchStats.ts | 36 +++++++++++----------- 23 files changed, 160 insertions(+), 132 deletions(-) create mode 100644 .eslintrc.json delete mode 100644 app/src/errors/CustomErro.js diff --git a/.eslintrc.json b/.eslintrc.json new file mode 100644 index 0000000..f7c5671 --- /dev/null +++ b/.eslintrc.json @@ -0,0 +1,24 @@ +{ + "env": { + "node": true + }, + "parser": "@typescript-eslint/parser", + "extends": [ + "eslint:recommended", + "plugin:@typescript-eslint/recommended" + ], + "parserOptions": { + "ecmaVersion": 2020, + "sourceType": "module" + }, + "rules": { + "no-console": "warn", + "indent": ["error", 4], + "linebreak-style": ["error", "unix"], + "quotes": ["error", "single"], + "semi": ["error", "always"], + "no-unused-vars": ["warn"], + "eqeqeq": ["error", "always"], + "curly": ["error"] + } +} \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 88f8954..45e052b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,15 +1,24 @@ +# Use multi-stage build FROM node:alpine ENV NODE_VERSION 18.16.0 WORKDIR /usr/app -COPY ./ /usr/app -RUN apk --no-cache add bash -RUN apk --no-cache --virtual build-dependencies add +# Copy package.json and package-lock.json first +COPY package*.json ./ + +# Set NODE_ENV to production before running npm install +ENV NODE_ENV production + +# Install bash +RUN apk add --no-cache bash + RUN npm cache clean --force RUN npm install -RUN apk del build-dependencies + +# Copy the rest of the application code +COPY ./ . ENV NODE_PORT 3000 ENV NODE_ENV production diff --git a/app/app.js b/app/app.js index 308b807..a4bb2bd 100644 --- a/app/app.js +++ b/app/app.js @@ -1,24 +1,24 @@ -const app = require('express')(); -const bodyParser = require('body-parser'); -const httpContext = require('express-http-context'); -const Mongo = require('./core/mongo'); - -app.use(bodyParser.json()); -app.use(bodyParser.urlencoded({ extended: true })); -app.use(httpContext.middleware); - -app.use((req, res, next) => { - httpContext.set('req', req); - next(); -}); - -require(__basedir + 'app/route')(app); - -app.use(function (req, res) { - return res.status(404).json({ - status: false, - statusMessage: '404 - Page not found' - }); -}); - +const app = require('express')(); +const bodyParser = require('body-parser'); +const httpContext = require('express-http-context'); +const Mongo = require('./core/mongo'); + +app.use(bodyParser.json()); +app.use(bodyParser.urlencoded({ extended: true })); +app.use(httpContext.middleware); + +app.use((req, res, next) => { + httpContext.set('req', req); + next(); +}); + +require(__basedir + 'app/route')(app); + +app.use(function (req, res) { + return res.status(404).json({ + status: false, + statusMessage: '404 - Page not found' + }); +}); + module.exports = app; \ No newline at end of file diff --git a/app/core/baseModel.js b/app/core/baseModel.js index 90df272..3c2d81c 100644 --- a/app/core/baseModel.js +++ b/app/core/baseModel.js @@ -89,7 +89,7 @@ const findIdByMatchUrl = async (matchUrl) => { try { return await Mongoose.model(MODEL_NAMES.LIVE_MATCHES).find({ matchUrl: matchUrl }); } catch (err) { - writeLogError(["findIdByMatchUrl error: ", err]); + writeLogError(['findIdByMatchUrl error: ', err]); throw err; } }; @@ -126,4 +126,4 @@ module.exports = { findIdByMatchUrl, insert, insertMany -} \ No newline at end of file +}; \ No newline at end of file diff --git a/app/core/logger.js b/app/core/logger.js index 869b82a..ebb9125 100644 --- a/app/core/logger.js +++ b/app/core/logger.js @@ -5,15 +5,15 @@ const logger = winston.createLogger({ format: winston.format.combine( winston.format.label({label:config.get('logging:label')}), winston.format.errors({stack: true}), - winston.format.timestamp({format: "YYYY-MM-DD hh:mm:ss"}), + winston.format.timestamp({format: 'YYYY-MM-DD hh:mm:ss'}), winston.format.printf(({ timestamp, label, level, message, meta, stack }) => { - const text = "[" + timestamp + "] " + - label + "." + level.toUpperCase() + ": " + (message ? message : + const text = '[' + timestamp + '] ' + + label + '.' + level.toUpperCase() + ': ' + (message ? message : '') +(meta && Object.keys(meta).length ? '\n' + JSON.stringify(meta, null, 4) : ''); - return stack ? text + '\n' + stack : text; - }), + return stack ? text + '\n' + stack : text; + }), winston.format.colorize({ all: true }), ), transports: [ @@ -25,16 +25,16 @@ const logger = winston.createLogger({ }); const writeLogInfo = (arr) => { - return logger.info( + return logger.info( arr - ); -} + ); +}; const writeLogError = (arr) => { - return logger.error ( - arr - ); -} + return logger.error ( + arr + ); +}; /** Return Logger instances */ module.exports = { diff --git a/app/route.js b/app/route.js index 08db5a0..74b7176 100644 --- a/app/route.js +++ b/app/route.js @@ -22,4 +22,4 @@ module.exports = function (app) { router.get('/liveMatches', errorHandler(controller.live)); router.get('/matchStats/:matchId', errorHandler(controller.matchStats)); router.get('/matchStats', errorHandler(controller.getMatchStats)); -} \ No newline at end of file +}; \ No newline at end of file diff --git a/app/src/LiveMatches/index.js b/app/src/LiveMatches/index.js index 305c996..deaabd2 100644 --- a/app/src/LiveMatches/index.js +++ b/app/src/LiveMatches/index.js @@ -46,8 +46,8 @@ class LiveMatches { (0, logger_1.writeLogError)([`${location} | error`, error]); return Promise.reject(new errors_1.CustomError(error.message)); } - async getMatches(matchId = "0") { - if (matchId !== "0") { + async getMatches(matchId = '0') { + if (matchId !== '0') { return this.getMatchById(matchId); } return this.getAllMatches(); diff --git a/app/src/MatchStats/MatchUtils.js b/app/src/MatchStats/MatchUtils.js index b38c90a..544de33 100644 --- a/app/src/MatchStats/MatchUtils.js +++ b/app/src/MatchStats/MatchUtils.js @@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true }); exports.getBatsmanData = exports.getTeamData = exports.getTeamScoreString = void 0; const logger_1 = require("../../core/logger"); function getTeamScoreString($, isLive, isCurrentTeam) { - let element = isLive + const element = isLive ? (isCurrentTeam ? $('span.cb-font-20.text-bold') : $('div.cb-text-gray.cb-font-16')) : $('div.cb-col.cb-col-100.cb-min-tm').eq(isCurrentTeam ? 1 : 0); return element.text().trim(); @@ -16,7 +16,7 @@ function getTeamData(input, isBatting = false) { (0, logger_1.writeLogInfo)(['matchStats | getTeamData | input', input]); return {}; } - const [, name, score1, wickets1 = "10", score2, wickets2 = "10", overs] = match; + const [, name, score1, wickets1 = '10', score2, wickets2 = '10', overs] = match; const hasTwoInnings = score2 !== undefined; const score = hasTwoInnings ? score2 : score1; const wickets = hasTwoInnings ? wickets2 : wickets1; diff --git a/app/src/MatchStats/index.js b/app/src/MatchStats/index.js index 108d3df..492ef81 100644 --- a/app/src/MatchStats/index.js +++ b/app/src/MatchStats/index.js @@ -46,13 +46,13 @@ class MatchStats { throw new errors_1.MatchIdRequriedError(); } // matchId should be 0 or alphanumeric string of length 16 - if (matchId !== "0" && !matchId.match(/^[a-zA-Z0-9]{16}$/)) { + if (matchId !== '0' && !matchId.match(/^[a-zA-Z0-9]{16}$/)) { throw new errors_1.InvalidMatchIdError(matchId); } const liveMatchesResponse = await this.liveMatchesObj.getMatches(matchId); - // If matchId is not "0", get stats for the single match + // If matchId is not '0', get stats for the single match // Otherwise, get stats for all matches - if (matchId !== "0") { + if (matchId !== '0') { return this.getStatsForSingleMatch(liveMatchesResponse, matchId); } return this.getStatsForAllMatches(liveMatchesResponse); @@ -82,7 +82,7 @@ class MatchStats { return data; } async getStatsForSingleMatch(liveMatchesResponse, matchId) { - let mongoData = await mongo.findById(matchId, this.tableName); + const mongoData = await mongo.findById(matchId, this.tableName); if (mongoData.length) { // Only add the properties you need const returnObj = { @@ -107,12 +107,13 @@ class MatchStats { } async scrapeData(url, matchId) { try { - if (!matchId) + if (!matchId) { return Promise.resolve('Match Id is required'); + } url = 'https://www.cricbuzz.com' + url; const response = await this.utilsObj.fetchData(url); - let tournamentName = await this.getTournamentName(response); - let finalResponse = await this.getMatchStatsByMatchId(response, matchId); + const tournamentName = await this.getTournamentName(response); + const finalResponse = await this.getMatchStatsByMatchId(response, matchId); finalResponse['tournamentName'] = tournamentName; return Promise.resolve(finalResponse); } @@ -137,10 +138,10 @@ class MatchStats { getMatchStatsByMatchId($, matchId) { return new Promise((resolve, reject) => { try { - let isLive = $('div.cb-text-complete').length === 0; - let currentTeamScoreString = (0, MatchUtils_1.getTeamScoreString)($, isLive, true); - let otherTeamScoreString = (0, MatchUtils_1.getTeamScoreString)($, isLive, false); - let matchData = { + const isLive = $('div.cb-text-complete').length === 0; + const currentTeamScoreString = (0, MatchUtils_1.getTeamScoreString)($, isLive, true); + const otherTeamScoreString = (0, MatchUtils_1.getTeamScoreString)($, isLive, false); + const matchData = { matchId: matchId, team1: (0, MatchUtils_1.getTeamData)(currentTeamScoreString, true), team2: (0, MatchUtils_1.getTeamData)(otherTeamScoreString), diff --git a/app/src/controller.js b/app/src/controller.js index ea73f3d..587b518 100644 --- a/app/src/controller.js +++ b/app/src/controller.js @@ -42,7 +42,7 @@ const matchStats = async (req, res) => { const getMatchStats = async (_req, res) => { try { const matchStatsObj = new MatchStats_1.MatchStats(); - const matchStatsResponse = await matchStatsObj.getMatchStats("0"); + const matchStatsResponse = await matchStatsObj.getMatchStats('0'); return res.status(200).send({ status: true, message: 'Match Stats', diff --git a/app/src/errors/CustomErro.js b/app/src/errors/CustomErro.js deleted file mode 100644 index f2e2b11..0000000 --- a/app/src/errors/CustomErro.js +++ /dev/null @@ -1,10 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.CustomError = void 0; -class CustomError extends Error { - constructor(message) { - super(message); - this.name = this.constructor.name; - } -} -exports.CustomError = CustomError; diff --git a/app/ts_src/LiveMatches/index.ts b/app/ts_src/LiveMatches/index.ts index e745c66..c93e9b6 100644 --- a/app/ts_src/LiveMatches/index.ts +++ b/app/ts_src/LiveMatches/index.ts @@ -4,7 +4,7 @@ import { MatchData } from './LiveMatchesInterfaces'; import { insertDataToLiveMatchesTable } from './LiveMatchesUtility'; import { CustomError } from '../errors'; import * as mongo from '../../core/baseModel'; -import randomstring from "randomstring"; +import randomstring from 'randomstring'; import _ from 'underscore'; const MATCH_URL = 'https://www.cricbuzz.com/cricket-match/live-scores'; @@ -23,8 +23,8 @@ export class LiveMatches { return Promise.reject(new CustomError(error.message)); } - public async getMatches(matchId = "0"): Promise<{}> { - if (matchId !== "0") { + public async getMatches(matchId = '0'): Promise<{}> { + if (matchId !== '0') { return this.getMatchById(matchId); } return this.getAllMatches(); diff --git a/app/ts_src/MatchStats/MatchUtils.ts b/app/ts_src/MatchStats/MatchUtils.ts index 51ca41b..f178714 100644 --- a/app/ts_src/MatchStats/MatchUtils.ts +++ b/app/ts_src/MatchStats/MatchUtils.ts @@ -2,7 +2,7 @@ import { writeLogInfo } from '../../core/logger'; import { ITeamData } from './MatchStatsInterfaces'; export function getTeamScoreString($, isLive: boolean, isCurrentTeam: boolean): string { - let element = isLive + const element = isLive ? (isCurrentTeam ? $('span.cb-font-20.text-bold') : $('div.cb-text-gray.cb-font-16')) : $('div.cb-col.cb-col-100.cb-min-tm').eq(isCurrentTeam ? 1 : 0); return element.text().trim(); @@ -16,7 +16,7 @@ export function getTeamData(input: string, isBatting: boolean = false): ITeamDat return {}; } - const [, name, score1, wickets1 = "10", score2, wickets2 = "10", overs] = match; + const [, name, score1, wickets1 = '10', score2, wickets2 = '10', overs] = match; const hasTwoInnings = score2 !== undefined; const score = hasTwoInnings ? score2 : score1; const wickets = hasTwoInnings ? wickets2 : wickets1; diff --git a/app/ts_src/MatchStats/index.ts b/app/ts_src/MatchStats/index.ts index 1e010ed..7dc1878 100644 --- a/app/ts_src/MatchStats/index.ts +++ b/app/ts_src/MatchStats/index.ts @@ -4,7 +4,7 @@ import * as mongo from '../../core/baseModel'; import { writeLogError } from '../../core/logger'; import { InvalidMatchIdError, MatchIdRequriedError, NoMatchesFoundError } from '../errors'; import { LiveMatchesResponse, MatchData } from './MatchStatsInterfaces'; -import { getTeamScoreString, getTeamData, getBatsmanData } from './MatchUtils' +import { getTeamScoreString, getTeamData, getBatsmanData } from './MatchUtils'; const _ = require('underscore'); @@ -26,15 +26,15 @@ export class MatchStats { } // matchId should be 0 or alphanumeric string of length 16 - if (matchId !== "0" && !matchId.match(/^[a-zA-Z0-9]{16}$/)) { + if (matchId !== '0' && !matchId.match(/^[a-zA-Z0-9]{16}$/)) { throw new InvalidMatchIdError(matchId); } const liveMatchesResponse = await this.liveMatchesObj.getMatches(matchId); - // If matchId is not "0", get stats for the single match + // If matchId is not '0', get stats for the single match // Otherwise, get stats for all matches - if (matchId !== "0") { + if (matchId !== '0') { return this.getStatsForSingleMatch(liveMatchesResponse, matchId); } @@ -72,7 +72,7 @@ export class MatchStats { } private async getStatsForSingleMatch(liveMatchesResponse: LiveMatchesResponse, matchId: string): Promise<{} | 'Match Id is invalid'> { - let mongoData = await mongo.findById(matchId, this.tableName); + const mongoData = await mongo.findById(matchId, this.tableName); if (mongoData.length) { // Only add the properties you need const returnObj = { @@ -100,14 +100,14 @@ export class MatchStats { private async scrapeData(url, matchId: string): Promise<{}> { try { - if (!matchId) return Promise.resolve('Match Id is required'); + if (!matchId) {return Promise.resolve('Match Id is required');} url = 'https://www.cricbuzz.com' + url; const response = await this.utilsObj.fetchData(url); - let tournamentName = await this.getTournamentName(response); + const tournamentName = await this.getTournamentName(response); - let finalResponse = await this.getMatchStatsByMatchId(response, matchId); + const finalResponse = await this.getMatchStatsByMatchId(response, matchId); finalResponse['tournamentName'] = tournamentName; return Promise.resolve(finalResponse); @@ -133,11 +133,11 @@ export class MatchStats { private getMatchStatsByMatchId($, matchId: string): Promise { return new Promise((resolve, reject) => { try { - let isLive = $('div.cb-text-complete').length === 0; - let currentTeamScoreString = getTeamScoreString($, isLive, true); - let otherTeamScoreString = getTeamScoreString($, isLive, false); + const isLive = $('div.cb-text-complete').length === 0; + const currentTeamScoreString = getTeamScoreString($, isLive, true); + const otherTeamScoreString = getTeamScoreString($, isLive, false); - let matchData: MatchData = { + const matchData: MatchData = { matchId: matchId, team1: getTeamData(currentTeamScoreString, true), team2: getTeamData(otherTeamScoreString), diff --git a/app/ts_src/Utils.ts b/app/ts_src/Utils.ts index c76a1f6..bc17ef7 100644 --- a/app/ts_src/Utils.ts +++ b/app/ts_src/Utils.ts @@ -18,7 +18,7 @@ export class Utils { throw new Error(`Error while fetching data from url: ${url}`); } catch (error) { - writeLogError(['Utils | scrapeData | error', error]) + writeLogError(['Utils | scrapeData | error', error]); return Promise.reject(error); } } @@ -34,7 +34,7 @@ export class Utils { // function for inserting data into matchStats table public async insertDataToMatchStatsTable(scrapedData: { [key: string]: any }, matchId?: string) { - const dataToInsert = { ...scrapedData, _id: matchId ? matchId : scrapedData['matchId'] } + const dataToInsert = { ...scrapedData, _id: matchId ? matchId : scrapedData['matchId'] }; delete dataToInsert['matchId']; await mongo.insert(dataToInsert, 'matchStats'); } diff --git a/app/ts_src/controller.ts b/app/ts_src/controller.ts index fca468d..c0a50b6 100644 --- a/app/ts_src/controller.ts +++ b/app/ts_src/controller.ts @@ -1,6 +1,6 @@ import { Request, Response } from 'express'; -import { LiveMatches } from "./LiveMatches"; -import { MatchStats } from "./MatchStats"; +import { LiveMatches } from './LiveMatches'; +import { MatchStats } from './MatchStats'; const live = async (_req: Request, res: Response) => { try { @@ -39,12 +39,12 @@ const matchStats = async (req: Request, res: Response) => { error: error.message }); } -} +}; const getMatchStats = async (_req: Request, res: Response) => { try { const matchStatsObj = new MatchStats(); - const matchStatsResponse = await matchStatsObj.getMatchStats("0"); + const matchStatsResponse = await matchStatsObj.getMatchStats('0'); return res.status(200).send({ status: true, @@ -58,7 +58,7 @@ const getMatchStats = async (_req: Request, res: Response) => { error: error.message }); } -} +}; module.exports = { live, diff --git a/build/index.js b/build/index.js index b675ab0..2f97d04 100644 --- a/build/index.js +++ b/build/index.js @@ -1,10 +1,10 @@ -global.__basedir = process.cwd() + '/'; -const port = process.env.NODE_PORT || 3000; -const app = require(__basedir + 'app/app.js'); -const { writeLogInfo } = require(__basedir + 'app/core/logger'); -//const config = require(__basedir + 'app/core/configuration'); -//const port = process.env.NODE_PORT || config.get('server:index:port'); - -app.listen(port, function () { - writeLogInfo([`Running on port: ${port}`]); +global.__basedir = process.cwd() + '/'; +const port = process.env.NODE_PORT || 3000; +const app = require(__basedir + 'app/app.js'); +const { writeLogInfo } = require(__basedir + 'app/core/logger'); +//const config = require(__basedir + 'app/core/configuration'); +//const port = process.env.NODE_PORT || config.get('server:index:port'); + +app.listen(port, function () { + writeLogInfo([`Running on port: ${port}`]); }); \ No newline at end of file diff --git a/functions/lib/index.js b/functions/lib/index.js index 5611d36..3f8916b 100644 --- a/functions/lib/index.js +++ b/functions/lib/index.js @@ -1,4 +1,4 @@ -"use strict"; +'use strict'; /** * Import function triggers from their respective submodules: * @@ -7,7 +7,7 @@ * * See a full list of supported triggers at https://firebase.google.com/docs/functions */ -Object.defineProperty(exports, "__esModule", { value: true }); +Object.defineProperty(exports, '__esModule', { value: true }); // Start writing functions // https://firebase.google.com/docs/functions/typescript // export const helloWorld = onRequest((request, response) => { diff --git a/package.json b/package.json index b9ee08f..23fd1de 100644 --- a/package.json +++ b/package.json @@ -9,10 +9,11 @@ "build": "tsc -p . & export NODE_ENV=production", "test": "NODE_ENV=test mocha", "test:coverage": "NODE_ENV=test nyc mocha && npm run posttest", - "posttest": "istanbul-badges-readme" + "posttest": "istanbul-badges-readme", + "lint": "eslint 'app/ts_src/**/*.ts'" }, "keywords": [], - "author": "", + "author": "Devesh Sangwan", "license": "ISC", "devDependencies": { "@istanbuljs/nyc-config-typescript": "^1.0.2", @@ -20,8 +21,11 @@ "@types/mocha": "^10.0.6", "@types/node": "^20.11.25", "@types/sinon": "^17.0.3", + "@typescript-eslint/eslint-plugin": "^6.20.0", + "@typescript-eslint/parser": "^6.20.0", "chai": "^4.4.1", "chai-http": "^4.4.0", + "eslint": "^8.56.0", "istanbul-badges-readme": "^1.8.5", "mocha": "^10.3.0", "nyc": "^15.1.0", @@ -42,4 +46,4 @@ "underscore": "^1.13.6", "winston": "^3.12.0" } -} +} \ No newline at end of file diff --git a/unitTest/LiveMatches.test.ts b/unitTest/LiveMatches.test.ts index afbe3d4..96c5ae4 100644 --- a/unitTest/LiveMatches.test.ts +++ b/unitTest/LiveMatches.test.ts @@ -6,7 +6,7 @@ describe('LiveMatches API', function () { it('retrieves all the live matches url and matchName', async function () { this.timeout(20000); try { - const body = await apiCall(`/liveMatches`); + const body = await apiCall('/liveMatches'); assert.equal(body.status, true); } catch (err) { assert.fail(`${ErrorMessage} ${err.message}`); diff --git a/unitTest/MatchStats.test.ts b/unitTest/MatchStats.test.ts index 0ceccf3..4f85b80 100644 --- a/unitTest/MatchStats.test.ts +++ b/unitTest/MatchStats.test.ts @@ -58,7 +58,7 @@ describe('MatchStats API', function () { it('retrieves stats for all live matches', async function () { try { - const body = await apiCall(`/matchStats`); + const body = await apiCall('/matchStats'); assert.equal(body.status, true); } catch (err) { assert.fail(`${ErrorMessage} ${err.message}`); @@ -85,21 +85,21 @@ describe('MatchStats | getMatchStats function', function () { describe('MatchStats | getTeamData function', function () { - function runTestWithSubsetDeepEqual(inputString: string, expectedOutput: any) { + function runTestWithSubsetDeepEqual(inputString: string, expectedOutput: object) { try { const result = getTeamData(inputString); assertResultSubset(result, expectedOutput); } catch (error) { - assert.fail(`Failed to get team data with input "${inputString}": ${error.message}`); + assert.fail(`Failed to get team data with input '${inputString}': ${error.message}`); } } - function runTestWithDeepEqual(inputString: string, expectedOutput: any) { + function runTestWithDeepEqual(inputString: string, expectedOutput: object) { try { const result = getTeamData(inputString); assert.deepEqual(result, expectedOutput); } catch (error) { - assert.fail(`Failed to get team data with input "${inputString}": ${error.message}`); + assert.fail(`Failed to get team data with input '${inputString}': ${error.message}`); } } @@ -136,7 +136,7 @@ describe('MatchStats | getTeamData function', function () { describe('MatchStats | getTournamentName function', function () { let $; - let matchStatsObj: MatchStats = new MatchStats(); + const matchStatsObj: MatchStats = new MatchStats(); beforeEach(() => { $ = sinon.stub(); diff --git a/unitTest/TestData/Generic.ts b/unitTest/TestData/Generic.ts index 4907c13..f8135b3 100644 --- a/unitTest/TestData/Generic.ts +++ b/unitTest/TestData/Generic.ts @@ -3,4 +3,4 @@ export const testData = { route: '/live', expectedOutput: { status: false, statusMessage: '404 - Page not found' } } -} \ No newline at end of file +}; \ No newline at end of file diff --git a/unitTest/TestData/MatchStats.ts b/unitTest/TestData/MatchStats.ts index f358702..4a7d676 100644 --- a/unitTest/TestData/MatchStats.ts +++ b/unitTest/TestData/MatchStats.ts @@ -13,43 +13,43 @@ export const testData = { status: false, message: 'Error fetching match stats', error: 'No match found with id: nCSAYi2BckuKRVA8' - } + } }, teamDataStandardCase: { inputString: 'CBD 74/3 (9.1)', expectedOutput: { - "name": "CBD", - "score": "74", - "wickets": "3", - "overs": "9.1" + 'name': 'CBD', + 'score': '74', + 'wickets': '3', + 'overs': '9.1' } }, teamDataNoOvers: { inputString: 'CBD 74/3', expectedOutput: { - "name": "CBD", - "score": "74", - "wickets": "3" + 'name': 'CBD', + 'score': '74', + 'wickets': '3' } }, teamDataNoWickets: { inputString: 'IND 436', expectedOutput: { - "name": "IND", - "score": "436", - "wickets": "10" + 'name': 'IND', + 'score': '436', + 'wickets': '10' } }, secondInningsInProgress: { inputString: 'ENG 246 & 316/6 (77)', expectedOutput: { - "name": "ENG", - "score": "316", - "wickets": "6", - "overs": "77", - "previousInnings": { - "score": "246", - "wickets": "10" + 'name': 'ENG', + 'score': '316', + 'wickets': '6', + 'overs': '77', + 'previousInnings': { + 'score': '246', + 'wickets': '10' } } },