Skip to content

Commit

Permalink
test: fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
AndyTWF committed Apr 14, 2024
1 parent cd0e20e commit 4ce2292
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions test/utils/log/ApiLoggerTest.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "log/ApiLogger.h"
#include "test/ApiTestCase.h"
#include "update/PluginVersion.h"

namespace UKControllerPluginUtilsTest::Api {
class ApiLoggerTest : public UKControllerPluginTest::ApiTestCase
Expand All @@ -9,26 +10,27 @@ namespace UKControllerPluginUtilsTest::Api {
{
}

const nlohmann::json expectedPluginVersionMetadata = {
{"plugin_version", UKControllerPlugin::Plugin::PluginVersion::version}};

UKControllerPluginUtils::Log::ApiLogger logger;
};

TEST_F(ApiLoggerTest, ItLogsSync)
{
const nlohmann::json expectedPayload = {
{"type", "type"}, {"message", "message"}, {"plugin_version", "#VERSION_STRING#"}};
{"type", "type"}, {"message", "message"}, {"metadata", expectedPluginVersionMetadata.dump()}};

this->ExpectApiRequest()->Post().To("plugin/logs").WithBody(expectedPayload).WillReturnCreated();
logger.Log("type", "message");
}

TEST_F(ApiLoggerTest, ItLogsSyncWithMetadata)
{
const nlohmann::json metadata = {{"key", "value"}};
nlohmann::json metadata = {{"key", "value"}};
metadata.update(expectedPluginVersionMetadata);
const nlohmann::json expectedPayload = {
{"type", "type"},
{"message", "message"},
{"metadata", metadata.dump()},
{"plugin_version", "#VERSION_STRING#"}};
{"type", "type"}, {"message", "message"}, {"metadata", metadata.dump()}};

this->ExpectApiRequest()->Post().To("plugin/logs").WithBody(expectedPayload).WillReturnCreated();
logger.Log("type", "message", metadata);
Expand All @@ -37,20 +39,18 @@ namespace UKControllerPluginUtilsTest::Api {
TEST_F(ApiLoggerTest, ItLogsAsync)
{
const nlohmann::json expectedPayload = {
{"type", "type"}, {"message", "message"}, {"plugin_version", "#VERSION_STRING#"}};
{"type", "type"}, {"message", "message"}, {"metadata", expectedPluginVersionMetadata.dump()}};

this->ExpectApiRequest()->Post().To("plugin/logs").WithBody(expectedPayload).WillReturnCreated();
logger.LogAsync("type", "message");
}

TEST_F(ApiLoggerTest, ItLogsAsyncWithMetadata)
{
const nlohmann::json metadata = {{"key", "value"}};
nlohmann::json metadata = {{"key", "value"}};
metadata.update(expectedPluginVersionMetadata);
const nlohmann::json expectedPayload = {
{"type", "type"},
{"message", "message"},
{"metadata", metadata.dump()},
{"plugin_version", "#VERSION_STRING#"}};
{"type", "type"}, {"message", "message"}, {"metadata", metadata.dump()}};

this->ExpectApiRequest()->Post().To("plugin/logs").WithBody(expectedPayload).WillReturnCreated();
logger.LogAsync("type", "message", metadata);
Expand Down

0 comments on commit 4ce2292

Please sign in to comment.