forked from customerio/customerio-flutter
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: add test coverage and refactored scripts (customerio#34)
Co-authored-by: Dan Ho <70310805+djanhjo@users.noreply.github.com>
- Loading branch information
Showing
13 changed files
with
595 additions
and
117 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
// Don't modify this line - it's automatically updated | ||
const version = "1.0.0-alpha.8"; | ||
const version = "1.0.0-beta.1"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#!/bin/bash | ||
|
||
# Script that updates the pubspec.yaml file in the SDK to newest semantic version. | ||
# | ||
# Designed to be run from CI server or manually. | ||
# | ||
# Use script: ./scripts/update-plugin.sh "0.1.1" | ||
|
||
set -e | ||
|
||
NEW_VERSION="$1" | ||
|
||
echo "Updating files to new version: $NEW_VERSION" | ||
|
||
echo "Updating customer_io_plugin_version.dart" | ||
# Given line: `const version = "1.0.0-alpha.4";` | ||
# Regex string will match the line of the file that we can then substitute. | ||
DART_LINE_PATTERN="const version = \"\(.*\)\"" | ||
sed -i "s/$DART_LINE_PATTERN/const version = \"$NEW_VERSION\"/" "./lib/customer_io_plugin_version.dart" | ||
|
||
echo "Check file, you should see version inside has been updated!" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#!/bin/bash | ||
|
||
# Script that updates the pubspec.yaml file in the SDK to newest semantic version. | ||
# | ||
# Designed to be run from CI server or manually. | ||
# | ||
# Use script: ./scripts/update-podspec.sh "0.1.1" | ||
|
||
set -e | ||
|
||
NEW_VERSION="$1" | ||
|
||
echo "Updating files to new version: $NEW_VERSION" | ||
|
||
echo "Updating customer_io.podspec" | ||
LINE_PATTERN="s.version\s*=.*" | ||
sed -i "s/$LINE_PATTERN/s.version = \'$NEW_VERSION\'/" "./ios/customer_io.podspec" | ||
|
||
echo "Check file, you should see version inside has been updated!" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,132 @@ | ||
import 'package:customer_io/customer_io_config.dart'; | ||
import 'package:customer_io/customer_io_enums.dart'; | ||
import 'package:customer_io/customer_io_method_channel.dart'; | ||
import 'package:flutter/services.dart'; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
|
||
/// This is more of test of what our Native platform is expecting. | ||
void main() { | ||
const MethodChannel channel = MethodChannel('customer_io'); | ||
final Map<String, dynamic> methodInvocations = {}; | ||
|
||
TestWidgetsFlutterBinding.ensureInitialized(); | ||
|
||
setUp(() { | ||
channel.setMockMethodCallHandler((MethodCall methodCall) async { | ||
return '42'; | ||
methodInvocations[methodCall.method] = methodCall.arguments; | ||
switch (methodCall.method) { | ||
case 'initialize': | ||
return Future | ||
.value(); // Simulate a successful response from the platform. | ||
case 'identify': | ||
case 'track': | ||
case 'trackMetric': | ||
case 'screen': | ||
case 'registerDeviceToken': | ||
case 'clearIdentify': | ||
case 'setProfileAttributes': | ||
case 'setDeviceAttributes': | ||
return; | ||
default: | ||
throw MissingPluginException(); | ||
} | ||
}); | ||
}); | ||
|
||
tearDown(() { | ||
channel.setMockMethodCallHandler(null); | ||
}); | ||
|
||
void expectMethodInvocationArguments(String methodKey, Map<String, dynamic> arguments) { | ||
expect(methodInvocations.containsKey(methodKey), true, reason: 'method `$methodKey` was called'); | ||
arguments.forEach((key, value) { | ||
expect(methodInvocations[methodKey][key], value, reason: 'method arg $key matches'); | ||
}); | ||
} | ||
|
||
test('initialize() should call platform method with correct arguments', () async { | ||
final customerIO = CustomerIOMethodChannel(); | ||
final config = CustomerIOConfig(siteId: 'site_id', apiKey: 'api_key'); | ||
await customerIO.initialize(config: config); | ||
|
||
expectMethodInvocationArguments('initialize', { 'siteId': config.siteId, 'apiKey': config.apiKey }); | ||
}); | ||
|
||
test('identify() should call platform method with correct arguments', () async { | ||
final Map<String, dynamic> args = { 'identifier': 'Customer 1', 'attributes': { 'email': 'customer@email.com' } }; | ||
|
||
final customerIO = CustomerIOMethodChannel(); | ||
customerIO.identify(identifier: args['identifier'] as String, attributes: args['attributes']); | ||
|
||
expectMethodInvocationArguments('identify', args); | ||
}); | ||
|
||
test('track() should call platform method with correct arguments', () async { | ||
final Map<String, dynamic> args = { 'eventName': 'test_event', 'attributes': { 'eventData': 2 }}; | ||
|
||
final customerIO = CustomerIOMethodChannel(); | ||
customerIO.track(name: args['eventName'], attributes: args['attributes']); | ||
|
||
expectMethodInvocationArguments('track', args); | ||
}); | ||
|
||
test('trackMetric() should call platform method with correct arguments', () async { | ||
final Map<String, dynamic> args = { | ||
'deliveryId': '123', | ||
'deliveryToken': 'asdf', | ||
'metricEvent': 'clicked'}; | ||
|
||
final customerIO = CustomerIOMethodChannel(); | ||
customerIO.trackMetric( | ||
deliveryID: args['deliveryId'], | ||
deviceToken: args['deliveryToken'], | ||
event: MetricEvent.values.byName(args['metricEvent'])); | ||
|
||
expectMethodInvocationArguments('trackMetric', args); | ||
}); | ||
|
||
test('screen() should call platform method with correct arguments', () async { | ||
final Map<String, dynamic> args = { 'eventName': 'screen_event', 'attributes': { 'screenName': '你好' }}; | ||
|
||
final customerIO = CustomerIOMethodChannel(); | ||
customerIO.screen(name: args['eventName'], attributes: args['attributes']); | ||
|
||
expectMethodInvocationArguments('screen', args); | ||
}); | ||
|
||
test('registerDeviceToken() should call platform method with correct arguments', () async { | ||
final Map<String, String> args = { 'token': 'asdf' }; | ||
|
||
final customerIO = CustomerIOMethodChannel(); | ||
customerIO.registerDeviceToken(deviceToken: args['token'] as String); | ||
|
||
expectMethodInvocationArguments('registerDeviceToken', args); | ||
}); | ||
|
||
test('clearIdentify() should call platform method with correct arguments', () async { | ||
final Map<String, String> args = {}; | ||
|
||
final customerIO = CustomerIOMethodChannel(); | ||
customerIO.clearIdentify(); | ||
|
||
expectMethodInvocationArguments('clearIdentify', args); | ||
}); | ||
|
||
test('setProfileAttributes() should call platform method with correct arguments', () async { | ||
final Map<String, dynamic> args = { 'attributes': { 'age': 1 }}; | ||
|
||
final customerIO = CustomerIOMethodChannel(); | ||
customerIO.setProfileAttributes(attributes: args['attributes']); | ||
|
||
expectMethodInvocationArguments('setProfileAttributes', args); | ||
}); | ||
|
||
test('setDeviceAttributes() should call platform method with correct arguments', () async { | ||
final Map<String, dynamic> args = { 'attributes': { 'os': 'Android' }}; | ||
|
||
final customerIO = CustomerIOMethodChannel(); | ||
customerIO.setDeviceAttributes(attributes: args['attributes']); | ||
|
||
expectMethodInvocationArguments('setDeviceAttributes', args); | ||
}); | ||
} |
Oops, something went wrong.