
import chai from 'chai'
import {fetchLightnings} from '../src/fmi-lightnings.js'
import dateFns from 'date-fns'

const {expect} = chai
const {setMilliseconds, setMinutes, setSeconds, subMinutes} = dateFns

describe('FMI lightning data set parser', () => {
  it('Should not fail on an empty set of frame dates', async () => {
    const lightnings = await fetchLightnings([])
    expect(lightnings).to.deep.equal([])
  })

  it('Should find some lightning locations (depending on weather naturally)', async () => {
    const time2 = closestFullHour()
    const time1 = subMinutes(time2, 5)
    const frameDates = [time1, time2]
    const lightningFrames = await fetchLightnings(frameDates)
    expect(lightningFrames).to.have.lengthOf(frameDates.length)
    lightningFrames.forEach(lightningFrame => {
      expect(lightningFrame).to.have.property('locations')
      expect(lightningFrame.locations).to.be.an('array')
      lightningFrame.locations.forEach(location => {
        expect(location).to.be.an('array')
        expect(location).have.lengthOf(2)
        expect(location[0]).to.be.a('number')
        expect(location[1]).to.be.a('number')
      })
      expect(lightningFrame).to.have.property('timestamp')
      expect(lightningFrame.timestamp).to.be.a('string')
    })
  })
})

function closestFullHour() {
  return setMinutes(setSeconds(setMilliseconds(Date.now(), 0), 0), 0)
}
@@ -415,16 +415,450 @@
 )%0A  %7D)%0A%0A
+  it('Should parse large set of lightning locations from local FMI data', async () =%3E %7B%0A    const frameDates = %5Bnew Date('2019-06-07T13:55:00Z'), new Date('2019-06-07T14:00:00Z')%5D%0A    const lightningFrames = await fetchLightnings(frameDates)%0A    verifyLightningStructure(lightningFrames, frameDates)%0A    expect(lightningFrames%5B0%5D.locations).to.have.lengthOf(1711)%0A    expect(lightningFrames%5B1%5D.locations).to.have.lengthOf(1813)%0A  %7D)%0A%0A
   it('Sh
@@ -924,16 +924,29 @@
 turally)
+ from FMI API
 ', async
@@ -1123,32 +1123,162 @@
 s(frameDates)%0A  
+  verifyLightningStructure(lightningFrames, frameDates)%0A  %7D)%0A%7D)%0A%0Afunction verifyLightningStructure(lightningFrames, frameDates) %7B%0A
   expect(lightni
@@ -1323,18 +1323,16 @@
 length)%0A
-  
   lightn
@@ -1365,26 +1365,24 @@
 gFrame =%3E %7B%0A
-  
     expect(l
@@ -1426,26 +1426,24 @@
 tions')%0A    
-  
 expect(light
@@ -1485,18 +1485,16 @@
 y')%0A    
-  
 lightnin
@@ -1534,26 +1534,24 @@
  =%3E %7B%0A      
- 
- 
 expect(locat
@@ -1571,34 +1571,32 @@
 ('array')%0A      
-  
 expect(location)
@@ -1596,16 +1596,19 @@
 cation).
+to.
 have.len
@@ -1616,18 +1616,16 @@
 thOf(2)%0A
-  
       ex
@@ -1662,26 +1662,24 @@
 ber')%0A      
- 
- 
 expect(locat
@@ -1708,23 +1708,19 @@
 r')%0A    
-  
 %7D)%0A
-  
     expe
@@ -1768,26 +1768,24 @@
 stamp')%0A    
-  
 expect(light
@@ -1827,22 +1827,14 @@
 g')%0A
-    %7D)%0A
   %7D)%0A%7D
-)
 %0A%0Afu
@@ -1931,8 +1931,9 @@
 0), 0)%0A%7D
+%0A

Add test case with local FMI lightning data