Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Moves logRevenueV2 logic into trackLogRevenue method #39

Merged
merged 1 commit into from
Oct 19, 2017

Conversation

ladanazita
Copy link
Contributor

@ladanazita ladanazita commented Oct 19, 2017

Build Succeeds with xcodebuild -scheme Segment-Amplitude_Example -workspace Example/Segment-Amplitude.xcworkspace

Tests succeed locally xcodebuild test -scheme Segment-Amplitude_Example -workspace Example/Segment-Amplitude.xcworkspace -destination 'platform=iOS Simulator,name=iPhone 6'

But fails with
When simulator is changed toname=iPhone 5

Travis and Podfile.lock issues are fixed on a separate branch:
#38

@SegmentBot
Copy link

By analyzing the blame information on this pull request, we identified and undefined to be a potential reviewer.

@ladanazita ladanazita changed the title Moves logRevenueV2 logic into trackLogRevenue method, cleans up varia… Moves logRevenueV2 logic into trackLogRevenue method, clean up Oct 19, 2017
- (void)trackLogRevenueV2:(NSDictionary *)properties andRevenueOrTotal:(NSNumber *)revenueOrTotal
{
id price = [properties objectForKey:@"price"] ?: revenueOrTotal;
id quantity = [properties objectForKey:@"quantity"] ?: [NSNumber numberWithInt:1];
Copy link
Contributor

Choose a reason for hiding this comment

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

In Android, we set quantity to 1 if "price" is null but either revenue or total has a value. That's because Amplitude will calculate their internal revenue with price * quantity. Maybe we should guard against this in iOS as well: https://github.com/segment-integrations/analytics-android-integration-amplitude/blob/master/src/main/java/com/segment/analytics/android/integrations/amplitude/AmplitudeIntegration.java#L203-L211

@@ -42,7 +42,6 @@ + (NSNumber *)extractRevenueOrTotal:(NSDictionary *)dictionary withRevenueKey:(N

if ([key caseInsensitiveCompare:totalKey] == NSOrderedSame) {
revenueOrTotal = dictionary[key];
break;
Copy link
Contributor

Choose a reason for hiding this comment

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

Hmmm... why did this change?

Copy link
Contributor Author

@ladanazita ladanazita Oct 19, 2017

Choose a reason for hiding this comment

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

We want revenue to be used in cases where both total and revenue are present

Copy link
Contributor

Choose a reason for hiding this comment

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

You'll want to add this reason as a comment in the codebase so the next developer (e.g. future you) does not look at it and think there's a missed break and thus a bug then put it back in.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I will say that if a break was added, tests would fail

@f2prateek
Copy link
Contributor

This is hard to review because of the huge diff. It would be better to break this up into commits or PR that are easier to review.

  1. Just copy paste old code into the new functions. No other logic should change here.
  2. Make any other changes associated. Ideally this would be a different PR though.

@ladanazita ladanazita changed the title Moves logRevenueV2 logic into trackLogRevenue method, clean up Moves logRevenueV2 logic into trackLogRevenue method Oct 19, 2017
@ladanazita
Copy link
Contributor Author

Tests succeed with: xcodebuild test -scheme Segment-Amplitude_Example -workspace Example/Segment-Amplitude.xcworkspace -destination 'platform=iOS Simulator,name=iPhone 5':

Test Suite 'All tests' started at 2017-10-19 11:34:47.544
Test Suite 'Segment-Amplitude_Tests.xctest' started at 2017-10-19 11:34:47.545
Test Suite 'InitialSpecsSpec' started at 2017-10-19 11:34:47.545
Test Case '-[InitialSpecsSpec test_SEGAmplitudeIntegrationFactory__factory_creates_integration_with_basic_settings]' started.
Test Case '-[InitialSpecsSpec test_SEGAmplitudeIntegrationFactory__factory_creates_integration_with_basic_settings]' passed (0.020 seconds).
Test Case '-[InitialSpecsSpec test_SEGAmplitudeIntegrationFactory__factory_creates_integration_with_trackSessionEvents]' started.
Test Case '-[InitialSpecsSpec test_SEGAmplitudeIntegrationFactory__factory_creates_integration_with_trackSessionEvents]' passed (0.001 seconds).
Test Case '-[InitialSpecsSpec test_SEGAmplitudeIntegration__Identify__identify_without_traits]' started.
Test Case '-[InitialSpecsSpec test_SEGAmplitudeIntegration__Identify__identify_without_traits]' passed (0.003 seconds).
Test Case '-[InitialSpecsSpec test_SEGAmplitudeIntegration__Identify__identify_with_traits]' started.
Test Case '-[InitialSpecsSpec test_SEGAmplitudeIntegration__Identify__identify_with_traits]' passed (0.001 seconds).
Test Case '-[InitialSpecsSpec test_SEGAmplitudeIntegration__Identify__identify_with_groups]' started.
Test Case '-[InitialSpecsSpec test_SEGAmplitudeIntegration__Identify__identify_with_groups]' passed (0.002 seconds).
Test Case '-[InitialSpecsSpec test_SEGAmplitudeIntegration__Screen__does_not_call_screen_if_trackAllPages_false]' started.
Test Case '-[InitialSpecsSpec test_SEGAmplitudeIntegration__Screen__does_not_call_screen_if_trackAllPages_false]' passed (0.002 seconds).
Test Case '-[InitialSpecsSpec test_SEGAmplitudeIntegration__Screen__calls_basic_screen]' started.
Test Case '-[InitialSpecsSpec test_SEGAmplitudeIntegration__Screen__calls_basic_screen]' passed (0.002 seconds).
Test Case '-[InitialSpecsSpec test_SEGAmplitudeIntegration__Group__sets_groupId]' started.
Test Case '-[InitialSpecsSpec test_SEGAmplitudeIntegration__Group__sets_groupId]' passed (0.001 seconds).
Test Case '-[InitialSpecsSpec test_SEGAmplitudeIntegration__Flush__calls_uploadEvents]' started.
Test Case '-[InitialSpecsSpec test_SEGAmplitudeIntegration__Flush__calls_uploadEvents]' passed (0.001 seconds).
Test Case '-[InitialSpecsSpec test_SEGAmplitudeIntegration__Reset__calls_regenerateDeviceId]' started.
Test Case '-[InitialSpecsSpec test_SEGAmplitudeIntegration__Reset__calls_regenerateDeviceId]' passed (0.001 seconds).
Test Case '-[InitialSpecsSpec test_SEGAmplitudeIntegration__Track__tracks_a_basic_event_without_props]' started.
Test Case '-[InitialSpecsSpec test_SEGAmplitudeIntegration__Track__tracks_a_basic_event_without_props]' passed (0.002 seconds).
Test Case '-[InitialSpecsSpec test_SEGAmplitudeIntegration__Track__tracks_a_basic_event_with_props]' started.
Test Case '-[InitialSpecsSpec test_SEGAmplitudeIntegration__Track__tracks_a_basic_event_with_props]' passed (0.001 seconds).
Test Case '-[InitialSpecsSpec test_SEGAmplitudeIntegration__Track__tracks_a_basic_event_with_groups]' started.
Test Case '-[InitialSpecsSpec test_SEGAmplitudeIntegration__Track__tracks_a_basic_event_with_groups]' passed (0.029 seconds).
Test Case '-[InitialSpecsSpec test_SEGAmplitudeIntegration__Track__tracks_Order_Completed_with_revenue_if_both_total_and_revenue_are_present]' started.
2017-10-19 11:34:47.619 Segment-Amplitude_Example[5179:104269] Price : 8, Quantity : 1
Test Case '-[InitialSpecsSpec test_SEGAmplitudeIntegration__Track__tracks_Order_Completed_with_revenue_if_both_total_and_revenue_are_present]' passed (0.002 seconds).
Test Case '-[InitialSpecsSpec test_SEGAmplitudeIntegration__Track__tracks_Order_Completed_with_total_if_revenue_is_not_present]' started.
2017-10-19 11:34:47.621 Segment-Amplitude_Example[5179:104269] Price : 30.45, Quantity : 1
Test Case '-[InitialSpecsSpec test_SEGAmplitudeIntegration__Track__tracks_Order_Completed_with_total_if_revenue_is_not_present]' passed (0.002 seconds).
Test Case '-[InitialSpecsSpec test_SEGAmplitudeIntegration__Track__tracks_Order_Completed_with_revenue_of_type_String]' started.
2017-10-19 11:34:47.624 Segment-Amplitude_Example[5179:104269] Price : 8, Quantity : 1
Test Case '-[InitialSpecsSpec test_SEGAmplitudeIntegration__Track__tracks_Order_Completed_with_revenue_of_type_String]' passed (0.002 seconds).
Test Case '-[InitialSpecsSpec test_SEGAmplitudeIntegration__Track__tracks_with_top_level_price_and_quantity]' started.
2017-10-19 11:34:47.627 Segment-Amplitude_Example[5179:104269] Price : 18.9, Quantity : 1
Test Case '-[InitialSpecsSpec test_SEGAmplitudeIntegration__Track__tracks_with_top_level_price_and_quantity]' passed (0.003 seconds).
Test Case '-[InitialSpecsSpec test_SEGAmplitudeIntegration__Track__tracks_Amplitude_ecommerce_fields]' started.
2017-10-19 11:34:47.632 Segment-Amplitude_Example[5179:104269] Price : 18.9, Quantity : 1
Test Case '-[InitialSpecsSpec test_SEGAmplitudeIntegration__Track__tracks_Amplitude_ecommerce_fields]' passed (0.004 seconds).
Test Case '-[InitialSpecsSpec test_SEGAmplitudeIntegration__Track__fallsback_to_logRevenue_v1]' started.
Test Case '-[InitialSpecsSpec test_SEGAmplitudeIntegration__Track__fallsback_to_logRevenue_v1]' passed (0.003 seconds).
Test Case '-[InitialSpecsSpec test_SEGAmplitudeIntegration__Track__fallsback_to_logRevenue_v1_with_default_values]' started.
Test Case '-[InitialSpecsSpec test_SEGAmplitudeIntegration__Track__fallsback_to_logRevenue_v1_with_default_values]' passed (0.002 seconds).
Test Suite 'InitialSpecsSpec' passed at 2017-10-19 11:34:47.640.
	 Executed 20 tests, with 0 failures (0 unexpected) in 0.086 (0.095) seconds
Test Suite 'Segment-Amplitude_Tests.xctest' passed at 2017-10-19 11:34:47.641.
	 Executed 20 tests, with 0 failures (0 unexpected) in 0.086 (0.096) seconds
Test Suite 'All tests' passed at 2017-10-19 11:34:47.641.
	 Executed 20 tests, with 0 failures (0 unexpected) in 0.086 (0.097) seconds
** TEST SUCCEEDED **

Build succeeds with: xcodebuild -scheme Segment-Amplitude_Example -workspace Example/Segment-Amplitude.xcworkspace

@ladanazita ladanazita merged commit b26c83e into master Oct 19, 2017
@ladanazita ladanazita deleted the refactor/logRevenueV2 branch October 19, 2017 18:37
Copy link
Contributor

@tonyxiao tonyxiao left a comment

Choose a reason for hiding this comment

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

Should clarify unexpected code usage via comments.

@@ -42,7 +42,6 @@ + (NSNumber *)extractRevenueOrTotal:(NSDictionary *)dictionary withRevenueKey:(N

if ([key caseInsensitiveCompare:totalKey] == NSOrderedSame) {
revenueOrTotal = dictionary[key];
break;
Copy link
Contributor

Choose a reason for hiding this comment

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

You'll want to add this reason as a comment in the codebase so the next developer (e.g. future you) does not look at it and think there's a missed break and thus a bug then put it back in.

[self.amprevenue setReceipt:receipt];
SEGLog(@"[[AMPRevenue revenue] setReceipt:%@];", receipt);
}
id revenueType = [properties objectForKey:@"revenueType"] ?: [properties objectForKey:@"revenue_type"];
Copy link
Contributor

Choose a reason for hiding this comment

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

Generally it's preferred to use shorthand syntax via []. is there any reason you are not?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants