Skip to content

Commit

Permalink
Handle incident dates separated by em
Browse files Browse the repository at this point in the history
  • Loading branch information
kremio committed Oct 25, 2018
1 parent 83cc3a3 commit b9fe5b5
Show file tree
Hide file tree
Showing 3 changed files with 262 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/report.js
Expand Up @@ -38,8 +38,13 @@ const parseDate = (date) => {
*/
const parseH1 = (text) => {
const [date, ...title] = text.split("–")
let days
if( date.trim().length < 4 ){ //the days were separated with "–"
days = [date, title.shift()]
}else{
//(d./)?d. Monat YYYY
const days = date.trim().split('/')
days = date.trim().split('/')
}
const {day, month, year} = parseDate( days.pop() )

//Create dates for all the days
Expand Down
14 changes: 14 additions & 0 deletions tests/lib/report.test.js
Expand Up @@ -23,6 +23,7 @@ jest.mock('request')
const sampleReport = fs.readFileSync('./tests/samples/report.html', 'utf8')
const reportWithoutYear = fs.readFileSync('./tests/samples/report_no_year.html', 'utf8')
const reportWithShortDateInSource = fs.readFileSync('./tests/samples/short_date_in_sources.html', 'utf8')
const daysSeparatedWithEm = fs.readFileSync('./tests/samples/daysSeparatedWithEm.html', 'utf8')

request.mockImplementation((...args) => {
const cb = args.pop()
Expand Down Expand Up @@ -75,3 +76,16 @@ test( 'Parse shortdate notation in source', async() => {
const result = await scrapeReport( 'https://domain.tld/path/to/page.html' )
expect( validateSchema(result) ).toBeTruthy()
})


test( 'Parse days separated with em', async() => {
request.mockImplementationOnce((...args) => {
const cb = args.pop()
cb( null, {statusCode: 200}, daysSeparatedWithEm )
})
const result = await scrapeReport( 'https://domain.tld/path/to/page.html' )
expect( validateSchema(result) ).toBeTruthy()
})



0 comments on commit b9fe5b5

Please sign in to comment.