-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ci skip]
- Loading branch information
Showing
1 changed file
with
36 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
'use strict' | ||
|
||
const assert = require('assert') | ||
const flix = require('.') | ||
|
||
const find = (name, stream) => { | ||
return new Promise((resolve, reject) => { | ||
stream.once('error', reject) | ||
stream.on('data', (item) => { | ||
if (item.name === name) resolve(item) | ||
}) | ||
stream.once('end', () => resolve(null)) | ||
}) | ||
} | ||
|
||
;(async () => { | ||
const berlin = await find('Berlin', flix.regions.all()) | ||
assert.ok(berlin, 'Berlin not found') | ||
const hamburg = await find('Hamburg', flix.regions.all()) | ||
assert.ok(hamburg, 'Hamburg not found') | ||
const berlinAlexanderplatz = await find('Berlin Alexanderplatz', flix.stations.all()) | ||
assert.ok(berlinAlexanderplatz, 'Berlin Alexanderplatz not found') | ||
|
||
const [journey] = await flix.journeys(berlin, hamburg, { | ||
departureAfter: new Date('2020-06-01T08:00+02:00'), | ||
results: 1, | ||
}) | ||
console.error(journey) | ||
|
||
const [depAtAlexanderplatz] = await flix.departures(berlinAlexanderplatz) | ||
console.error(depAtAlexanderplatz) | ||
})() | ||
.catch((err) => { | ||
console.error(err) | ||
process.exit(1) | ||
}) |