From cb981ed3176afc7c2fa51828f6d2fbc2e44000f3 Mon Sep 17 00:00:00 2001 From: Marcos Date: Wed, 25 Mar 2020 02:08:09 -0300 Subject: [PATCH] tests(State): Updating latitude and longititude --- .eslintrc.json | 3 +- __tests__/unit/modules/brazil/spider.test.ts | 7 ++- __tests__/unit/modules/global/spider.test.ts | 6 +-- .../modules/states/services/finder.test.ts | 50 +++++++++---------- .../states/services/mocks/state-mocks.ts | 2 +- package.json | 1 + .../brazil/{spider => crawler}/index.ts | 0 .../brazil/{spider => crawler}/selectors.ts | 0 src/modules/brazil/service.ts | 2 +- .../global/{spider => crawler}/index.ts | 0 .../global/{spider => crawler}/selectors.ts | 0 src/modules/global/service.ts | 2 +- .../services/{finder.ts => data-finder.ts} | 2 +- .../states/services/update-states-data.ts | 2 +- .../{utils.ts => states-informations.ts} | 0 tsconfig.json | 2 +- yarn.lock | 9 +++- 17 files changed, 48 insertions(+), 40 deletions(-) rename src/modules/brazil/{spider => crawler}/index.ts (100%) rename src/modules/brazil/{spider => crawler}/selectors.ts (100%) rename src/modules/global/{spider => crawler}/index.ts (100%) rename src/modules/global/{spider => crawler}/selectors.ts (100%) rename src/modules/states/services/{finder.ts => data-finder.ts} (94%) rename src/modules/states/{utils.ts => states-informations.ts} (100%) diff --git a/.eslintrc.json b/.eslintrc.json index c017a8c..c87f70d 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -1,7 +1,8 @@ { "env": { "browser": true, - "es6": true + "es6": true, + "jest": true }, "extends": [ "plugin:react/recommended", diff --git a/__tests__/unit/modules/brazil/spider.test.ts b/__tests__/unit/modules/brazil/spider.test.ts index 1d5f8f8..e46029b 100644 --- a/__tests__/unit/modules/brazil/spider.test.ts +++ b/__tests__/unit/modules/brazil/spider.test.ts @@ -1,5 +1,5 @@ -import * as path from 'path' -import BrazilSpider from '~/modules/brazil/spider' +import path from 'path' +import BrazilCrawler from '~/modules/brazil/crawler' import { fromMockFile } from '../../../helpers/mock-crawler' const pagePath = path.join(__dirname, 'mocks', 'page.html') @@ -13,8 +13,7 @@ describe('[Unit]:: Global', () => { totalRecovered, activeCases, closedCases - } = BrazilSpider.getData(document) - + } = BrazilCrawler.getData(document) expect(totalCases).toBe(529) expect(totalDeaths).toBe(4) diff --git a/__tests__/unit/modules/global/spider.test.ts b/__tests__/unit/modules/global/spider.test.ts index 94a4c4a..8ca2e85 100644 --- a/__tests__/unit/modules/global/spider.test.ts +++ b/__tests__/unit/modules/global/spider.test.ts @@ -1,5 +1,5 @@ -import * as path from 'path' -import GlobalSpider from '~/modules/global/spider' +import * as path from 'path' +import GlobalCrawler from '~/modules/global/crawler' import { fromMockFile } from '../../../helpers/mock-crawler' const pagePath = path.join(__dirname, 'mocks', 'page.html') @@ -13,7 +13,7 @@ describe('[Unit]:: Global', () => { totalRecovered, activeCases, closedCases - } = GlobalSpider.getData(document) + } = GlobalCrawler.getData(document) expect(totalCases).toBe(219032) expect(totalDeaths).toBe(8953) diff --git a/__tests__/unit/modules/states/services/finder.test.ts b/__tests__/unit/modules/states/services/finder.test.ts index 1178ebe..41c4629 100644 --- a/__tests__/unit/modules/states/services/finder.test.ts +++ b/__tests__/unit/modules/states/services/finder.test.ts @@ -1,40 +1,40 @@ import axios from 'axios' import MockAdapter from 'axios-mock-adapter' -import { getStatesData } from '~/modules/states/services/finder' + +import { getStatesData } from '~/modules/states/services/data-finder' import { stateMocks } from './mocks/state-mocks' const mockAxios = new MockAdapter(axios) mockAxios.onGet('https://raw.githubusercontent.com/wcota/covid19br/master/cases-brazil-total.csv').reply(200, stateMocks) -const expected = [ - { - uf: "SP", - name: "São Paulo", - cases: 459, - casesMS: 459, - casesNotConfirmedByMS: 0, - deaths: 15, - latitude: -9.48000405, - longitude: -35.83996769 - }, - { - uf: "RJ", - name: "Rio de Janeiro", - cases: 119, - casesMS: 119, - casesNotConfirmedByMS: 0, - deaths: 3, - latitude: -9.48000405, - longitude: -35.83996769 - } -] - describe('[Unit]::StatesFinder', () => { describe('getStatesData', () => { it('Deve parsear o csv e retornar os dados continudos no mesmo', async done => { const result = await getStatesData() - expect(result).toEqual(expect.arrayContaining(expected)) + expect(result).toEqual(expect.arrayContaining([ + expect.objectContaining({ + uf: 'SP', + name: 'São Paulo', + cases: 459, + casesMS: 459, + casesNotConfirmedByMS: 0, + deaths: 15, + latitude: -23.55, + longitude: -46.64 + }), + expect.objectContaining({ + uf: 'RJ', + name: 'Rio de Janeiro', + cases: 119, + casesMS: 119, + casesNotConfirmedByMS: 0, + deaths: 3, + latitude: -22.84, + longitude: -43.15 + }) + ])) + done() }) }) diff --git a/__tests__/unit/modules/states/services/mocks/state-mocks.ts b/__tests__/unit/modules/states/services/mocks/state-mocks.ts index 26ce6b8..f9980cd 100644 --- a/__tests__/unit/modules/states/services/mocks/state-mocks.ts +++ b/__tests__/unit/modules/states/services/mocks/state-mocks.ts @@ -2,4 +2,4 @@ export const stateMocks = `country,state,totalCases,totalCasesMS,notConfirmedByM Brazil,TOTAL,1213,1128,85,18,http://plataforma.saude.gov.br/novocoronavirus/ Brazil,SP,459,459,0,15,http://www.saopaulo.sp.gov.br/ Brazil,RJ,119,119,0,3,http://www.rj.gov.br/ -` \ No newline at end of file +` diff --git a/package.json b/package.json index 3c3f155..81b629b 100644 --- a/package.json +++ b/package.json @@ -34,6 +34,7 @@ "eslint": "^6.8.0", "eslint-config-standard": "^14.1.1", "eslint-plugin-import": "^2.20.1", + "eslint-plugin-jest": "^23.8.2", "eslint-plugin-node": "^11.0.0", "eslint-plugin-promise": "^4.2.1", "eslint-plugin-react": "^7.19.0", diff --git a/src/modules/brazil/spider/index.ts b/src/modules/brazil/crawler/index.ts similarity index 100% rename from src/modules/brazil/spider/index.ts rename to src/modules/brazil/crawler/index.ts diff --git a/src/modules/brazil/spider/selectors.ts b/src/modules/brazil/crawler/selectors.ts similarity index 100% rename from src/modules/brazil/spider/selectors.ts rename to src/modules/brazil/crawler/selectors.ts diff --git a/src/modules/brazil/service.ts b/src/modules/brazil/service.ts index c41eaa2..1e9a419 100644 --- a/src/modules/brazil/service.ts +++ b/src/modules/brazil/service.ts @@ -2,7 +2,7 @@ import { logger } from '~/common/logger' import { fromURL, WORLD_METER_URL } from '~/common/spider' import { BrazilCollection } from '~/config/database' -import BrazilSpider from './spider' +import BrazilSpider from './crawler' export const findAndStoreData = async () => { logger.info('Buscando informarções do Brasil') diff --git a/src/modules/global/spider/index.ts b/src/modules/global/crawler/index.ts similarity index 100% rename from src/modules/global/spider/index.ts rename to src/modules/global/crawler/index.ts diff --git a/src/modules/global/spider/selectors.ts b/src/modules/global/crawler/selectors.ts similarity index 100% rename from src/modules/global/spider/selectors.ts rename to src/modules/global/crawler/selectors.ts diff --git a/src/modules/global/service.ts b/src/modules/global/service.ts index ce7dda3..e38ca00 100644 --- a/src/modules/global/service.ts +++ b/src/modules/global/service.ts @@ -1,5 +1,5 @@ import { fromURL, WORLD_METER_URL } from '~/common/spider' -import GlobalSpider from './spider' +import GlobalSpider from './crawler' import { GlobalCollection } from '~/config/database' import { logger } from '~/common/logger' diff --git a/src/modules/states/services/finder.ts b/src/modules/states/services/data-finder.ts similarity index 94% rename from src/modules/states/services/finder.ts rename to src/modules/states/services/data-finder.ts index d0412ce..27790c6 100644 --- a/src/modules/states/services/finder.ts +++ b/src/modules/states/services/data-finder.ts @@ -1,6 +1,6 @@ import axios from 'axios' import Papa from 'papaparse' -import { states } from '~/modules/states/utils' +import { states } from '~/modules/states/states-informations' import { State } from '../typeDefs/State' const URL = 'https://raw.githubusercontent.com/wcota/covid19br/master/cases-brazil-total.csv' diff --git a/src/modules/states/services/update-states-data.ts b/src/modules/states/services/update-states-data.ts index 2ff3b11..cb662f8 100644 --- a/src/modules/states/services/update-states-data.ts +++ b/src/modules/states/services/update-states-data.ts @@ -1,5 +1,5 @@ import { StatesCollection, db } from '~/config/database' -import { getStatesData } from './finder' +import { getStatesData } from './data-finder' import { logger } from '~/common/logger' export const findAndStoreData = async () => { diff --git a/src/modules/states/utils.ts b/src/modules/states/states-informations.ts similarity index 100% rename from src/modules/states/utils.ts rename to src/modules/states/states-informations.ts diff --git a/tsconfig.json b/tsconfig.json index 2b9dc90..b0ea55d 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -25,7 +25,7 @@ "emitDecoratorMetadata": true, "experimentalDecorators": true, "resolveJsonModule": true, - "baseUrl": ".", + "baseUrl": "./", "paths": { "~/*": [ "./src/*" diff --git a/yarn.lock b/yarn.lock index d8e0b86..c46686d 100644 --- a/yarn.lock +++ b/yarn.lock @@ -750,7 +750,7 @@ regexpp "^3.0.0" tsutils "^3.17.1" -"@typescript-eslint/experimental-utils@2.25.0": +"@typescript-eslint/experimental-utils@2.25.0", "@typescript-eslint/experimental-utils@^2.5.0": version "2.25.0" resolved "https://registry.yarnpkg.com/@typescript-eslint/experimental-utils/-/experimental-utils-2.25.0.tgz#13691c4fe368bd377b1e5b1e4ad660b220bf7714" integrity sha512-0IZ4ZR5QkFYbaJk+8eJ2kYeA+1tzOE1sBjbwwtSV85oNWYUBep+EyhlZ7DLUCyhMUGuJpcCCFL0fDtYAP1zMZw== @@ -2165,6 +2165,13 @@ eslint-plugin-import@^2.20.1: read-pkg-up "^2.0.0" resolve "^1.12.0" +eslint-plugin-jest@^23.8.2: + version "23.8.2" + resolved "https://registry.yarnpkg.com/eslint-plugin-jest/-/eslint-plugin-jest-23.8.2.tgz#6f28b41c67ef635f803ebd9e168f6b73858eb8d4" + integrity sha512-xwbnvOsotSV27MtAe7s8uGWOori0nUsrXh2f1EnpmXua8sDfY6VZhHAhHg2sqK7HBNycRQExF074XSZ7DvfoFg== + dependencies: + "@typescript-eslint/experimental-utils" "^2.5.0" + eslint-plugin-node@^11.0.0: version "11.0.0" resolved "https://registry.yarnpkg.com/eslint-plugin-node/-/eslint-plugin-node-11.0.0.tgz#365944bb0804c5d1d501182a9bc41a0ffefed726"