Skip to content

Commit

Permalink
Merge pull request #44 from appspector/develop
Browse files Browse the repository at this point in the history
Release 0.6.2
  • Loading branch information
Dimdron authored Mar 30, 2021
2 parents b9345e0 + 2657ecf commit f81266e
Show file tree
Hide file tree
Showing 8 changed files with 91 additions and 50 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## 0.6.2 30 Mar 2021
* Add internal updates

## 0.6.1 14 Mar 2021
* Fix for incorrect HTTP response handling on iOS

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ - (void)testHandlerReturnsErrorForInvalidCallArgs {
[self waitForExpectations:@[e] timeout:1.1];
}


- (void)testHandlerSendsLogEvent {
NSDictionary *payload = @{ @"level" : @"warning",
@"message" : @"test" };
Expand Down
25 changes: 25 additions & 0 deletions example/ios/AppSpectorPluginTests/AppSpectorPluginTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -187,4 +187,29 @@ - (void)testHandlerRejectsUnknownCalls {
[self waitForExpectations:@[e] timeout:0.1];
}

- (void)testHandlerExtractsEnvFlagFromArgs {
XCTestExpectation *e = [self expectationWithDescription:@""];

FlutterMethodCall *call = [FlutterMethodCall methodCallWithMethodName:@"run" arguments:@{ @"apiKey" : @"DEADBEEF",
@"enabledMonitors" : @[],
@"metadata" : @{ @"APPSPECTOR_CHECK_STORE_ENVIRONMENT" : @"false" }
}];
OCMStub([self.validatorMock controlMethodSupported:[OCMArg any]]).andReturn(YES);
OCMStub([self.validatorMock argumentsValid:call.arguments call:call.method error:[OCMArg anyObjectRef]]).andReturn(YES);

id sdkMock = OCMClassMock([AppSpector class]);
OCMExpect(ClassMethod([sdkMock runWithConfig:[OCMArg checkWithBlock:^BOOL(AppSpectorConfig *config) {
expect([config valueForKey:@"disableProductionCheck"]).to.beTruthy();
return YES;
}]]));

[self.handler handleMethodCall:call result:^(id result) {
expect(result).equal(@"Ok");
OCMVerifyAll(sdkMock);
[e fulfill];
}];

[self waitForExpectations:@[e] timeout:0.1];
}

@end
1 change: 0 additions & 1 deletion example/ios/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ flutter_ios_podfile_setup

target 'Runner' do
flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__))

target 'AppSpectorPluginTests' do
pod 'Expecta', '~> 1.0.5'
pod 'OCMock', '~> 3.4'
Expand Down
80 changes: 38 additions & 42 deletions example/ios/Runner.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 23 additions & 4 deletions ios/Classes/AppSpectorPlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
static NSString * const kControlChannelName = @"appspector_plugin";
static NSString * const kEventChannelName = @"appspector_event_channel";

static NSString * const kEnvCheckOptionKey = @"APPSPECTOR_CHECK_STORE_ENVIRONMENT";

@interface AppSpectorPlugin ()

@property (strong, nonatomic) ASPluginCallValidator *callValidator;
Expand Down Expand Up @@ -54,6 +56,8 @@ + (void)registerWithRegistrar:(NSObject<FlutterPluginRegistrar> *)registrar {
[registrar addMethodCallDelegate:plugin.eventsHandler channel:eventChannel];
}

#pragma mark - Call handlers -

- (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result {
if ([self.callValidator controlMethodSupported:call.method]) {
// Validate arguments
Expand Down Expand Up @@ -94,8 +98,21 @@ - (void)handleRunCall:(ASPluginMethodArgumentsList *)arguments result:(FlutterRe
NSSet<ASMonitorID> *monitorIds = [self validateAndMapRawMonitorIds:arguments[@"enabledMonitors"]];

AppSpectorConfig *config = [AppSpectorConfig configWithAPIKey:apiKey monitorIDs:monitorIds];
config.metadata = [self validateAndMapRawMeatdata:arguments[@"metadata"]];

// Handle special case when private SDK options are transferred via metadata
if (arguments[@"metadata"] != [NSNull null] && [arguments[@"metadata"][kEnvCheckOptionKey] isKindOfClass:[NSString class]]) {
NSString *checkOption = arguments[@"metadata"][kEnvCheckOptionKey];
NSNumber *productionCheck = [checkOption isEqualToString:@"true"] ? @(NO) : @(YES);
[config setValue:productionCheck forKey:@"disableProductionCheck"];

// Drop flag to not include in session metadata
NSMutableDictionary *mutableArgs = [arguments mutableCopy];
[[arguments mutableCopy] removeObjectForKey:kEnvCheckOptionKey];
arguments = [mutableArgs copy];
}

config.metadata = [self validateAndMapRawMeatdata:arguments[@"metadata"]];

__weak __auto_type weakSelf = self;
config.startCallback = ^(NSURL * _Nonnull sessionURL) {
[weakSelf.controlChannel invokeMethod:@"onSessionUrl" arguments:sessionURL.absoluteString];
Expand Down Expand Up @@ -124,10 +141,10 @@ - (void)handleIsStartedCallWithResult:(FlutterResult)result {
- (void)handleSetMetadataCall:(ASPluginMethodArgumentsList *)arguments result:(FlutterResult)result {
NSString *key = arguments[@"key"];
NSString *value = arguments[@"value"];

if (key != nil && (id)key != NSNull.null && value != nil && (id)value != NSNull.null) {
ASMetadata *metadata = @{key : value};
[AppSpector updateMetadata:metadata];
ASMetadata *metadata = @{key : value};
[AppSpector updateMetadata:metadata];
}

result(@"Ok");
Expand All @@ -139,6 +156,8 @@ - (void)handleRemoveMetadataCall:(ASPluginMethodArgumentsList *)arguments result
result(@"Ok");
}

#pragma mark - Validators -

- (ASMetadata *)validateAndMapRawMeatdata:(NSDictionary *)rawMetadata {
if (rawMetadata == nil || (id)rawMetadata == NSNull.null) {
return @{};
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: appspector
description: A plugin that integrate AppSpector to your Flutter project.
version: 0.6.1
version: 0.6.2
homepage: https://github.com/appspector/flutter-plugin

environment:
Expand Down

0 comments on commit f81266e

Please sign in to comment.