Welcome to mirror list, hosted at ThFree Co, Russian Federation.

rutaxi_tests.cpp « partners_api_tests « partners_api - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: aca011d121ac0f27e3c0656b50d1b807cdbdeab5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#include "testing/testing.hpp"

#include "partners_api/rutaxi_api.hpp"

#include "platform/platform.hpp"

#include "geometry/latlon.hpp"

#include <string>

namespace
{
class DelegateForTesting : public taxi::Delegate
{
public:
  storage::TCountriesVec GetCountryIds(m2::PointD const & point) override { return {""}; }
  std::string GetCityName(m2::PointD const & point) override { return ""; }
  storage::TCountryId GetMwmId(m2::PointD const & point) override { return ""; }
};

using Runner = Platform::ThreadRunner;

auto const kNearObject = R"(
{
  "success": true,
  "time": "2018-09-07 16:20:52",
  "data": {
    "objects": [
      {
        "id": "467",
        "house": "6ст3",
        "name": "Булатниковский проезд",
        "metatype": 0
      }
    ],
    "status": 220
  }
})";

UNIT_TEST(RuTaxi_GetNearObject)
{
  ms::LatLon pos(55.592522, 37.653501);
  std::string result;
  taxi::rutaxi::RawApi::GetNearObject(pos, "moscow", result);
  TEST(!result.empty(), ());
  LOG(LINFO, (result));

  my::Json root(result.c_str());

  TEST(json_is_object(root.get()), ());

  bool success = false;
  FromJSONObject(root.get(), "success", success);

  TEST(success, ());
}

UNIT_TEST(RuTaxi_GetCost)
{
  taxi::rutaxi::Object from = {"3440", "2"};
  taxi::rutaxi::Object to = {"467", "6ст3"};
  std::string result;
  taxi::rutaxi::RawApi::GetCost(from, to, "moscow", result);
  TEST(!result.empty(), ());
  LOG(LINFO, (result));

  my::Json root(result.c_str());

  TEST(json_is_object(root.get()), ());

  bool success = false;
  FromJSONObject(root.get(), "success", success);

  TEST(success, ());
}

UNIT_TEST(RuTaxi_MakeNearObject)
{
  taxi::rutaxi::Object dst;
  taxi::rutaxi::MakeNearObject(kNearObject, dst);
  TEST_EQUAL(dst.m_id, "467", ());
  TEST_EQUAL(dst.m_house, "6ст3", ());
}

UNIT_TEST(RuTaxi_MakeProducts)
{
  auto const src = R"(
  {
    "success": true,
    "time": "2018-09-07 16:20:53",
    "data": {
      "cost": "1005",
      "status": 220
    }
  })";

  taxi::rutaxi::Object from;
  taxi::rutaxi::MakeNearObject(kNearObject, from);
  taxi::rutaxi::Object to;
  taxi::rutaxi::MakeNearObject(kNearObject, to);
  taxi::rutaxi::City city = {"moscow", "RUB"};

  std::vector<taxi::Product> dst;
  taxi::rutaxi::MakeProducts(src, from, to, city, dst);
  TEST_EQUAL(dst.size(), 1, ());
  TEST_EQUAL(dst[0].m_price, "1005", ());
  TEST_EQUAL(dst[0].m_currency, "RUB", ());

  TEST(!dst[0].m_productId.empty(), ());
  TEST(!dst[0].m_time.empty(), ());
  TEST(dst[0].m_name.empty(), ());
}

UNIT_TEST(RuTaxi_LoadCityMapping)
{
  auto const mapping = taxi::rutaxi::LoadCityMapping();
  TEST(!mapping.empty(), ());

  for (auto const & item : mapping)
  {
    TEST(!item.second.m_id.empty(), ());
    TEST(!item.second.m_currency.empty(), ());
  }
}
}  // namespace