Skip to content

Instantly share code, notes, and snippets.

@jzucker2
Created June 29, 2015 18:22
Show Gist options
  • Save jzucker2/4d8e12b42cc07b21a957 to your computer and use it in GitHub Desktop.
Save jzucker2/4d8e12b42cc07b21a957 to your computer and use it in GitHub Desktop.
Example proper test
- (void)weak_testHereNow {
self.testExpectation = [self expectationWithDescription:@"network"];
[self.client hereNowWithCompletion:^(PNPresenceGlobalHereNowResult *result, PNErrorStatus *status) {
XCTAssertNil(status);
XCTAssertEqual([result operation], PNHereNowGlobalOperation, @"Wrong operation");
XCTAssertNotNil([result data]);
XCTAssertEqual([result statusCode], 200);
[self.testExpectation fulfill];
}];
[self waitForExpectationsWithTimeout:10 handler:^(NSError *error) {
if (error) {
NSLog(@"error: %@", error);
XCTFail(@"what went wrong?");
}
}];
}
- (void)testHereNow {
self.testExpectation = [self expectationWithDescription:@"network"];
[self.client hereNowWithCompletion:^(PNPresenceGlobalHereNowResult *result, PNErrorStatus *status) {
XCTAssertNil(status);
XCTAssertEqual([result operation], PNHereNowGlobalOperation, @"Wrong operation");
XCTAssertNotNil([result data]);
XCTAssertEqual([result statusCode], 200);
[self.testExpectation fulfill];
}];
[self waitForExpectationsWithTimeout:10 handler:^(NSError *error) {
if (error) {
NSLog(@"error: %@", error);
XCTFail(@"what went wrong?");
}
}];
}
- (void)testHereNow {
self.testExpectation = [self expectationWithDescription:@"network"];
[self.client hereNowWithCompletion:^(PNPresenceGlobalHereNowResult *result, PNErrorStatus *status) {
XCTAssertNil(status);
XCTAssertEqual([result operation], PNHereNowGlobalOperation, @"Wrong operation");
XCTAssertNotNil([result data]);
XCTAssertEqual([result statusCode], 200);
NSDictionary *expectedChannels = @{
@"0_5098427633369088" : @{
@"occupancy" : @1,
@"uuids" : @[
@{
@"uuid" : @"Fun-You--88888"
}
]
},
@"0_5650661106515968" : @{
@"occupancy" : @1,
@"uuids" : @[
@{
@"uuid" : @"Fun-You--88888"
}
]
},
@"0_5661377586790400" : @{
@"occupancy" : @1,
@"uuids" : @[
@{
@"uuid" : @"Fun-You--88888"
}
]
},
@"0_5743861762621440" : @{
@"occupancy" : @1,
@"uuids" : @[
@{
@"uuid" : @"Fun-You--88888"
}
]
},
@"2_us" : @{
@"occupancy" : @1,
@"uuids" : @[
@{
@"uuid" : @"Fun-You--88888"
}
]
},
@"a" : @{
@"occupancy" : @1,
@"uuids" : @[
@{
@"uuid" : @"322A70B3-F0EA-48CD-9BB0-D3F1F5DE006C"
},
@{
@"uuid" : @"322A70B3-F0EA-48CD-9BB0-D3F0F5DE996C"
}
]
},
@"all_activity" : @{
@"occupancy" : @1,
@"uuids" : @[
@{
@"uuid" : @"Fun-You--88888"
}
]
}
};
XCTAssertEqualObjects(result.data.channels, expectedChannels);
[self.testExpectation fulfill];
}];
[self waitForExpectationsWithTimeout:10 handler:^(NSError *error) {
if (error) {
NSLog(@"error: %@", error);
XCTFail(@"what went wrong?");
}
}];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment