Skip to content
This repository has been archived by the owner on Feb 25, 2019. It is now read-only.

Fix linking error and add unit tests #67

Merged
merged 22 commits into from
Feb 19, 2019
Merged

Conversation

tmancey
Copy link
Collaborator

@tmancey tmancey commented Feb 11, 2019

fixes #59
fixes #60

@tmancey tmancey self-assigned this Feb 11, 2019
@tmancey tmancey changed the title Fix linking error terry [WIP Fix linking error terry Feb 11, 2019
@tmancey tmancey changed the title [WIP Fix linking error terry [WIP] Fix linking error and merge latest changes Feb 11, 2019
emerick
emerick previously approved these changes Feb 11, 2019
Copy link
Collaborator

@emerick emerick left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@@ -285,7 +319,7 @@ std::map<std::string, std::string> ConfirmationsImpl::GetCatalogIssuers()
}

bool ConfirmationsImpl::IsValidPublicKeyForCatalogIssues(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: Is that a typo in the method name (Issues vs. Issuers)?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is a typo 👍

@tmancey tmancey force-pushed the fix-linking-error-terry branch 8 times, most recently from a9bdaab to 760af7d Compare February 12, 2019 15:59
@tmancey tmancey changed the title [WIP] Fix linking error and merge latest changes Fix linking error and add unit tests Feb 12, 2019
This was referenced Feb 12, 2019
Copy link

@riastradh-brave riastradh-brave left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small nit about unit tests, not critical; otherwise OK.

delete request_;

delete confirmations_;
delete mock_confirmations_client_;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any particular reason not to use std::unique_ptr for these, so you can skip the explicit deletes?

Copy link
Collaborator Author

@tmancey tmancey Feb 16, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 fixed

":*",
rebase_path("bat-native-ledger", dep_base) + ":*",
"//brave/test:*",
]

sources = [
"src/bat/confirmations/notification_info.cc",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

header files need to be included here as well

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍


UpdateConfirmationsIsReadyStatus();
NotifyAdsIfConfirmationsIsReady();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

naming convention for this would be MaybeNotifyConfirmationsIsReady

Copy link
Collaborator Author

@tmancey tmancey Feb 16, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MaybeNotifyConfirmationsIsReady does not seem right to me either as not using observer pattern, what about UpdateConfirmationsStatus until this code can be refactored to use observers?

@@ -17,11 +17,13 @@
#include "refill_tokens.h"
#include "redeem_token.h"
#include "payout_tokens.h"
#include "unblinded_tokens.h"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we have a header include and a forward decl? Looks like only the forward decl is needed

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍


namespace confirmations {

CreateConfirmationRequest::CreateConfirmationRequest() = default;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

convention here would be ConfirmationRequestBuilder or just ConfirmationRequest

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CreateConfirmationRequest is due to the server API naming the task CreateConfirmation as the API creates a confirmation

Copy link
Collaborator Author

@tmancey tmancey Feb 16, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right now these classes do not follow the builder design pattern where we could return a request object which can then also be unit tested

@@ -0,0 +1,112 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should really avoid this pattern of putting everything in the src root, it's going to cause issues with conflicting header include paths.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Totally agree as we discussed before, can we do this after 1.0 as we need to do this across all native libs?


namespace confirmations {

FetchPaymentTokenRequest::FetchPaymentTokenRequest() = default;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PaymentTokenRequestBuilder or just PaymentTokenRequest

Copy link
Collaborator Author

@tmancey tmancey Feb 15, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FetchPaymentTokenRequest is due to the server API naming the task FetchPaymentToken as the API fetches a payment token

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, but the convention in chromium is still to use *Builder for stuff like this

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it seems a little unnecessary to even instantiate this in its current form since all the state is transient. I think we either want a Builder pattern with set_confirmation_id and maybe set_endpoint_version (default to 1) or just make them static and dump the class


namespace confirmations {

RequestSignedTokensRequest::RequestSignedTokensRequest() = default;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see above builder naming convention

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above, the API requests a signed token

#include <string>

#include "confirmations_client_mock.h"
#include "brave/vendor/bat-native-confirmations/src/confirmations_impl.h"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We shouldn't be using header paths like this, it indicates a problem with the include_dirs in the config. We should expose the internal-config to tests so they can access these files using the correct paths

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually I already did that so not sure how these paths came back

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these paths came back as part of unit tests and I used an older template for the unit tests, let me fix these issues

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed 👍


confirmations_client_->URLRequest(ads_serve_url, {}, "", "",
URLRequestMethod::GET, callback);
confirmations_client_->LoadURL(url, {}, "", "", method, callback);
}

void RedeemToken::OnFetchPaymentToken(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this method is huge and should be broken up, but it also has no tests that I can see which is scary given how big it is

Copy link
Collaborator Author

@tmancey tmancey Feb 15, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method is 16 lines long? There are currently no tests for URL requests and parsing of the JSON from server responses. I will decouple the JSON parsing code and add further unit tests.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

am I misreading something? Starts at line 188 and ends at line 341?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sometimes I miss collapsed code in the diff, but I looked again and don't see a method ending that I missed

@tmancey tmancey merged commit 74fee31 into master Feb 19, 2019
@tmancey tmancey deleted the fix-linking-error-terry branch February 19, 2019 01:43
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
4 participants