Contents

Search for stops

In order to find out where to go As a developer I want to find stops using a simple yet powerful API

Background:

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

Scenario: Find stop by name

  • Given the following stop documents:
    _idnameaddress
    1Dworzec GłównyBasztowa
    2Dworzec Towarowy
    3Basztowa LOTDługa
  • And an indexed database
  • When I send a GET request to http://api.bagate.la/foo/_search/Stop?q=Basztowa
  • Then the response status should be 200
  • And the result should be stops: 3, 1
  • When I send a GET request to http://api.bagate.la/foo/_search/Stop?q=name:Dworzec
  • Then the response status should be 200
  • And the result should be stops: 1, 2
  • When I send a GET request to http://api.bagate.la/foo/_search/Stop?q=dł*
  • Then the response status should be 200
  • And the result should be stop: 3
  • When I send a GET request to http://api.bagate.la/foo/_search/Stop?q=Basztowa,Długa
  • Then the response status should be 200
  • And the result should be stop: 3

Scenario: Find stops within a given radius

  • Given the following stop documents:
    _idnameaddresslocation
    1Dworzec GłównyBasztowa{ "lat": 50.064708, "lon": 19.944381 }
    2Dworzec GłównyLubicz{ "lat": 50.064662, "lon": 19.945671 }
    3Dworzec GłównyWesterplatte{ "lat": 50.064123, "lon": 19.945086 }
    4Basztowa LOTDługa{ "lat": 50.066495, "lon": 19.938925 }
    5Basztowa LOTBasztowa{ "lat": 50.066163, "lon": 19.938675 }
  • And an indexed database
  • When I send a GET request to http://api.bagate.la/foo/_search/Stop:
    {
      "query": {
        "filtered": {
          "query" : {
            "match_all": {}
          },
          "filter" : {
            "geo_distance" : {
              "distance" : "0.1km",
              "location" : {
                "lat" : 50.0646,
                "lon" : 19.9451
              }
            }
          }
        }
      }
    }
  • Then the response status should be 200
  • And the result should be stops: 1, 2, 3
  • When I send a GET request to http://api.bagate.la/foo/_search/Stop:
    {
      "query": {
        "filtered" : {
          "query" : {
            "field" : { "address" : "Basztowa" }
          },
          "filter" : {
            "geo_distance" : {
              "distance" : "1km",
              "location" : {
                "lat" : 50.0646,
                "lon" : 19.9451
              }
            }
          }
        }
      }
    }
  • Then the response status should be 200
  • And the result should be stops: 1, 5

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