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

Paywalls: Add support for sub_period variable #1264

Merged
merged 3 commits into from
Sep 19, 2023

Conversation

tonidero
Copy link
Contributor

Description

This PR adds support for the sub_period variable. In order to do that, some refactors were made to make sure we could test the result.

R.string.annual -> "Annual"
R.string.semester -> "6 month"
R.string.quarter -> "3 month"
R.string.bimonthly -> "2 month"
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 copied the strings from iOS. Though it felt a bit weird to not make this plural

PackageType.WEEKLY -> R.string.weekly
PackageType.UNKNOWN, PackageType.CUSTOM -> null
}
return stringId?.let { applicationContext.getString(it) } ?: ""
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'm defaulting to an empty string, which I think is the same we do in iOS.

Copy link
Contributor

Choose a reason for hiding this comment

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

👍🏻

PackageType.ANNUAL -> "Annual"
PackageType.MONTHLY -> "Monthly"
PackageType.WEEKLY -> "Weekly"
else -> error("Unknown package type ${rcPackage.packageType}")
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 didn't like copying this here... But I thought it was better to kind of duplicate this logic than use the real code during the tests.

@Test
fun `process variables processes custom period`() {
rcPackage = TestData.Packages.annual.copy(packageType = PackageType.CUSTOM)
expectVariablesResult("{{ sub_period }}", "")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just want to confirm this is what we expect @NachoSoto

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah 👍🏻 I don't have a test for this in iOS but this is fine.
The idea is to have validations in the frontend / backend to prevent users from using these with custom pacakges.

@tonidero tonidero marked this pull request as ready for review September 19, 2023 16:05
@tonidero tonidero requested a review from a team September 19, 2023 16:05
Base automatically changed from add-more-variable-processor-tests to paywalls September 19, 2023 16:06
@@ -13,45 +15,131 @@ import java.util.Locale
@RunWith(AndroidJUnit4::class)
class VariableProcessorTest {

private val usLocale = Locale.US
private val esLocale = Locale("es", "ES")
Copy link
Contributor

Choose a reason for hiding this comment

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

Cool 👍🏻

Don't have to do it now, but I guess we're close to adding Spanish strings and testing them? :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I can probably add them tomorrow morning so we can test it. However, note that since we are mocking the application context, we won't be using the localized strings. However, this can still be useful to test formatters and such

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 mean, we could potentially run instrumentation tests (that run on an actual device), but I'm not sure it's worth it for this since we need to run them on firebase test lab and are much slower.

@codecov
Copy link

codecov bot commented Sep 19, 2023

Codecov Report

Patch and project coverage have no change.

Comparison is base (3d7deb1) 85.46% compared to head (a42abfe) 85.46%.

Additional details and impacted files
@@            Coverage Diff            @@
##           paywalls    #1264   +/-   ##
=========================================
  Coverage     85.46%   85.46%           
=========================================
  Files           189      189           
  Lines          6376     6376           
  Branches        929      929           
=========================================
  Hits           5449     5449           
  Misses          568      568           
  Partials        359      359           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@tonidero tonidero force-pushed the toniricodiez/pwl-216-sub_period branch from f6388a8 to a42abfe Compare September 19, 2023 18:09
@tonidero tonidero merged commit cefc0cc into paywalls Sep 19, 2023
@tonidero tonidero deleted the toniricodiez/pwl-216-sub_period branch September 19, 2023 18:26
tonidero added a commit that referenced this pull request Oct 31, 2023
### Description
This PR adds support for the `sub_period` variable. In order to do that,
some refactors were made to make sure we could test the result.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants