Skip to content

Commit

Permalink
ci: fix ABTesting test
Browse files Browse the repository at this point in the history
  • Loading branch information
YoloMao committed Oct 16, 2023
1 parent 4cdc268 commit cc66e14
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -227,26 +227,7 @@ - (void)test05FetchCodeFailure {
[self waitForExpectationsWithTimeout:5.0f handler:nil];
}

- (void)test06FetchWithNilBlock {
[HTTPStubs stubRequestsPassingTest:^BOOL(NSURLRequest * _Nonnull request) {
return [request.URL.host isEqualToString:@"www.example.com"];
} withStubResponse:^HTTPStubsResponse * _Nonnull(NSURLRequest * _Nonnull request) {
NSDictionary *obj = @{
@"code": @(0),
@"experimentId": @(123),
@"strategyId": @(456),
@"variables": @{
@"key": @"value"
}
};
return [HTTPStubsResponse responseWithJSONObject:obj statusCode:200 headers:nil];
}];

NSString *layerId = [NSUUID UUID].UUIDString; //避免缓存影响
[GrowingABTesting fetchExperiment:layerId completedBlock:nil];
}

- (void)test07ExperimentEqual {
- (void)test06ExperimentEqual {
NSString *layerId = @"123456";
NSString *experimentId = @"123";
NSString *strategyId = @"456";
Expand Down Expand Up @@ -370,7 +351,7 @@ - (void)test07ExperimentEqual {
}
}

- (void)test08ExperimentHash {
- (void)test07ExperimentHash {
NSMutableSet *set = [NSMutableSet set];
NSString *layerId = @"123456";
NSString *experimentId = @"123";
Expand Down
19 changes: 12 additions & 7 deletions Modules/ABTesting/GrowingABTesting.m
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,11 @@ + (void)requestExperiment:(NSString *)layerId
}

Check warning on line 143 in Modules/ABTesting/GrowingABTesting.m

View check run for this annotation

Codecov / codecov/patch

Modules/ABTesting/GrowingABTesting.m#L141-L143

Added lines #L141 - L143 were not covered by tests
[service sendRequest:request
completion:^(NSHTTPURLResponse *_Nonnull httpResponse, NSData *_Nonnull data, NSError *_Nonnull error) {
if (!completedBlock) {
return;
}
if (httpResponse.statusCode < 200 || httpResponse.statusCode >= 300) {
// 请求失败
completedBlock(NO, nil, retryCount);
if (completedBlock) {
completedBlock(NO, nil, retryCount);
}
return;
}
NSInteger code = -1;
Expand All @@ -169,13 +168,17 @@ + (void)requestExperiment:(NSString *)layerId
}
} @catch (NSException *exception) {
// 接口返回数据结构异常,SDK无法解析,不上报不缓存
completedBlock(NO, nil, retryCount);
if (completedBlock) {
completedBlock(NO, nil, retryCount);
}

Check warning on line 173 in Modules/ABTesting/GrowingABTesting.m

View check run for this annotation

Codecov / codecov/patch

Modules/ABTesting/GrowingABTesting.m#L172-L173

Added lines #L172 - L173 were not covered by tests
return;
}

if (code != 0) {
// 请求失败
completedBlock(NO, nil, retryCount);
if (completedBlock) {
completedBlock(NO, nil, retryCount);
}
return;
}

Expand All @@ -199,7 +202,9 @@ + (void)requestExperiment:(NSString *)layerId
[exp saveToDisk];

// 返回实验结果
completedBlock(YES, exp, 0);
if (completedBlock) {
completedBlock(YES, exp, 0);
}
}];
}

Expand Down

0 comments on commit cc66e14

Please sign in to comment.