Skip to content

Commit

Permalink
Fix Bug #93 with template fix (#94)
Browse files Browse the repository at this point in the history
* Fix Bug #93 with template fix

* Adding test for toJSON equality
  • Loading branch information
mpodwysocki authored Aug 11, 2020
1 parent 9d4fd18 commit 9487352
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 10 deletions.
2 changes: 1 addition & 1 deletion AzureNotificationHubs-iOS.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "AzureNotificationHubs-iOS"
s.version = "3.0.1"
s.version = "3.0.2"

s.summary = "Push notifications for consumer and enterprise apps – from any backend to any device platform"
s.description = <<-DESC
Expand Down
2 changes: 1 addition & 1 deletion Config/Version.xcconfig
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
BUILD_NUMBER = 1
VERSION_STRING = 3.0.1
VERSION_STRING = 3.0.2
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ let package = Package(
path: "WindowsAzureMessaging/WindowsAzureMessaging",
exclude: ["Support"],
cSettings: [
.define("NH_C_VERSION", to:"\"3.0.1\""),
.define("NH_C_VERSION", to:"\"3.0.2\""),
.define("NH_C_BUILD", to:"\"1\""),
.headerSearchPath("**"),
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,6 @@ + (instancetype)createFromJSON:(NSDictionary *)json {
}

- (NSData *)toJsonData {
NSMutableDictionary *resultTemplates = [NSMutableDictionary new];
for (NSString *key in [templates allKeys]) {
MSInstallationTemplate *template = [templates objectForKey:key];
[resultTemplates setObject:[template toDictionary] forKey:key];
}

NSMutableDictionary *dictionary = [NSMutableDictionary
dictionaryWithDictionary:@{@"installationId" : self.installationId, @"platform" : @"apns", @"pushChannel" : self.pushChannel}];

Expand All @@ -109,7 +103,12 @@ - (NSData *)toJsonData {
}

if (templates && [templates count] > 0) {
[dictionary setObject:templates forKey:@"templates"];
NSMutableDictionary *resultTemplates = [NSMutableDictionary new];
for (NSString *key in [templates allKeys]) {
MSInstallationTemplate *template = [templates objectForKey:key];
[resultTemplates setObject:[template toDictionary] forKey:key];
}
[dictionary setObject:resultTemplates forKey:@"templates"];
}

return [NSJSONSerialization dataWithJSONObject:dictionary options:NSJSONWritingPrettyPrinted error:nil];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,4 +108,45 @@ - (void)testInstallationsEquality {
XCTAssertTrue([installation isEqual:installation2]);
}

- (void)testToJson {
// If
MSInstallationTemplate *templateA = [MSInstallationTemplate new];
[templateA setBody:@"body"];
[templateA addTags:@[ @"tag1", @"tag2" ]];
[templateA setHeaderValue:@"Sample-Value" forKey:@"Sample-Key"];

MSInstallationTemplate *templateB = [MSInstallationTemplate new];
[templateB setBody:@"body"];
[templateB addTags:@[ @"tag1", @"tag2" ]];
[templateB setHeaderValue:@"Sample-Value" forKey:@"Sample-Key"];

NSString *installationId = @"installationID";
NSString *key = @"key";
NSString *pushChannel = @"740f4707bebcf74f9b7c25d48e3358945f6aa01da5ddb387462c7eaf61bb78ad";
MSInstallation *installation1 = [MSInstallation new];
installation1.installationId = installationId;
installation1.pushChannel = pushChannel;
[installation1 addTags:@[ @"tag1", @"tag2", @"tag3" ]];
[installation1 setTemplate:templateA forKey:key];

MSInstallation *installation2 = [MSInstallation new];
installation2.installationId = installationId;
installation2.pushChannel = pushChannel;
[installation2 addTags:@[ @"tag1", @"tag2", @"tag3" ]];
[installation2 setTemplate:templateB forKey:key];

// When
NSData *installationData1 = [installation1 toJsonData];
NSData *installationData2 = [installation2 toJsonData];

// Then
NSError *error1;
NSError *error2;
NSDictionary *jsonData1 = [NSJSONSerialization JSONObjectWithData:installationData1 options:0 error:&error1];
NSDictionary *jsonData2 = [NSJSONSerialization JSONObjectWithData:installationData2 options:0 error:&error2];
XCTAssertNil(error1);
XCTAssertNil(error2);
XCTAssertTrue([jsonData1 isEqualToDictionary:jsonData2]);
}

@end

0 comments on commit 9487352

Please sign in to comment.