void RestClientTests::testGet() { RestClient client; QJsonDocument* jsonResponse = client.getJson(QUrl(QString("http://localhost:5000/api/colors"))); QCOMPARE(client.statusCode(), 200); QJsonObject jsonRootObject = jsonResponse->object(); QJsonValue value = jsonRootObject.value("data"); QJsonArray jsonArray = value.toArray(); QCOMPARE(jsonArray.count(), 6); foreach (const QJsonValue& current, jsonArray) { QVERIFY(!current.toObject().value("name").toString().isEmpty()); QVERIFY(!current.toObject().value("value").toString().isEmpty()); }
void getColors() { qDebug() << "########## GET REQUEST TEST ##########"; qDebug() << "########## GET LIST ##########"; RestClient client; QJsonDocument* jsonResponse = client.getJson(QUrl(QString("http://localhost:5000/api/colors"))); qDebug() << "Response: " << jsonResponse->toJson(); QJsonObject jsonRootObject = jsonResponse->object(); QJsonValue value = jsonRootObject.value("data"); QJsonArray jsonArray = value.toArray(); foreach (const QJsonValue& current, jsonArray) { qDebug() << "Name: " << current.toObject().value("name").toString(); qDebug() << "Value: " << current.toObject().value("value").toString(); }