Commit 8576bf9e authored by Volker Krause's avatar Volker Krause
Browse files

Use and test proper content type for JSON responses

parent cffaa355
......@@ -41,6 +41,8 @@ public function get_products()
$db = new DataStore();
$products = Product::allProducts($db);
$json = json_encode($products);
header('Content-Type: text/json');
echo($json);
}
......@@ -95,6 +97,8 @@ public function get_data($productName)
$product = Product::productByName($db, $productName);
if (is_null($product))
throw new RESTException('Product not found.', 404);
header('Content-Type: text/json');
echo(Sample::dataAsJson($db, $product));
}
......@@ -106,6 +110,8 @@ public function get_surveys($productName)
$db = new DataStore();
$surveys = Survey::surveysForProduct($db, $productName);
header('Content-Type: text/json');
echo(json_encode($surveys));
}
......
......@@ -48,6 +48,7 @@ function post_submit($productName)
$responseData['surveys'] = $surveys;
$db->commit();
header('Content-Type: text/json');
echo(json_encode($responseData));
}
......
......@@ -100,6 +100,7 @@ private slots:
reply = RESTApi::listProducts(&client);
QVERIFY(waitForFinished(reply));
QCOMPARE(reply->error(), QNetworkReply::NoError);
QCOMPARE(reply->header(QNetworkRequest::ContentTypeHeader).toString(), QLatin1String("text/json"));
const auto products = Product::fromJson(reply->readAll());
QVERIFY(!findProduct(products, QLatin1String("org.kde.UserFeedback.UnitTestProduct")).isValid());
......
......@@ -96,11 +96,12 @@ private slots:
provider.addDataSource(new ScreenInfoSource, Provider::AllStatistics);
provider.addDataSource(new PlatformInfoSource, Provider::AllStatistics);
provider.submit();
QTest::qWait(10); // HACK submit is async
QTest::qWait(100); // HACK submit is async
// retrieve data
reply = RESTApi::listSamples(&client, p);
QVERIFY(waitForFinished(reply));
QCOMPARE(reply->header(QNetworkRequest::ContentTypeHeader).toString(), QLatin1String("text/json"));
auto doc = QJsonDocument::fromJson(reply->readAll());
QVERIFY(doc.isArray());
auto a = doc.array();
......
......@@ -94,6 +94,7 @@ private slots:
auto reply = RESTApi::listSurveys(&client, p);
QVERIFY(waitForFinished(reply));
QCOMPARE(reply->error(), QNetworkReply::NoError);
QCOMPARE(reply->header(QNetworkRequest::ContentTypeHeader).toString(), QLatin1String("text/json"));
auto surveys = Survey::fromJson(reply->readAll());
QVERIFY(surveys.isEmpty());
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment