config-plugins
config-plugins copied to clipboard
feat(branch): add support for test environments
Why
Branch has a handy test mode that lets developers test their implementation in a sandbox, preventing data pollution in the live environment. At the moment this config plugin does not support the test environment feature.
How
I introduced this feature into the config plugin by expanding the config plugin parameters to accept some new values:
testApiKey(string): the test API key to be used when the test environment is enabledenableTestEnvironment(boolean): setting this totruewill enable the usage of the test environment.
Enabling the test environment varies between platforms:
- iOS: By injecting a
branch_test_environmentvalue into the generatedinfo.plist, we can assert whether this value istruefrom theapplicationDidFinishLaunchWithOptions(inside our Swift delegate) and call the appropriate SDK's mechanism to enable the test environment:RNBranch.useTestInstance() - Android: The native Branch module supports enabling the test environment by adding a metadata item to the AndroidManifest:
io.branch.sdk.TestMode.
Considerations / Help Needed
Part of this PR depends on some updated types in the official expo/config-types. Specifically, the ExpoConfig type supports a branch.apiKey field underneath the config.ios and config.android, and this config-plugin currently makes use of those values.
In an ideal world, I think the global ExpoConfig should have nothing that deals with Branch. It just... doesn't make sense? If this sentiment is shared between other maintainers, I'd be happy to completely kill those values from ExpoConfig and make the necessary changes in this PR to only take in options from the config-plugin itself.
Regardless, I have opened a PR in the expo repo to update the ExpoConfig type to accept the testApiKey and enableTestEnvironment parameters: https://github.com/expo/expo/pull/28084
What I'm confused about is how would these PRs be orchestrated to work together? Would we have to first merge the main repo PR and only then update the config plugin here? I'll wait for someone to chime in on this, as I'm a beginner in multi-repo contributions 😂
Test Plan
- I updated the existing suite to include tests for the new
enableBranchTestEnvironmentfunctions. - I unfortunately don't know how to test the native layer for this. I don't think this is required, however, as we currently don't have native tests for each platforms.