From 4ce2292aa365ae62bb5cd302b1a9f62ce067d3fc Mon Sep 17 00:00:00 2001 From: Andy Ford Date: Sun, 14 Apr 2024 21:13:55 +0100 Subject: [PATCH] test: fix test --- test/utils/log/ApiLoggerTest.cpp | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/test/utils/log/ApiLoggerTest.cpp b/test/utils/log/ApiLoggerTest.cpp index 4501ef1b..4ba64e9f 100644 --- a/test/utils/log/ApiLoggerTest.cpp +++ b/test/utils/log/ApiLoggerTest.cpp @@ -1,5 +1,6 @@ #include "log/ApiLogger.h" #include "test/ApiTestCase.h" +#include "update/PluginVersion.h" namespace UKControllerPluginUtilsTest::Api { class ApiLoggerTest : public UKControllerPluginTest::ApiTestCase @@ -9,13 +10,16 @@ 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"); @@ -23,12 +27,10 @@ namespace UKControllerPluginUtilsTest::Api { 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); @@ -37,7 +39,7 @@ 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"); @@ -45,12 +47,10 @@ namespace UKControllerPluginUtilsTest::Api { 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);