| 9 | {} |
| 10 | |
| 11 | bool UpdaterServer::create() |
| 12 | { |
| 13 | TEST_WRAP_BEGIN |
| 14 | |
| 15 | QVERIFY(_server->route(QStringLiteral("/test-api/update-check"), [this](const QHttpServerRequest &request) -> QHttpServerResponse { |
| 16 | auto ok = false; |
| 17 | [&](){ |
| 18 | QCOMPARE(request.query(), _testQuery); |
| 19 | ok = true; |
| 20 | }(); |
| 21 | if (!ok) |
| 22 | return QHttpServerResponse::StatusCode::BadRequest; |
| 23 | |
| 24 | if (_versionOnly) { |
| 25 | if (_infos.first().version().isNull()) |
| 26 | return QHttpServerResponse::StatusCode::NoContent; |
| 27 | else |
| 28 | return _infos.first().version().toString(); |
| 29 | } else { |
| 30 | QJsonArray infoArray; |
| 31 | for (const auto &info : _infos) { |
| 32 | QJsonObject infoObj; |
| 33 | infoObj[QStringLiteral("name")] = info.name(); |
| 34 | infoObj[QStringLiteral("version")] = info.version().toString(); |
| 35 | infoObj[QStringLiteral("identifier")] = QJsonValue::fromVariant(info.identifier()); |
| 36 | infoObj[QStringLiteral("data")] = QJsonValue::fromVariant(info.data()); |
| 37 | infoArray.append(infoObj); |
| 38 | } |
| 39 | return infoArray; |
| 40 | } |
| 41 | })); |
| 42 | |
| 43 | QVERIFY(_server->route(QStringLiteral("/test-api/install"), [this](const QHttpServerRequest &request) -> QHttpServerResponse { |
| 44 | QUrlQuery query{QString::fromUtf8(request.body())}; |
| 45 | if (query.queryItemValue(QStringLiteral("success")) == QVariant{true}) { |
| 46 | const auto key = QStringLiteral("version"); |
| 47 | QCoreApplication::setApplicationVersion(query.queryItemValue(key)); |
| 48 | QUrlQuery newQuery; |
| 49 | for (const auto &q : _testQuery.queryItems()) { |
| 50 | if (q.first == key) |
| 51 | newQuery.addQueryItem(key, query.queryItemValue(key)); |
| 52 | else |
| 53 | newQuery.addQueryItem(q.first, q.second); |
| 54 | } |
| 55 | _testQuery = newQuery; |
| 56 | _infos.clear(); |
| 57 | return QHttpServerResponse::StatusCode::NoContent; |
| 58 | } else |
| 59 | return QHttpServerResponse::StatusCode::NotAcceptable; |
| 60 | })); |
| 61 | |
| 62 | QVERIFY(_server->route(QStringLiteral("/test-api/download/<arg>/<arg>"), [this](const QString &id, const QString &version) -> QHttpServerResponse { |
| 63 | if (_infos.size() != 1) |
| 64 | return QHttpServerResponse::StatusCode::BadRequest; |
| 65 | if (_infos[0].identifier() != id) |
| 66 | return QHttpServerResponse::StatusCode::BadRequest; |
| 67 | if (_infos[0].version() != QVersionNumber::fromString(version)) |
| 68 | return QHttpServerResponse::StatusCode::BadRequest; |
no test coverage detected