Files
MuditaOS/module-db/tests/NotesTable_tests.cpp
RobertPiet cafeb52103 [EGD-5317] Module-db UT solved
Vfs init.
Convertion time string to unix time returns 1 hour later than should.
DatabaseInitializer stub that just creates empty dbs with table
structure but without data. Notification table initial records moved
to Database Initilize section. UT run with a stub of Database
Initialize - new test section introduced to test original
initializer: test-initializer.
Added missing data for contacts db to run the sorted list test
and test fix.
2021-02-04 16:45:50 +01:00

78 lines
2.0 KiB
C++

// Copyright (c) 2017-2020, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md
#include "vfs.hpp"
#include <catch2/catch.hpp>
#include <Tables/NotesTable.hpp>
#include "Database/Database.hpp"
#include "Databases/NotesDB.hpp"
#include <purefs/filesystem_paths.hpp>
#include <vfs.hpp>
TEST_CASE("Notes Table tests")
{
vfs.Init();
Database::initialize();
const auto notesDbPath = purefs::dir::getUserDiskPath() / "notes.db";
NotesDB notesDb{notesDbPath.c_str()};
REQUIRE(notesDb.isInitialized());
NotesTable table{&notesDb};
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 = table.getByText(testSearch);
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);
}
Database::deinitialize();
}