~aleteoryx/muditaos

ref: 898de0540cf40c516edc2bac6456616953035989 muditaos/module-services/service-db/test/test-service-db-quotes.cpp -rw-r--r-- 2.7 KiB
898de054 — Mateusz Grzegorzek [EGD-5932] Create Quotes agent 5 years ago
                                                                                
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include <catch2/catch.hpp>

#include "test-service-db-quotes.hpp"

using namespace Quotes;

constexpr auto totalNumOfCategoriesInDb = 6;
constexpr auto totalNumOfQuotesInDb     = 48;

TEST_CASE("Quotes")
{
    Database::initialize();

    auto tester = std::make_unique<QuotesAgentTester>(nullptr);

    SECTION("Get categories with limit and offset")
    {
        CategoryList categoryList;
        categoryList.limit  = 2;
        categoryList.offset = 1;

        auto record  = std::make_unique<CategoryList>(categoryList);
        auto request = std::make_shared<Messages::GetCategoryListRequest>(std::move(record));
        auto response =
            std::dynamic_pointer_cast<Messages::GetCategoryListResponse>(tester->handleCategoryList(request.get()));

        REQUIRE(response->getCount() == totalNumOfCategoriesInDb);
        REQUIRE(response->getResults().size() == categoryList.limit);
    }

    SECTION("Get all categories")
    {
        CategoryList categoryList;
        categoryList.limit = 0;

        auto record  = std::make_unique<CategoryList>(categoryList);
        auto request = std::make_shared<Messages::GetCategoryListRequest>(std::move(record));
        auto response =
            std::dynamic_pointer_cast<Messages::GetCategoryListResponse>(tester->handleCategoryList(request.get()));

        REQUIRE(response->getCount() == totalNumOfCategoriesInDb);
        REQUIRE(response->getResults().size() == totalNumOfCategoriesInDb);
    }

    SECTION("Get quotes with limit and offset")
    {
        QuotesList quotesList;
        quotesList.limit  = 3;
        quotesList.offset = 4;

        auto record  = std::make_unique<QuotesList>(quotesList);
        auto request = std::make_shared<Messages::GetQuotesListRequest>(std::move(record));
        auto response =
            std::dynamic_pointer_cast<Messages::GetQuotesListResponse>(tester->handleQuotesList(request.get()));

        REQUIRE(response->getCount() == totalNumOfQuotesInDb);
        REQUIRE(response->getResults().size() == quotesList.limit);
    }

    SECTION("Get all quotes")
    {
        QuotesList quotesList;
        quotesList.limit = 0;

        auto record  = std::make_unique<QuotesList>(quotesList);
        auto request = std::make_shared<Messages::GetQuotesListRequest>(std::move(record));
        auto response =
            std::dynamic_pointer_cast<Messages::GetQuotesListResponse>(tester->handleQuotesList(request.get()));

        REQUIRE(response->getCount() == totalNumOfQuotesInDb);
        REQUIRE(response->getResults().size() == totalNumOfQuotesInDb);
    }

    Database::deinitialize();
}