Skip to content

Commit

Permalink
test: Add more tests and run prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
jpedroh committed Nov 16, 2023
1 parent 7d28d83 commit ed215e6
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 11 deletions.
Binary file added packages/rpl-crawler/__mocks__/RPL_NAVBRASIL.zip
Binary file not shown.
13 changes: 9 additions & 4 deletions packages/rpl-crawler/__mocks__/handlers.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import { http } from "msw";
import { http } from 'msw'

export const handlers = [
http.get(`http://portal.cgna.decea.mil.br/files/abas/:date/painel_rpl/companhias/Cia_GLO_CS.txt`, ({ params }) => {
return new Response(null, { status: params.date === '2022-08-22' ? 200 : 404 })
})
http.get(
`http://portal.cgna.decea.mil.br/files/abas/:date/painel_rpl/companhias/Cia_GLO_CS.txt`,
({ params }) => {
return new Response(null, {
status: params.date === '2022-08-22' ? 200 : 404,
})
}
),
]
2 changes: 1 addition & 1 deletion packages/rpl-crawler/setup-test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { beforeAll, afterEach, afterAll } from "vitest"
import { beforeAll, afterEach, afterAll } from 'vitest'
import { server } from './__mocks__/node'

beforeAll(() => server.listen())
Expand Down
15 changes: 15 additions & 0 deletions packages/rpl-crawler/src/rpl-file-lines-extractor/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { readFile } from 'fs/promises'
import path from 'path'
import { test, expect } from 'vitest'
import rplFileLinesExtractor from '.'

test('It extracts the lines from the zip file', async () => {
const file = await readFile(
path.join(__dirname, '../../__mocks__/RPL_NAVBRASIL.zip')
)
const lines = rplFileLinesExtractor(file)

expect(lines).toEqual([
`161123 161123 0004000 ACN5135 C208/L SBAC1730 N0155 065 DCT 0427S03754W/N0150F080 IFR DCT SBFZ0030 EQPT/SDFGR/S PBN/B2C2D2O2S1 OPR/AZUL CONECTA LTDA PER/A RMK/JAH VOADO VMC`,
])
})
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ const makeRplFileLinesExtractor = ({ zip }: { zip: ZipPort }) => {
.listZipFileNames()
.find((fileName) => fileName.startsWith('RPL'))

return zipFile.readFileLines(flightsFileName).split('\n').slice(1)
return zipFile
.readFileLines(flightsFileName)
.split('\n')
.slice(1, -1)
.map((v) => v.trim())
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import { expect, test } from 'vitest'
import updateChecker from './index'

test('The update checker returns true if there are updates for the given date', async () => {
const hasUpdate = await updateChecker("2022-08-22")
const hasUpdate = await updateChecker('2022-08-22')
expect(hasUpdate).toBeTruthy()
})

test('The update checker returns false if there are non updates for the given date', async () => {
const hasUpdate = await updateChecker("2022-08-23")
const hasUpdate = await updateChecker('2022-08-23')
expect(hasUpdate).toBeFalsy()
})
6 changes: 3 additions & 3 deletions packages/rpl-crawler/vitest.config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { defineConfig } from "vitest/config";
import { defineConfig } from 'vitest/config'

export default defineConfig({
test: {
setupFiles: './setup-test.ts'
}
setupFiles: './setup-test.ts',
},
})

0 comments on commit ed215e6

Please sign in to comment.