From 6a07506f62141c21ff9c47d0c8fd9946b5b7fd13 Mon Sep 17 00:00:00 2001 From: Andrei Tudorache Date: Thu, 7 Sep 2023 18:16:26 +0300 Subject: [PATCH 1/3] changes and whitespace removal --- CMakeLists.txt | 4 +- README.md | 2 +- documentation.md | 2 +- documentation_es.md | 2 +- include/ZeroBounce/ZBErrorResponse.h | 4 +- include/ZeroBounce/ZBFindEmailResponse.h | 50 ++++++++++++++++ include/ZeroBounce/ZBValidateBatchResponse.h | 2 +- include/ZeroBounce/ZeroBounce.h | 45 ++++++++++++++- include/ZeroBounce/utils.h | 2 +- src/ZBActivityDataResponse.cpp | 2 +- src/ZBCreditsResponse.cpp | 2 +- src/ZBDeleteFileResponse.cpp | 4 +- src/ZBErrorResponse.cpp | 4 +- src/ZBFileStatusResponse.cpp | 4 +- src/ZBFindEmailResponse.cpp | 60 ++++++++++++++++++++ src/ZBGetApiUsageResponse.cpp | 4 +- src/ZBGetFileResponse.cpp | 4 +- src/ZBSendFileResponse.cpp | 6 +- src/ZBValidateBatchResponse.cpp | 6 +- src/ZBValidateRespone.cpp | 6 +- src/ZeroBounce.cpp | 45 +++++++++++++-- 21 files changed, 223 insertions(+), 37 deletions(-) create mode 100644 include/ZeroBounce/ZBFindEmailResponse.h create mode 100644 src/ZBFindEmailResponse.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 17d332a..5b9243f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,13 +12,13 @@ include(FetchContent) # Download and build libcpr FetchContent_Declare( - cpr + cpr GIT_REPOSITORY https://github.com/libcpr/cpr.git GIT_TAG 1.10.2 ) # Download and build nlohmann_json FetchContent_Declare( - nlohmann_json + nlohmann_json URL https://github.com/nlohmann/json/releases/download/v3.11.2/json.tar.xz ) # Download and build googletest diff --git a/README.md b/README.md index 9aa97be..6d000a7 100644 --- a/README.md +++ b/README.md @@ -50,7 +50,7 @@ Be aware that the library may require some .dll files (found in the `build` dire Include the library in your file: ```cpp #include -``` +``` Initialize the wrapper with your api key: ```cpp diff --git a/documentation.md b/documentation.md index 8e58f5b..e4b0984 100644 --- a/documentation.md +++ b/documentation.md @@ -46,7 +46,7 @@ Be aware that the library may require some .dll files (found in the `build` dire Include the library in your file: ```cpp ###include -``` +``` Initialize the wrapper with your api key: ```cpp diff --git a/documentation_es.md b/documentation_es.md index 0716fa1..78b338a 100644 --- a/documentation_es.md +++ b/documentation_es.md @@ -46,7 +46,7 @@ Ten en cuenta que es posible que la biblioteca requiera algunos archivos .dll (q Incluye la biblioteca en tu archivo: ```cpp ###include -``` +``` Inicializa el envoltorio con tu clave de API: ```cpp diff --git a/include/ZeroBounce/ZBErrorResponse.h b/include/ZeroBounce/ZBErrorResponse.h index 5cf169d..dd48a4c 100644 --- a/include/ZeroBounce/ZBErrorResponse.h +++ b/include/ZeroBounce/ZBErrorResponse.h @@ -9,11 +9,11 @@ /** * The model used for when a request throws an error. This model was introduced in order to provide * a standardized way of handling the error responses that a request can return. - * + * * If the error JSON received from the server includes the words "error" or "message", then the * values of those keys will be added to the [errors] array. If the error is not a JSON dictionary, * then JSON String will be added to the [errors] array. - * + * * If any type of messages are received, then they will be added according to the same rule above * after the errors found above. */ diff --git a/include/ZeroBounce/ZBFindEmailResponse.h b/include/ZeroBounce/ZBFindEmailResponse.h new file mode 100644 index 0000000..6737ec7 --- /dev/null +++ b/include/ZeroBounce/ZBFindEmailResponse.h @@ -0,0 +1,50 @@ +#ifndef ZB_FIND_EMAIL_RESPONSE_H +#define ZB_FIND_EMAIL_RESPONSE_H + +#include +#include + +#include + +using json = nlohmann::json; + +/** + * @brief highlights how a domain can format its emails and how confident is + * the API about it + */ +class ZBDomainFormat { + +public: + std::string format; + std::string confidence; + + static ZBDomainFormat from_json(const json& json_obj); + + bool operator==(const ZBDomainFormat& other) const; +}; + +/** + * @brief The class associated with the GET /guessformat request. + * + */ +class ZBFindEmailResponse { + +public: + std::string email; + std::string domain; + std::string format; + std::string status; + std::string subStatus; + std::string confidence; + std::string didYouMean; + std::string failureReason; + std::vector otherDomainFormats; + + static ZBFindEmailResponse from_json(const json& json_obj); + + bool operator==(const ZBFindEmailResponse& other) const; +}; + + + +#endif \ No newline at end of file diff --git a/include/ZeroBounce/ZBValidateBatchResponse.h b/include/ZeroBounce/ZBValidateBatchResponse.h index e5619a1..6e976f3 100644 --- a/include/ZeroBounce/ZBValidateBatchResponse.h +++ b/include/ZeroBounce/ZBValidateBatchResponse.h @@ -17,7 +17,7 @@ struct ZBEmailToValidate { std::string emailAddress; std::string ipAddress; - ZBEmailToValidate(const std::string& email, const std::string& ip = "") + ZBEmailToValidate(const std::string& email, const std::string& ip = "") : emailAddress(email), ipAddress(ip) {} }; diff --git a/include/ZeroBounce/ZeroBounce.h b/include/ZeroBounce/ZeroBounce.h index ca51928..d8bf955 100644 --- a/include/ZeroBounce/ZeroBounce.h +++ b/include/ZeroBounce/ZeroBounce.h @@ -15,6 +15,7 @@ #include "ZeroBounce/ZBGetFileResponse.h" #include "ZeroBounce/ZBDeleteFileResponse.h" #include "ZeroBounce/ZBActivityDataResponse.h" +#include "ZeroBounce/ZBFindEmailResponse.h" #include @@ -181,15 +182,15 @@ class ZeroBounce { OnSuccessCallback successCallback, OnErrorCallback errorCallback ); - + public: ZeroBounce(); ZeroBounce(const ZeroBounce& obj) = delete; /** * Get pointer to ZeroBounce instance. - * - * @return ZeroBounce* + * + * @return ZeroBounce* */ static ZeroBounce* getInstance(); @@ -384,6 +385,44 @@ class ZeroBounce { OnSuccessCallback successCallback, OnErrorCallback errorCallback ); + + /** + * @brief Email Address Search - Identifies and validates a person’s primary email address + * + * @param zb ZeroBounce pointer + * @param domain The email domain for which to find the email format + * @param first_name The first name of the person whose email format is being searched + * @param middle_name The middle name of the person whose email format is being searched + * @param last_name The last name of the person whose email format is being searched + * @param success_callback success callback + * @param error_callback error callback + */ + void findEmail( + std::string domain, + std::string first_name, + std::string middle_name, + std::string last_name, + OnSuccessCallback successCallback, + OnErrorCallback errorCallback + ); + + /** + * @brief Email Address Search - Identifies and validates a person’s primary email address + * + * @param zb ZeroBounce pointer + * @param domain The email domain for which to find the email format + * @param first_name The first name of the person whose email format is being searched + * @param last_name The last name of the person whose email format is being searched + * @param success_callback success callback + * @param error_callback error callback + */ + void findEmail( + std::string domain, + std::string first_name, + std::string last_name, + OnSuccessCallback successCallback, + OnErrorCallback errorCallback + ); }; #endif \ No newline at end of file diff --git a/include/ZeroBounce/utils.h b/include/ZeroBounce/utils.h index a3f6ba8..d8311df 100644 --- a/include/ZeroBounce/utils.h +++ b/include/ZeroBounce/utils.h @@ -8,7 +8,7 @@ using json = nlohmann::json; /** * Function used to get the value of a given key in a json. * If the key doesn't exist or it's null, a default value is returned. - * + * * @tparam T type of the returned value * @param j json object * @param key name of the field diff --git a/src/ZBActivityDataResponse.cpp b/src/ZBActivityDataResponse.cpp index 7970aef..a6ea599 100644 --- a/src/ZBActivityDataResponse.cpp +++ b/src/ZBActivityDataResponse.cpp @@ -11,7 +11,7 @@ std::string ZBActivityDataResponse::toString() ", activeInDays='" << activeInDays << '\'' << ", error='" << error << '\'' << '}'; - + return stringStream.str(); } diff --git a/src/ZBCreditsResponse.cpp b/src/ZBCreditsResponse.cpp index 9577cbe..2f0d7de 100644 --- a/src/ZBCreditsResponse.cpp +++ b/src/ZBCreditsResponse.cpp @@ -9,7 +9,7 @@ std::string ZBCreditsResponse::toString() stringStream << "ZBCreditsResponse{" << "credits='" << credits << '\'' << '}'; - + return stringStream.str(); } diff --git a/src/ZBDeleteFileResponse.cpp b/src/ZBDeleteFileResponse.cpp index 90633a0..d954e85 100644 --- a/src/ZBDeleteFileResponse.cpp +++ b/src/ZBDeleteFileResponse.cpp @@ -12,7 +12,7 @@ std::string ZBDeleteFileResponse::toString() ", fileName='" << fileName << '\'' << ", fileId='" << fileId << '\'' << '}'; - + return stringStream.str(); } @@ -23,7 +23,7 @@ ZBDeleteFileResponse ZBDeleteFileResponse::from_json(const json& j) { r.message = getOrDefault(j, "message", ""); r.fileName = getOrDefault(j, "file_name", ""); r.fileId = getOrDefault(j, "file_id", ""); - + return r; } diff --git a/src/ZBErrorResponse.cpp b/src/ZBErrorResponse.cpp index 2b80736..628b66f 100644 --- a/src/ZBErrorResponse.cpp +++ b/src/ZBErrorResponse.cpp @@ -24,9 +24,9 @@ std::string ZBErrorResponse::toString() stringStream << ", "; } } - + stringStream << "]}"; - + return stringStream.str(); } diff --git a/src/ZBFileStatusResponse.cpp b/src/ZBFileStatusResponse.cpp index 4db8c75..ad22f79 100644 --- a/src/ZBFileStatusResponse.cpp +++ b/src/ZBFileStatusResponse.cpp @@ -17,7 +17,7 @@ std::string ZBFileStatusResponse::toString() ", returnUrl='" << returnUrl << '\'' << ", errorReason='" << errorReason << '\'' << '}'; - + return stringStream.str(); } @@ -33,7 +33,7 @@ ZBFileStatusResponse ZBFileStatusResponse::from_json(const json& j) { r.fileStatus = getOrDefault(j, "file_status", ""); r.completePercentage = getOrDefault(j, "complete_percentage", ""); r.returnUrl = getOrDefault(j, "return_url", ""); - + return r; } diff --git a/src/ZBFindEmailResponse.cpp b/src/ZBFindEmailResponse.cpp new file mode 100644 index 0000000..6822c90 --- /dev/null +++ b/src/ZBFindEmailResponse.cpp @@ -0,0 +1,60 @@ +#include "ZeroBounce/utils.h" +#include "ZeroBounce/ZBFindEmailResponse.h" + +ZBDomainFormat ZBDomainFormat::from_json(const json& json_obj) { + ZBDomainFormat response; + response.format = getOrDefault(json_obj, "format", ""); + response.confidence = getOrDefault(json_obj, "confidence", ""); + return response; +} + +bool ZBDomainFormat::operator==(const ZBDomainFormat& other) const { + return this->confidence == other.confidence && this->format == other.format; +} + + +ZBFindEmailResponse ZBFindEmailResponse::from_json(const json& json_obj) { + ZBFindEmailResponse response; + response.email = getOrDefault(json_obj, "email", ""); + response.domain = getOrDefault(json_obj, "domain", ""); + response.format = getOrDefault(json_obj, "format", ""); + response.status = getOrDefault(json_obj, "status", ""); + response.subStatus = getOrDefault(json_obj, "sub_status", ""); + response.confidence = getOrDefault(json_obj, "confidence", ""); + response.didYouMean = getOrDefault(json_obj, "did_you_mean", ""); + response.failureReason = getOrDefault(json_obj, "failure_reason", ""); + + response.otherDomainFormats = std::vector(); + const json domainFormats = json_obj["other_domain_formats"]; + if (domainFormats.is_array()) { + for (int index = 0; index < domainFormats.size(); index ++) { + response.otherDomainFormats.push_back( + ZBDomainFormat::from_json(domainFormats.at(index)) + ); + } + } + return response; +} + +bool ZBFindEmailResponse::operator==(const ZBFindEmailResponse& other) const { + bool fieldsAreEqual = this->email == other.email + && this->domain == other.domain + && this->format == other.format + && this->status == other.status + && this->subStatus == other.subStatus + && this->confidence == other.confidence + && this->didYouMean == other.didYouMean + && this->failureReason == other.failureReason; + if (!fieldsAreEqual) { + return false; + } + if (this->otherDomainFormats.size() != other.otherDomainFormats.size()) { + return false; + } + for (int index = 0; index < this->otherDomainFormats.size(); index ++) { + if (this->otherDomainFormats[index] != other.otherDomainFormats[index]) { + return false; + } + } + return true; +} diff --git a/src/ZBGetApiUsageResponse.cpp b/src/ZBGetApiUsageResponse.cpp index 5ef199d..665e700 100644 --- a/src/ZBGetApiUsageResponse.cpp +++ b/src/ZBGetApiUsageResponse.cpp @@ -43,7 +43,7 @@ std::string ZBGetApiUsageResponse::toString() ", endDate='" << endDate << '\'' << ", error='" << error << '\'' << '}'; - + return stringStream.str(); } @@ -85,7 +85,7 @@ ZBGetApiUsageResponse ZBGetApiUsageResponse::from_json(const json& j) { r.startDate = getOrDefault(j, "start_date", ""); r.endDate = getOrDefault(j, "end_date", ""); r.error = getOrDefault(j, "error", ""); - + return r; } diff --git a/src/ZBGetFileResponse.cpp b/src/ZBGetFileResponse.cpp index d6fc1a6..8c7f386 100644 --- a/src/ZBGetFileResponse.cpp +++ b/src/ZBGetFileResponse.cpp @@ -11,7 +11,7 @@ std::string ZBGetFileResponse::toString() ", message='" << message << '\'' << ", localFilePath='" << localFilePath << '\'' << '}'; - + return stringStream.str(); } @@ -20,7 +20,7 @@ ZBGetFileResponse ZBGetFileResponse::from_json(const json& j) { r.success = getOrDefault(j, "success", false); r.message = getOrDefault(j, "message", ""); - + return r; } diff --git a/src/ZBSendFileResponse.cpp b/src/ZBSendFileResponse.cpp index a0acfec..270b411 100644 --- a/src/ZBSendFileResponse.cpp +++ b/src/ZBSendFileResponse.cpp @@ -16,11 +16,11 @@ std::string ZBSendFileResponse::toString() stringStream << ", "; } } - + stringStream << '\'' << ", fileName='" << fileName << '\'' << ", fileId='" << fileId << '\'' << '}'; - + return stringStream.str(); } @@ -38,7 +38,7 @@ ZBSendFileResponse ZBSendFileResponse::from_json(const json& j) { r.fileName = j.value("file_name", ""); r.fileId = j.value("file_id", ""); - + return r; } diff --git a/src/ZBValidateBatchResponse.cpp b/src/ZBValidateBatchResponse.cpp index 17c2e9f..1f1a390 100644 --- a/src/ZBValidateBatchResponse.cpp +++ b/src/ZBValidateBatchResponse.cpp @@ -17,7 +17,7 @@ ZBValidateError ZBValidateError::from_json(const json& j) { r.error = getOrDefault(j, "error", ""); r.emailAddress = getOrDefault(j, "email_address", ""); - + return r; } @@ -30,7 +30,7 @@ std::string ZBValidateBatchResponse::toString() { std::stringstream stringStream; stringStream << "ZBValidateBatchResponse{" << "emailBatch=["; - + for (auto it = emailBatch.begin(); it != emailBatch.end(); ++it) { stringStream << it->toString(true); if (std::next(it) != emailBatch.end()) { @@ -64,7 +64,7 @@ ZBValidateBatchResponse ZBValidateBatchResponse::from_json(const json& j) { ZBValidateError error = ZBValidateError::from_json(errorObj); r.errors.push_back(error); } - + return r; } diff --git a/src/ZBValidateRespone.cpp b/src/ZBValidateRespone.cpp index 0d29f58..08217c9 100644 --- a/src/ZBValidateRespone.cpp +++ b/src/ZBValidateRespone.cpp @@ -52,7 +52,7 @@ ZBValidateResponse ZBValidateResponse::from_json(const json& j) { r.domain = getOrDefault(j, "domain", ""); r.domainAgeDays = getOrDefault(j, "domain_age_days", ""); r.smtpProvider = getOrDefault(j, "smtp_provider", ""); - + bool mxFound; std::istringstream ss(getOrDefault(j, "mx_found", "false")); ss >> std::boolalpha >> mxFound; @@ -68,7 +68,7 @@ ZBValidateResponse ZBValidateResponse::from_json(const json& j) { r.zipCode = getOrDefault(j, "zipcode", ""); r.processedAt = getOrDefault(j, "processed_at", ""); r.error = getOrDefault(j, "error", ""); - + return r; } @@ -93,4 +93,4 @@ bool ZBValidateResponse::operator==(const ZBValidateResponse& other) const { country == other.country && processedAt == other.processedAt && error == other.error; -} \ No newline at end of file +} diff --git a/src/ZeroBounce.cpp b/src/ZeroBounce.cpp index a42a53b..2103487 100644 --- a/src/ZeroBounce.cpp +++ b/src/ZeroBounce.cpp @@ -123,7 +123,7 @@ void ZeroBounce::validateBatch( }, cpr::Body{payload.dump()} ); - + std::string rsp = reqResponse.text; if (reqResponse.status_code > 299) { @@ -238,7 +238,7 @@ void ZeroBounce::sendRequest( cpr::Url{urlPath}, cpr::Header{{"Accept", "application/json"}} ); - + std::string rsp = reqResponse.text; if (reqResponse.status_code > 299) { @@ -295,7 +295,7 @@ void ZeroBounce::sendFileInternal( if (!options.returnUrl.empty()) { multipart.parts.emplace_back(cpr::Part{"return_url", options.returnUrl}); } - + multipart.parts.emplace_back(cpr::Part{"has_header_row", options.hasHeaderRow}); multipart.parts.emplace_back(cpr::Part{"remove_duplicate", options.removeDuplicate}); @@ -352,7 +352,7 @@ void ZeroBounce::getFileInternal( try { std::string urlPath = (scoring ? bulkApiScoringBaseUrl : bulkApiBaseUrl) + "/getfile?api_key=" + apiKey + "&file_id=" + fileId; - + cpr::Response reqResponse = requestHandler->Get(cpr::Url{urlPath}); std::string contentType = reqResponse.header["Content-Type"]; @@ -413,3 +413,40 @@ void ZeroBounce::deleteFileInternal( errorCallback ); } + +void ZeroBounce::findEmail( + std::string domain, + std::string first_name, + std::string middle_name, + std::string last_name, + OnSuccessCallback successCallback, + OnErrorCallback errorCallback +) { + std::stringstream urlStream; + urlStream << apiBaseUrl << "/guessformat?api_key==" << apiKey; + if (domain.size() > 0) { + urlStream << "&domain=" << domain; + } + if (first_name.size() > 0) { + urlStream << "&first_name=" << first_name; + } + if (middle_name.size() > 0) { + urlStream << "&middle_name=" << middle_name; + } + if (last_name.size() > 0) { + urlStream << "&last_name=" << last_name; + } + sendRequest(urlStream.str(), successCallback, errorCallback); +} + +void ZeroBounce::findEmail( + std::string domain, + std::string first_name, + std::string last_name, + OnSuccessCallback successCallback, + OnErrorCallback errorCallback +) { + ZeroBounce::findEmail( + domain, first_name, "", last_name, successCallback, errorCallback + ); +} From 4caa0aae3e6f1baf23e75505658e1b1d20859c3e Mon Sep 17 00:00:00 2001 From: Andrei Tudorache Date: Thu, 7 Sep 2023 18:16:30 +0300 Subject: [PATCH 2/3] unit tests --- test/ZeroBounceTest.cpp | 81 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 76 insertions(+), 5 deletions(-) diff --git a/test/ZeroBounceTest.cpp b/test/ZeroBounceTest.cpp index 7bcd697..3aba4c1 100644 --- a/test/ZeroBounceTest.cpp +++ b/test/ZeroBounceTest.cpp @@ -57,7 +57,7 @@ ZeroBounceTest* ZeroBounceTest::instance = nullptr; /** * Function that creates a mock response to be returned by http requests. - * + * * @param content content of the response * @param statusCode status code of the response * @param contentType content type of the response @@ -120,7 +120,7 @@ TEST_F(Tests, testGetCreditsValid) { mockRequestHandler->setResponse(reqResponse); ZBCreditsResponse expectedResponse = ZBCreditsResponse::from_json(json::parse(responseJson)); - + ZeroBounceTest::getInstance()->getCredits( [&](ZBCreditsResponse response) { ASSERT_EQ(response, expectedResponse); @@ -273,7 +273,7 @@ TEST_F(Tests, testSingleEmailValidateValid) { mockRequestHandler->setResponse(reqResponse); ZBValidateResponse expectedResponse = ZBValidateResponse::from_json(json::parse(responseJson)); - + ZeroBounceTest::getInstance()->validate( "valid@example.com", "127.0.0.1", @@ -496,7 +496,7 @@ TEST_F(Tests, testGetFileInvalid) { } TEST_F(Tests, testGetFileValid) { - std::string responseJson = + std::string responseJson = R"("Email Address","First Name","Last Name","Gender","ZB Status","ZB Sub Status","ZB Account","ZB Domain","ZB First Name","ZB Last Name","ZB Gender","ZB Free Email","ZB MX Found","ZB MX Record","ZB SMTP Provider","ZB Did You Mean" "valid@example.com","zero","bounce","","valid","","","","zero","bounce","male","False","true","mx.example.com","example","" )"; @@ -682,7 +682,7 @@ TEST_F(Tests, testScoringGetFileInvalid) { } TEST_F(Tests, testScoringGetFileValid) { - std::string responseJson = + std::string responseJson = R"("email","firstname","lastname","ZeroBounceQualityScore" "valid@example.com","zero","bounce","10")"; @@ -785,3 +785,74 @@ TEST_F(Tests, testActivityDataValid) { } ); } + +TEST_F(Tests, testFindMailStatusInvalid) { + std::string responseJson = "{\n" + " \"email\": \"\",\n" + " \"domain\": \"example.com\",\n" + " \"format\": \"unknown\",\n" + " \"status\": \"invalid\",\n" + " \"sub_status\": \"no_dns_entries\",\n" + " \"confidence\": \"undetermined\",\n" + " \"did_you_mean\": \"\",\n" + " \"failure_reason\": \"\",\n" + " \"other_domain_formats\": []\n" + "}"; + + cpr::Response reqResponse = mockResponse(responseJson, 200); + mockRequestHandler->setResponse(reqResponse); + + ZBFindEmailResponse expectedResponse = ZBFindEmailResponse::from_json(json::parse(responseJson)); + + ZeroBounce::getInstance()->findEmail( + "example.com", + "John", + "Doe", + [&](ZBFindEmailResponse response) { + ASSERT_EQ(response, expectedResponse); + }, + [&](ZBErrorResponse errorResponse) { + FAIL() << errorResponse.toString(); + } + ); +} + +TEST_F(Tests, testFindMailStatusValid) { + std::string responseJson = "{\n" + " \"email\": \"john.doe@example.com\",\n" + " \"domain\": \"example.com\",\n" + " \"format\": \"first.last\",\n" + " \"status\": \"valid\",\n" + " \"sub_status\": \"\",\n" + " \"confidence\": \"high\",\n" + " \"did_you_mean\": \"\",\n" + " \"failure_reason\": \"\",\n" + " \"other_domain_formats\": [\n" + " {\n" + " \"format\": \"first_last\",\n" + " \"confidence\": \"high\"\n" + " },\n" + " {\n" + " \"format\": \"first\",\n" + " \"confidence\": \"medium\"\n" + " }\n" + " ]\n" + "}"; + + cpr::Response reqResponse = mockResponse(responseJson, 200); + mockRequestHandler->setResponse(reqResponse); + + ZBFindEmailResponse expectedResponse = ZBFindEmailResponse::from_json(json::parse(responseJson)); + + ZeroBounce::getInstance()->findEmail( + "example.com", + "John", + "Doe", + [&](ZBFindEmailResponse response) { + ASSERT_EQ(response, expectedResponse); + }, + [&](ZBErrorResponse errorResponse) { + FAIL() << errorResponse.toString(); + } + ); +} From 8469b97d155220b8ba4fde2c71321c4cd65fc06e Mon Sep 17 00:00:00 2001 From: Andrei Tudorache Date: Thu, 7 Sep 2023 18:23:25 +0300 Subject: [PATCH 3/3] fixed tests --- src/ZeroBounce.cpp | 2 +- test/ZeroBounceTest.cpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/ZeroBounce.cpp b/src/ZeroBounce.cpp index 2103487..39c6b0c 100644 --- a/src/ZeroBounce.cpp +++ b/src/ZeroBounce.cpp @@ -423,7 +423,7 @@ void ZeroBounce::findEmail( OnErrorCallback errorCallback ) { std::stringstream urlStream; - urlStream << apiBaseUrl << "/guessformat?api_key==" << apiKey; + urlStream << apiBaseUrl << "/guessformat?api_key=" << apiKey; if (domain.size() > 0) { urlStream << "&domain=" << domain; } diff --git a/test/ZeroBounceTest.cpp b/test/ZeroBounceTest.cpp index 3aba4c1..aa51211 100644 --- a/test/ZeroBounceTest.cpp +++ b/test/ZeroBounceTest.cpp @@ -804,7 +804,7 @@ TEST_F(Tests, testFindMailStatusInvalid) { ZBFindEmailResponse expectedResponse = ZBFindEmailResponse::from_json(json::parse(responseJson)); - ZeroBounce::getInstance()->findEmail( + ZeroBounceTest::getInstance()->findEmail( "example.com", "John", "Doe", @@ -844,7 +844,7 @@ TEST_F(Tests, testFindMailStatusValid) { ZBFindEmailResponse expectedResponse = ZBFindEmailResponse::from_json(json::parse(responseJson)); - ZeroBounce::getInstance()->findEmail( + ZeroBounceTest::getInstance()->findEmail( "example.com", "John", "Doe",