Skip to content

Commit

Permalink
fix: test
Browse files Browse the repository at this point in the history
  • Loading branch information
dudantas committed Oct 12, 2024
1 parent c7aee32 commit b45296c
Showing 1 changed file with 8 additions and 19 deletions.
27 changes: 8 additions & 19 deletions tests/unit/database/database_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,28 +58,17 @@ suite<"database"> databaseTest = [] {

test("Database::escapeString should escape special characters") = [&]() {
std::string unsafeString = "O'Reilly";
std::string escapedString = db.escapeString(unsafeString);
std::string escapedString = g_database().escapeString(unsafeString);

expect(eq(escapedString, std::string("'O\\'Reilly'"))) << "The string should be correctly escaped";
};

test("Database::updateBlobData should update BLOB data") = [&]() {
std::string tableName = "test_table";
std::string columnName = "data";
uint32_t recordId = 1;
const char* blobData = "binary_data";
size_t size = strlen(blobData);
std::string idColumnName = "id";

expect(db.updateBlobData(tableName, columnName, recordId, blobData, size, idColumnName)) << "Should successfully update the BLOB";
};

test("Database::insertTable should insert data into a table") = [&]() {
std::string tableName = "test_table";
std::vector<std::string> columns = { "name", "value" };
std::vector<mysqlx::Value> values = { "test_name", 42 };
std::string tableName = "player_bosstiary";
std::vector<std::string> columns = { "player_id", "bossIdSlotOne" , "bossIdSlotTwo"};
std::vector<mysqlx::Value> values = { 1, 1, 2 };

expect(db.insertTable(tableName, columns, values)) << "Should successfully insert data into the table";
expect(g_database().insertTable(tableName, columns, values)) << "Should successfully insert data into the table";
};

test("Database::updateTable should update existing records") = [&]() {
Expand All @@ -89,7 +78,7 @@ suite<"database"> databaseTest = [] {
std::string whereColumnName = "name";
mysqlx::Value whereValue = "test_name";

expect(db.updateTable(tableName, columns, values, whereColumnName, whereValue)) << "Should successfully update the existing record";
expect(g_database().updateTable(tableName, columns, values, whereColumnName, whereValue)) << "Should successfully update the existing record";
};

test("Database::updateTable should insert if record does not exist") = [&]() {
Expand All @@ -99,14 +88,14 @@ suite<"database"> databaseTest = [] {
std::string whereColumnName = "name";
mysqlx::Value whereValue = "new_name";

expect(db.updateTable(tableName, columns, values, whereColumnName, whereValue)) << "Should insert a new record if it does not exist";
expect(g_database().updateTable(tableName, columns, values, whereColumnName, whereValue)) << "Should insert a new record if it does not exist";
};

test("Database::retryQuery should retry on failure") = [&]() {
std::string query = "INVALID QUERY";
int retries = 3;

expect(not db.retryQuery(query, retries)) << "Should fail after retry attempts are exhausted";
expect(not g_database().retryQuery(query, retries)) << "Should fail after retry attempts are exhausted";
};

test("DBInsert should construct and execute insert queries") = [&]() {
Expand Down

0 comments on commit b45296c

Please sign in to comment.