const test = require('tap').test
const confCal = require('..')
const apiKey = process.env['GOOGLE_API_KEY']
if (!apiKey) {
throw new Error('To run the unit test you need to set the GOOGLE_API_KEY environment variable')
}
const DOC_SAMPLE = `Mighty Superhero Gathering
on 2019/01/01
at Top of the World#ChIJvZ69FaJU6DkRsrqrBvjcdgU
[Main Room]
10:00-10:20 Opening
11:15-12:00 What I love about underground sountracks by Batman
In this special session Batman looks into a often
overlooked benefit of getting to know really special
music played in the bars just while beating up
scum.
13:00-14:00 Lighting talks
- Lassos materials by Wonder Woman
- Leveraging water in battle by Wolverine
- Why we need friends by The Hulk
- 楽しい CM の作り方 by ウルトラマン in ja
[Track A]
10:20-11:00 Doing the right thing by Super Man #keynote
Super Man will talk about the challenges he faced
trying to do the right thing when you are
basically a god
11:15-14:00 Akward bumps of 2018 by The Flash #flash-talk
Its not always easy to travel quickly without colliding
with things. Lightheartedly, the flash will reflect on
the funniest bumps of the last year.`
test('PROJECT USAGE', async t => {
const calendar = await confCal({
apiKey, // The Google API key to call "places"
cache: `${__dirname}/api-documentation.objects` // Store
}, DOC_SAMPLE)
t.deepEquals(
{
title: calendar.title,
location: calendar.location,
date: calendar.date,
googleObjectId: calendar.googleObjectId
},
{
title: 'Mighty Superhero Gathering',
location: 'Top of the World',
date: '20190101',
googleObjectId: 'ChIJvZ69FaJU6DkRsrqrBvjcdgU'
},
'All basic properties are normalized!'
)
t.deepEquals(
{
long_name: calendar.googleObject.name,
place_id: calendar.googleObject.place_id,
rating: calendar.googleObject.rating
},
{
long_name: 'Mount Everest',
place_id: 'ChIJvZ69FaJU6DkRsrqrBvjcdgU',
rating: 4.2
},
'The googleObject is taken straight from the Google API'
)
t.equals(
calendar.googleObject.timeZone,
'Asia/Shanghai',
'... but it has a timeZone added!'
)
t.deepEquals(
Object.keys(calendar.rooms),
['Main Room', 'Track A'],
'The calendar has a handy set of rooms'
)
t.equals(
calendar.rooms['Main Room'].length,
3,
'The room contains a list of entries for that room'
)
t.deepEquals(
Object.keys(calendar.persons),
['Batman', 'Wonder Woman', 'Wolverine', 'The Hulk', 'ウルトラマン', 'Super Man', 'The Flash'],
'There is also a handy list of all the persons that appear in this calendar.'
)
t.equals(
calendar.persons['Batman'].length,
1,
'... and for every person there is an array of entries.'
)
t.equals(
calendar.toMarkdown(),
`## Mighty Superhero Gathering
at [Top of the World](https://maps.google.com/?q=Mount+Everest&ftid=0x39e854a215bd9ebd:0x576dcf806abbab2)
| | Main Room | Track A |
| --- | --- | --- |
| 10:00-10:20 | Opening | ← |
| 10:20-11:00 | → | Doing the right thing _by Super Man_ |
| 11:00-11:15 | [Break] | [Break] |
| 11:15-12:00 | What I love about underground sountracks _by Batman_ | Akward bumps of 2018 _by The Flash_ |
| 12:00-13:00 | [Break] | ⤓ |
| 13:00-14:00 | Lighting talks