~aleteoryx/muditaos

ref: sign_test muditaos/module-db/tests/NotesTable_tests.cpp -rw-r--r-- 1.8 KiB
a217eeb3 — Dawid Wojtas [BH-2024] Fix lack of alarm directory after updating software 1 year, 5 months 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
// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include <catch2/catch.hpp>
#include "Helpers.hpp"

#include <filesystem>
#include <Tables/NotesTable.hpp>
#include "module-db/databases/NotesDB.hpp"

TEST_CASE("Notes Table tests")
{
    db::tests::DatabaseUnderTest<NotesDB> notesDb{"notes.db", db::tests::getPurePhoneScriptsPath()};

    NotesTable table{&notesDb.get()};
    table.removeAll();
    REQUIRE(table.count() == 0);

    constexpr auto testSnippet = "TEST SNIPPET";

    NotesTableRow rowIn;
    rowIn.snippet = testSnippet;

    table.add(rowIn);
    REQUIRE(table.count() == 1);

    SECTION("Get notes")
    {
        const auto &records = table.getLimitOffset(0, table.count());
        REQUIRE(records.size() == table.count());
        REQUIRE(records[0].snippet == testSnippet);
    }

    SECTION("Get notes by text query")
    {
        constexpr auto testSearch   = "TEST";
        const auto [records, count] = table.getByText(testSearch, 0, 1);
        REQUIRE(records.size() == 1);
        REQUIRE(records[0].snippet == testSnippet);
    }

    SECTION("Add a note")
    {
        NotesTableRow row;
        row.snippet = testSnippet;
        table.add(row);
        REQUIRE(table.count() == 2);
    }

    SECTION("Update a note")
    {
        constexpr auto testId             = 1;
        constexpr auto testSnippetUpdated = "UPDATED TEST SNIPPET";
        NotesTableRow row;
        row.ID      = testId;
        row.snippet = testSnippetUpdated;
        table.update(row);
        REQUIRE(table.count() == 1);

        const auto &record = table.getById(testId);
        REQUIRE(record.snippet == testSnippetUpdated);
    }

    SECTION("Remove a note")
    {
        table.removeById(1);
        REQUIRE(table.count() == 0);
    }
}