Skip to content
This repository has been archived by the owner on May 24, 2023. It is now read-only.

Commit

Permalink
added tests for new/changed code, these will also ensure the classes …
Browse files Browse the repository at this point in the history
…deal with incomplete data in the future;

bumped version number, dependencies, etc.;
removed some warnings that come with the latest Xcode update (explicitly referring to self, just a readability thing)
  • Loading branch information
Gero Herkenrath committed Feb 19, 2018
1 parent b93300f commit 82f651e
Show file tree
Hide file tree
Showing 15 changed files with 114 additions and 16 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Trustbadge

## Version 0.8.4
* Fixed an issue that could lead to a crash when the backend provided incomplete product review data
* Fixed an issue that could lead to a crash when the backend provided incomplete shop review data

## Version 0.8.3

* Fixed an issues with a method that is not available before iOS 9.
Expand Down
9 changes: 9 additions & 0 deletions Example/Tests/Fixtures/productGrade-incomplete.response
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
HTTP/1.1 400 Bad Request
Date: Fri, 25 Jun 2016 11:36:17 GMT
Server: Apache
Access-Control-Allow-Origin: *
Connection: close
Transfer-Encoding: identity
Content-Type: application/json

{"response":{"code":200,"data":{"product":{"sku":"123456","name":"somename","uuid":"4de34cfbcb359f8b4550c5306728be7a"}},"message":"SUCCESS","responseInfo":{"apiVersion":"2.4.18"},"status":"SUCCESS"}}
1 change: 1 addition & 0 deletions Example/Tests/Fixtures/shopGrade-incomplete.data
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"response":{"code":200,"data":{"shop":{"tsId":"X330A2E7D449E31E467D2F53A55DDD070","url":"demoshop.trustedshops.com/ch","name":"demoshop.trustedshops.com/ch","qualityIndicators":{"reviewIndicator":{"activePeriodInDays":133,"activeReviewCount":5,"reviewsCountedSince":"2016-02-05","totalReviewCount":5,"overallMark":4.87,"overallMarkDescription":"EXCELLENT","reviewIndicatorPeriodSummary":{"reviewIndicatorPeriods":[{"startDate":"2016-02-05","endDate":"2016-06-17","periodReviewCount":5,"overallMark":4.87,"overallMarkDescription":"EXCELLENT","reviewIndicatorCriteria":[{"criterionDescription":"DELIVERY","periodCriterionCount":5,"mark":5.00,"markDescription":"EXCELLENT"},{"criterionDescription":"GOODS","periodCriterionCount":5,"mark":4.60,"markDescription":"EXCELLENT"},{"criterionDescription":"SERVICE","periodCriterionCount":5,"mark":5.00,"markDescription":"EXCELLENT"}],"reviewIndicatorMarkSummaries":[{"markDescription":"EXCELLENT","periodMarkCount":5},{"markDescription":"GOOD","periodMarkCount":0},{"markDescription":"FAIR","periodMarkCount":0},{"markDescription":"POOR","periodMarkCount":0},{"markDescription":"VERY_POOR","periodMarkCount":0}]}]}}}}},"message":"SUCCESS","responseInfo":{"apiVersion":"2.4.11","parameters":[{"name":"startDate","value":"2015-06-17"},{"name":"endDate","value":"2016-06-17"},{"name":"timeDimension","value":"YEAR"}]},"status":"SUCCESS"}}
35 changes: 35 additions & 0 deletions Example/Tests/TRSNetworkAgent+ProductGradeSpec.m
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,41 @@

});

context(@"when receiving an incomplete response", ^{

__block NSString *trustedShopsID;
beforeEach(^{
trustedShopsID = @"123123123";
NSString *file = OHPathForFileInBundle(@"productGrade-incomplete.response", [NSBundle bundleForClass:[self class]]);
NSData *messageData = [NSData dataWithContentsOfFile:file];
OHHTTPStubsResponse *response = [OHHTTPStubsResponse responseWithHTTPMessageData:messageData];

[OHHTTPStubs stubRequestsPassingTest:^BOOL(NSURLRequest *request) {
return [request.URL isEqual:[NSURL productGradeAPIURLForTSID:@"123123123" skuHash:skuHash debug:YES]];
}
withStubResponse:^OHHTTPStubsResponse *(NSURLRequest *request) {
return response;
}];
});

afterEach(^{
[OHHTTPStubs removeAllStubs];
});

it(@"passes a custom error code (Invalid data)", ^{
waitUntil(^(DoneCallback done) {
[agent getProductGradeForTrustedShopsID:@"123123123"
apiToken:@"apiToken"
SKU:sku success:nil
failure:^(NSError *error) {
expect(error.code).to.equal(TRSErrorDomainInvalidData);
done();
}];
});
});

});

context(@"when receiving a not found error", ^{

__block NSString *trustedShopsID;
Expand Down
35 changes: 35 additions & 0 deletions Example/Tests/TRSNetworkAgent+ShopGradeSpec.m
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,41 @@

});

context(@"when receiving an incpmplete response", ^{

__block NSString *trustedShopsID;
beforeEach(^{
trustedShopsID = @"123123123";
NSString *file = OHPathForFileInBundle(@"shopGrade-incomplete.response", [NSBundle bundleForClass:[self class]]);
NSData *messageData = [NSData dataWithContentsOfFile:file];
OHHTTPStubsResponse *response = [OHHTTPStubsResponse responseWithHTTPMessageData:messageData];

[OHHTTPStubs stubRequestsPassingTest:^BOOL(NSURLRequest *request) {
return [request.URL isEqual:[NSURL shopGradeAPIURLForTSID:@"123123123" debug:YES]];
}
withStubResponse:^OHHTTPStubsResponse *(NSURLRequest *request) {
return response;
}];
});

afterEach(^{
[OHHTTPStubs removeAllStubs];
});

it(@"passes a custom error code (Invalid data)", ^{
waitUntil(^(DoneCallback done) {
[agent getShopGradeForTrustedShopsID:@"123123123"
apiToken:@"apiToken"
success:nil
failure:^(NSError *error) {
expect(error.code).to.equal(TRSErrorDomainInvalidData);
done();
}];
});
});

});

context(@"when receiving a not found error", ^{

__block NSString *trustedShopsID;
Expand Down
4 changes: 4 additions & 0 deletions Example/Trustbadge.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@
1D6695581CD23E8600AA0E4E /* checkout_unit_test.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = checkout_unit_test.html; sourceTree = "<group>"; };
1D69A5A21CC791D2001A93EE /* TRSConsumerSpec.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TRSConsumerSpec.m; sourceTree = "<group>"; };
1D69A5A31CC791D2001A93EE /* TRSOrderSpec.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TRSOrderSpec.m; sourceTree = "<group>"; };
1D6BB066203AF4330080B26E /* productGrade-incomplete.response */ = {isa = PBXFileReference; lastKnownFileType = text; path = "productGrade-incomplete.response"; sourceTree = "<group>"; };
1D6BB067203AF4F40080B26E /* shopGrade-incomplete.data */ = {isa = PBXFileReference; lastKnownFileType = text; path = "shopGrade-incomplete.data"; sourceTree = "<group>"; };
1D6D50591D424C26004A5431 /* NSString+TRSStringOperationsSpec.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSString+TRSStringOperationsSpec.m"; sourceTree = "<group>"; };
1D6FAE561D2AAA3C0007BF7E /* TRSNetworkAgent+ShopGradeSpec.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "TRSNetworkAgent+ShopGradeSpec.m"; sourceTree = "<group>"; };
1D6FDCF01D13F9CC00884C2A /* shopGrade.data */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = shopGrade.data; sourceTree = "<group>"; };
Expand Down Expand Up @@ -346,9 +348,11 @@
1D6695581CD23E8600AA0E4E /* checkout_unit_test.html */,
1D6FDCF01D13F9CC00884C2A /* shopGrade.data */,
1D6FDCF21D13FBFF00884C2A /* shopGrade-badrequest.response */,
1D6BB067203AF4F40080B26E /* shopGrade-incomplete.data */,
1D6FDCF41D13FD8000884C2A /* shopGrade-notfound.response */,
1D445D091D2D0C9700A5B099 /* productGrade.data */,
1D445D0B1D2D0CCC00A5B099 /* productGrade-badrequest.response */,
1D6BB066203AF4330080B26E /* productGrade-incomplete.response */,
1D445D0D1D2D0D0700A5B099 /* productGrade-notfound.response */,
1D867C041D3CBBAF008AD80E /* productReviews.data */,
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0910"
LastUpgradeVersion = "0920"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
4 changes: 2 additions & 2 deletions Example/Trustbadge/Trustbadge-Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>0.8.3</string>
<string>0.8.4</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>201711211554</string>
<string>201802191226</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>UILaunchStoryboardName</key>
Expand Down
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
source "https://rubygems.org"

gem "bundler", "~> 1.16.0"
gem "cocoapods", "~> 1.3.1"
gem "cocoapods", "~> 1.4.0"
gem "slather", "~> 2.4.3"
gem "xcpretty", "~> 0.2.8"
gem "activesupport", "~> 4.2.10"
4 changes: 2 additions & 2 deletions Pod/Classes/Public/TRSShopGradeView.m
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,8 @@ - (void)loadShopGradeWithSuccessBlock:(void (^)(void))success failureBlock:(void
// but if the request is e.g. cached, it might screw us.
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.02 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
self.starsView = [[TRSStarsView alloc] initWithFrame:self.starPlaceholder.bounds rating:self.overallMark];
self.starsView.activeStarColor = _activeStarColor;
self.starsView.inactiveStarColor = _inactiveStarColor;
self.starsView.activeStarColor = self->_activeStarColor;
self.starsView.inactiveStarColor = self->_inactiveStarColor;
[self.starPlaceholder addSubview:self.starsView];
if (success) {
success();
Expand Down
4 changes: 2 additions & 2 deletions Pod/Classes/Public/TRSShopRatingView.m
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,8 @@ - (void)loadShopRatingWithSuccessBlock:(void (^)(void))success failureBlock:(voi
// but if the request is e.g. cached, it might screw us.
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.02 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
self.starsView = [[TRSStarsView alloc] initWithFrame:self.starPlaceholder.bounds rating:self.overallMark];
self.starsView.activeStarColor = _activeStarColor;
self.starsView.inactiveStarColor = _inactiveStarColor;
self.starsView.activeStarColor = self->_activeStarColor;
self.starsView.inactiveStarColor = self->_inactiveStarColor;
[self.starPlaceholder addSubview:self.starsView];
if (success) {
success();
Expand Down
4 changes: 2 additions & 2 deletions Pod/Classes/Public/TRSShopSimpleRatingView.m
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ - (void)loadShopSimpleRatingWithSuccessBlock:(void (^)(void))success failureBloc
// but if the request is e.g. cached, it might screw us.
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.02 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
self.starsView = [[TRSStarsView alloc] initWithFrame:self.starPlaceholder.bounds rating:self.overallMark];
self.starsView.activeStarColor = _activeStarColor;
self.starsView.inactiveStarColor = _inactiveStarColor;
self.starsView.activeStarColor = self->_activeStarColor;
self.starsView.inactiveStarColor = self->_inactiveStarColor;
[self.starPlaceholder addSubview:self.starsView];
if (success) {
success();
Expand Down
2 changes: 1 addition & 1 deletion Pod/Classes/Public/TRSTrustbadgeView.m
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ - (void)loadTrustbadgeWithSuccessBlock:(void (^)(void))success failureBlock:(voi

self.trustbadge = theTrustbadge;
self.trustbadge.debugMode = self.debugMode;
self.trustbadge.customColor = _customColor;
self.trustbadge.customColor = self->_customColor;

if (success) { // don't these lines look kinda sick? shifting brackets... :)
success();
Expand Down
16 changes: 13 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Trustbadge is available through [CocoaPods](http://cocoapods.org). To install
it, simply add the following line to your Podfile:

```ruby
pod "Trustbadge", "~> 0.8.3"
pod "Trustbadge", "~> 0.8.4"
```

#### Example project ####
Expand Down Expand Up @@ -78,7 +78,10 @@ It also explains the buyer protection (depending on services) inline, so custome
By default the trustbadge relies on your application's root `UIViewController` to modally display the information about your certificate. To change that set the `trustcardPresentingViewController` to a different `UIViewController`.
The trustbadge also has a `debugMode` property that, if set to `YES`, makes it load data from the Trusted Shops development API instead of the production API (the above example TS-ID works for debug and normal mode). Note that your shop's TS-ID might not be present on this API, if you need to debug with your own shop's TS-ID please contact Trusted Shops (see below).
The trustbadge also has a `debugMode` property that, if set to `YES`, makes it load data from the Trusted Shops development API instead of the production API (the above example TS-ID works for debug and normal mode).
Note that your shop's TS-ID might not be present on this API.
If you need to debug with your own shop's TS-ID please contact Trusted Shops (see below) or use one of the sample TS-IDs in the Example project of the pod
for trying things out with the debug flag.
- - - -
Expand Down Expand Up @@ -229,6 +232,8 @@ You should only leave out the email address if you really don't have it, as this
Like is the case with the `TRSTrustbadgeView`, you can specify a `customPresentingViewController` object to manage the presentation of the displayed dialogue boxes during the finish process.
If you are developing your application and want to test this SDK feature __please be aware that unless the order object's `debugMode` property is set to `YES`, the generated data is sent to the Trusted Shops production database!__
Also, if you are already using your own authorized TS-ID, it is very likely that it is not part of the QA environment and you will get an error.
If that is the case, you should use one of the sample TS-IDs that are part of the Example project of the pod together with the debug flag.
- - - -
Expand All @@ -237,12 +242,17 @@ To use this SDK in your own mobile app Trusted Shops needs to audit and authoriz
Please contact your customer success manager directly or via [members@trustedshops.com](mailto:members@trustedshops.com) to start the process.
Note that an authorized TS-ID is usually only present on our production backend, so if you use the debug flag on any object with an already
authorized TS-ID you might get an error (the data on QA is periodically updated with an anonymized dump from our production server).
If you encounter this during development, temporarily use one of the TS-IDs from the Example project to test your code with the debug flag.
- - - -
## 7. About this SDK ##
#### Documentation ####
The latest documentation can be found at [cocoadocs](http://cocoadocs.org/docsets/Trustbadge/0.8.3/).
~~The latest documentation can be found at [cocoadocs](http://cocoadocs.org/docsets/Trustbadge/0.8.2/).~~
Cocoadocs is unfortunately no longer actively maintained, please rely on the source or appledoc directly. Thanks go to [Orta](http://orta.io) for providing this service for so long!
All headers are documented according to the [appledoc](http://appledoc.gentlebytes.com/appledoc/) syntax, so you can also use that to directly include the docsets into your XCode.
#### Data Privacy ####
Expand Down
4 changes: 2 additions & 2 deletions Trustbadge.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "Trustbadge"
s.version = "0.8.3"
s.version = "0.8.4"
s.summary = "Trusted Shops SDK for iOS"
s.description = <<-DESC
Use the Trustbadge and Trusted Shops guarantee in your iOS app.
Expand All @@ -13,7 +13,7 @@ Pod::Spec.new do |s|
s.platform = :ios, '8.0'
s.requires_arc = true

s.dependency 'MaryPopin', '~> 1.4.2'
s.dependency 'MaryPopin', '~> 1.4.3'

s.source_files = 'Pod/Classes/**/*'
s.public_header_files = 'Pod/Classes/Public/*.h'
Expand Down

0 comments on commit 82f651e

Please sign in to comment.