From 604d0ef151165c0c9b46c863dcd22fcd09828113 Mon Sep 17 00:00:00 2001 From: German Robayo Date: Mon, 25 Nov 2019 19:18:09 -0400 Subject: [PATCH 1/2] cast string to number where necessary --- src/calculator/routes.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/calculator/routes.ts b/src/calculator/routes.ts index 89cac07..bb4d931 100644 --- a/src/calculator/routes.ts +++ b/src/calculator/routes.ts @@ -43,7 +43,7 @@ calculatorRoutes.get('/twitter/social/:userId', validate('socialCredibility'), a if (!errors.isEmpty()){ errorMapper(errors.array()) } - const socialCredibilityVal = await socialCredibility(req.params.userId, req.query.maxFollowers) + const socialCredibilityVal = await socialCredibility(req.params.userId, +req.query.maxFollowers) res.send(socialCredibilityVal) })) @@ -59,7 +59,7 @@ calculatorRoutes.get('/twitter/tweets', validate('tweetCredibility'), asyncWrap( weightSocial: +req.query.weightSocial, weightText: +req.query.weightText, weightUser: +req.query.weightUser }, - req.query.maxFollowers)) + +req.query.maxFollowers)) })) calculatorRoutes.get('/social/scrape', validate('scrapedSocialCredibility'), function(req, res){ @@ -67,7 +67,7 @@ calculatorRoutes.get('/social/scrape', validate('scrapedSocialCredibility'), fun if (!errors.isEmpty()){ errorMapper(errors.array()) } - res.send(scrapedSocialCredibility(req.query.followersCount, req.query.friendsCount, req.query.maxFollowers)) + res.send(scrapedSocialCredibility(+req.query.followersCount, +req.query.friendsCount, +req.query.maxFollowers)) }) calculatorRoutes.get('/tweets/scraped', validate('scrapedTweetCredibility'), asyncWrap(async function(req, res){ @@ -92,7 +92,7 @@ calculatorRoutes.get('/tweets/scraped', validate('scrapedTweetCredibility'), asy yearJoined: +req.query.yearJoined, followersCount: +req.query.followersCount, friendsCount: +req.query.friendsCount - }, req.query.maxFollowers)) + }, +req.query.maxFollowers)) })) export default calculatorRoutes From 311fd0d37b11c4fd7b6d28509afbb66dd307ad8d Mon Sep 17 00:00:00 2001 From: German Robayo Date: Mon, 25 Nov 2019 19:34:57 -0400 Subject: [PATCH 2/2] ammend test --- tests/calculus-endpoints/social-scrapped.test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/calculus-endpoints/social-scrapped.test.ts b/tests/calculus-endpoints/social-scrapped.test.ts index 4667fb4..b1487f2 100644 --- a/tests/calculus-endpoints/social-scrapped.test.ts +++ b/tests/calculus-endpoints/social-scrapped.test.ts @@ -23,8 +23,8 @@ describe('/calculate/social/scrape endpoint', () => { friendsCount: 421, maxFollowers: 2000000 } - it('returns credibility=30.04999998245834 with', () => { - return testCredibilityWithOkData({ credibility: 30.04999998245834 }, params) + it('returns credibility=79.98246448537638 with', () => { + return testCredibilityWithOkData({ credibility: 79.98246448537638 }, params) }) })