Contents

Querying stops

In order to provide users with detailed information about their journey As a developer I want to build applications which have easy access to stops details

Background:

  • Given an empty database "foo"
  • And design documents

Scenario: Find stop by name

  • Given the following stop documents:
    _idnameaddress
    1BagatelaDunajewskiego
    2BagatelaKarmelicka
    3BagatelaPodwale
  • When I send a GET request to http://api.bagate.la/foo/_design/Stops/_view/by_name?key=["Bagatela","Karmelicka"]&reduce=false
  • Then the response status should be 200
  • And the response without rows' value._rev should be:
    {"total_rows":3,"offset":1,"rows":[
      {"id":"2","key":["Bagatela","Karmelicka"],"value": {"_id": "2", "name": "Bagatela", "address": "Karmelicka", "type": "Stop"}}
    ]}

Scenario: Find stops by name

@by_name

  • Given the following stop documents:
    _idnameaddress
    1BagatelaDunajewskiego
    2BagatelaKarmelicka
    3BagatelaPodwale
  • When I send a GET request to http://api.bagate.la/foo/_design/Stops/_view/by_name?reduce=false&startkey=["Bagatela"]&endkey=["Bagatela",{}]
  • Then the response status should be 200
  • And the response without rows' value._rev should be:
    {"total_rows":3, "offset":0, "rows":[
      {"id":"1", "key":["Bagatela", "Dunajewskiego"], "value": {"_id": "1", "name": "Bagatela", "address": "Dunajewskiego", "type": "Stop"}},
      {"id":"2", "key":["Bagatela", "Karmelicka"], "value": {"_id": "2", "name": "Bagatela", "address": "Karmelicka", "type": "Stop"}},
      {"id":"3", "key":["Bagatela", "Podwale"], "value": {"_id": "3", "name": "Bagatela", "address": "Podwale", "type": "Stop"}}
    ]}

Scenario: Attempt to find stops which do not exist

@by_name

  • When I send a GET request to http://api.bagate.la/foo/_design/Stops/_view/by_name?reduce=false&startkey=["Utopia"]&endkey=["Utopia",{}]
  • Then the response status should be 200
  • And the response should be:
    {"total_rows":0, "offset":0, "rows":[]}

Scenario: Get hub location

@by_name

  • Given the following stop documents:
    _idnameaddresslocation
    1BagatelaDunajewskiego{"lat":3, "lon":7.6}
    2BagatelaKarmelicka{"lat":4, "lon":8.2}
    3BagatelaPodwale{"lat":8, "lon":8.2}
  • When I send a GET request to http://api.bagate.la/foo/_design/Stops/_view/by_name?startkey=["Bagatela"]&endkey=["Bagatela",{}]&group_level=1
  • Then the response status should be 200
  • And the response should be:
    {"rows":[
      {"key":["Bagatela"], "value":{"docs":["3","2","1"], "location":{"lat":5, "lon":8}}}
    ]}

Scenario: Find stops in line

@by_line

  • Given the following stop documents:
    _idname
    1Cmentarz Rakowicki
    2Cmentarz Rakowicki
    3Rakowiecka
    4Uniwersytet Ekonomiczny
    5Lubicz
    6Dworzec Główny
    7Basztowa LOT
    8Teatr Bagatela
    9Filharmonia
    10Jubilat
    11Komorowskiego
    12Flisacka
    13Salvator
  • And the following timetable documents:
    _idstopstop_idlineroutesource
    14Cmentarz Rakowicki12CMENTARZ - Rakowicka, Lubicz - SALWATORa
    15Cmentarz Rakowicki22CMENTARZ - Rakowicka, Lubicz - SALWATORb
    16Rakowiecka32CMENTARZ - Rakowicka, Lubicz - SALWATORc
    17Uniwersytet Ekonomiczny42CMENTARZ - Rakowicka, Lubicz - SALWATORd
    18Lubicz52CMENTARZ - Rakowicka, Lubicz - SALWATORe
    19Dworzec Główny62CMENTARZ - Rakowicka, Lubicz - SALWATORf
    20Basztowa LOT72CMENTARZ - Rakowicka, Lubicz - SALWATORg
    21Teatr Bagatela82CMENTARZ - Rakowicka, Lubicz - SALWATORh
    22Filharmonia92CMENTARZ - Rakowicka, Lubicz - SALWATORi
    23Jubilat102CMENTARZ - Rakowicka, Lubicz - SALWATORj
    24Komorowskiego112CMENTARZ - Rakowicka, Lubicz - SALWATORk
    25Flisacka122CMENTARZ - Rakowicka, Lubicz - SALWATORl
  • When I send a GET request to http://api.bagate.la/foo/_design/Stops/_view/by_line?startkey=["2", "SALWATOR"]&endkey=["2", "SALWATOR", {}]&include_docs=true
  • Then the response status should be 200
  • And the response without rows' doc._rev should be:
    {"total_rows":12, "offset":0, "rows":[
      {"id":"14","key":["2","SALWATOR","a"],"value":{"_id":"1"},"doc":{"_id":"1","name":"Cmentarz Rakowicki","type":"Stop"}},
      {"id":"15","key":["2","SALWATOR","b"],"value":{"_id":"2"},"doc":{"_id":"2","name":"Cmentarz Rakowicki","type":"Stop"}},
      {"id":"16","key":["2","SALWATOR","c"],"value":{"_id":"3"},"doc":{"_id":"3","name":"Rakowiecka","type":"Stop"}},
      {"id":"17","key":["2","SALWATOR","d"],"value":{"_id":"4"},"doc":{"_id":"4","name":"Uniwersytet Ekonomiczny","type":"Stop"}},
      {"id":"18","key":["2","SALWATOR","e"],"value":{"_id":"5"},"doc":{"_id":"5","name":"Lubicz","type":"Stop"}},
      {"id":"19","key":["2","SALWATOR","f"],"value":{"_id":"6"},"doc":{"_id":"6","name":"Dworzec Główny","type":"Stop"}},
      {"id":"20","key":["2","SALWATOR","g"],"value":{"_id":"7"},"doc":{"_id":"7","name":"Basztowa LOT","type":"Stop"}},
      {"id":"21","key":["2","SALWATOR","h"],"value":{"_id":"8"},"doc":{"_id":"8","name":"Teatr Bagatela","type":"Stop"}},
      {"id":"22","key":["2","SALWATOR","i"],"value":{"_id":"9"},"doc":{"_id":"9","name":"Filharmonia","type":"Stop"}},
      {"id":"23","key":["2","SALWATOR","j"],"value":{"_id":"10"},"doc":{"_id":"10","name":"Jubilat","type":"Stop"}},
      {"id":"24","key":["2","SALWATOR","k"],"value":{"_id":"11"},"doc":{"_id":"11","name":"Komorowskiego","type":"Stop"}},
      {"id":"25","key":["2","SALWATOR","l"],"value":{"_id":"12"},"doc":{"_id":"12","name":"Flisacka","type":"Stop"}}
    ]}

Scenario: Find line's route polyline

@polylines

  • Given the following stop documents:
    _idnamepolylines
    1Pierwszy{ "2": [[0,0], [1,1]] }
    2Środkowy{ "3": [[1,1], [2,2]] }
  • And the following timetable documents:
    linestop_iddestination
    L1OSTATNI
    L2OSTATNI
    L3OSTATNI
  • When I send a GET request to http://api.bagate.la/foo/_design/Stops/_list/polyline/by_line?startkey=["L", "OSTATNI"]&endkey=["L", "OSTATNI", {}]&include_docs=true
  • Then the response status should be 200
  • And the response should be:
    {"total_rows": 2, "rows": [
      {"id": "1:2", "value": {"type": "Polyline", "points": [[0,0], [1,1]]}},
      {"id": "2:3", "value": {"type": "Polyline", "points": [[1,1], [2,2]]}}
    ]}

Scenario: Attributes filtering

@filter

  • Given the following stop documents:
    _idnamelatlonaddress
    1Bagatela50.0638008119.93320084Dunajewskiego
    2Bagatela50.063720719.93255997Karmelicka
    3Bagatela50.0630989119.9326992Podwale
  • When I send a GET request to http://api.bagate.la/foo/_design/Stops/_list/filter/by_name?startkey=["Bagatela"]&endkey=["Bagatela",{}]&reduce=false&only=lat,lon
  • Then the response status should be 200
  • And the response should be:
    {"total_rows":3,"offset":0,"rows":[
      {"id":"1","key":["Bagatela","Dunajewskiego"],"value":{"lat":"50.06380081","lon":"19.93320084"}},
      {"id":"2","key":["Bagatela","Karmelicka"],"value":{"lat":"50.0637207","lon":"19.93255997"}},
      {"id":"3","key":["Bagatela","Podwale"],"value":{"lat":"50.06309891","lon":"19.9326992"}}
    ]}
  • When I send a GET request to http://api.bagate.la/foo/_design/Stops/_list/filter/by_name?startkey=["Bagatela"]&endkey=["Bagatela",{}]&reduce=false&except=_rev,lat,lon
  • Then the response status should be 200
  • And the response should be:
    {"total_rows":3,"offset":0,"rows":[
      {"id":"1","key":["Bagatela","Dunajewskiego"],"value":{"_id":"1","name":"Bagatela","address":"Dunajewskiego","type":"Stop"}},
      {"id":"2","key":["Bagatela","Karmelicka"],"value":{"_id":"2","name":"Bagatela","address":"Karmelicka","type":"Stop"}},
      {"id":"3","key":["Bagatela","Podwale"],"value":{"_id":"3","name":"Bagatela","address":"Podwale","type":"Stop"}}
    ]}

Source: features/stops/design.feature at commit 70ec5050, Bagatela (GPL license).