#include #include #include #include #include "../src/CoreHandler.hpp" #include "http_mock.hpp" class CoreHandlerTestable : public rublon::CoreHandler< HttpHandlerMock > { public: CoreHandlerTestable() : rublon::CoreHandler< HttpHandlerMock >{conf} {} auto & _http() { return http; } }; class CoreHandlerTests : public testing::Test { public: CoreHandlerTests() : http{sut._http()} { doc.SetObject(); } CoreHandlerTestable sut; HttpHandlerMock & http; rublon::Document doc; }; using namespace testing; MATCHER(HasValue, "") { return arg.has_value(); } bool operator==(const rublon::CoreHandlerError & lhs, const rublon::CoreHandlerError & rhs) { return lhs.errorClass == rhs.errorClass; } MATCHER_P(Unexpected, error, "") { return arg.error() == error; } TEST_F(CoreHandlerTests, coreShouldSetConnectionErrorOnBrokenConnection) { EXPECT_CALL(http, request(_, _)).WillOnce(Return(std::optional< rublon::Response >{})); EXPECT_THAT(sut.request("", doc), // AllOf(Not(HasValue()), Unexpected(rublon::CoreHandlerError::ConnectionError))); } TEST_F(CoreHandlerTests, coreShouldCheckSignatureAndReturnBadSignatureBeforeAnythingElse) { EXPECT_CALL(http, request(_, _)).WillOnce(Return((rublon::Response) http.brokenSignature().brokenBody())); EXPECT_THAT(sut.request("", doc), // AllOf(Not(HasValue()), Unexpected(rublon::CoreHandlerError::BadSigature))); } TEST_F(CoreHandlerTests, coreShouldSetBrokenDataWhenResultIsNotAvailable) { EXPECT_CALL(http, request(_, _)).WillOnce(Return(( rublon::Response ) http.brokenBody())); EXPECT_THAT(sut.request("", doc), // AllOf(Not(HasValue()), Unexpected(rublon::CoreHandlerError::BrokenData))); } TEST_F(CoreHandlerTests, coreSignatureIsBeingChecked) { EXPECT_CALL(http, request(Eq(conf.parameters.apiServer + "/path"), _)).WillOnce(Return(( rublon::Response ) http.statusPending())); auto val = sut.request("/path", doc); EXPECT_TRUE(val.value().IsObject()); }