aboutsummaryrefslogtreecommitdiff
path: root/tests/DummyResourceAPI.h
diff options
context:
space:
mode:
Diffstat (limited to 'tests/DummyResourceAPI.h')
-rw-r--r--tests/DummyResourceAPI.h47
1 files changed, 47 insertions, 0 deletions
diff --git a/tests/DummyResourceAPI.h b/tests/DummyResourceAPI.h
new file mode 100644
index 00000000..e91be96c
--- /dev/null
+++ b/tests/DummyResourceAPI.h
@@ -0,0 +1,47 @@
+#pragma once
+
+#include <QJsonDocument>
+
+#include <modplatform/ResourceAPI.h>
+
+class SearchTask : public Task {
+ Q_OBJECT
+
+ public:
+ void executeTask() override { emitSucceeded(); }
+};
+
+class DummyResourceAPI : public ResourceAPI {
+ public:
+ static auto searchRequestResult()
+ {
+ static QByteArray json_response =
+ "{\"hits\":["
+ "{"
+ "\"author\":\"flowln\","
+ "\"description\":\"the bestest mod\","
+ "\"project_id\":\"something\","
+ "\"project_type\":\"mod\","
+ "\"slug\":\"bip_bop\","
+ "\"title\":\"AAAAAAAA\","
+ "\"versions\":[\"2.71\"]"
+ "}"
+ "]}";
+
+ return QJsonDocument::fromJson(json_response);
+ }
+
+ DummyResourceAPI() : ResourceAPI() {}
+ [[nodiscard]] auto getSortingMethods() const -> QList<SortingMethod> override { return {}; };
+
+ [[nodiscard]] Task::Ptr searchProjects(SearchArgs&&, SearchCallbacks&& callbacks) const override
+ {
+ auto task = new SearchTask;
+ QObject::connect(task, &Task::succeeded, [=] {
+ auto json = searchRequestResult();
+ callbacks.on_succeed(json);
+ });
+ QObject::connect(task, &Task::finished, task, &Task::deleteLater);
+ return task;
+ }
+};