aboutsummaryrefslogtreecommitdiff
path: root/tests/DummyResourceAPI.h
blob: 0cc909584d503d8267e31c8f705177b8d27c99d2 (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
#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 = makeShared<SearchTask>();
        QObject::connect(task.get(), &Task::succeeded, [=] {
            auto json = searchRequestResult();
            callbacks.on_succeed(json);
        });
        return task;
    }
};