I would like to test some manager classes that perform asynchronous requests.
I would like to perform a log in request in the setup so that in the following tests, I can use the auth token for the api requests. Basically before the tests are performed I would like to make sure the auth key is set in the setup.
Here is some code that works, but With these method I have to login for every test. I only want to login once in the setup.
-(void)testRetrieveAddressesForUserID {
XCTestExpectation *expectation = [self expectationWithDescription:@"ready"];
[self.userManager loginWithEmail:kEmail password:kUserPassword successBlock:^(DRYVUser *loggedInUser) {
NSLog(@"login success");
self.addressManager = [DRYVAddressManager new];
[self.addressManager retrieveAddressesForUserID:@(362) withSuccessBlock:^(NSArray * success) {
NSLog(@"RETRIEVED ADDRESS");
self.address = success.firstObject;
XCTAssertEqualObjects(self.address.addressID, @(131));
XCTAssertEqualObjects(self.address.streetAddress, @"2016 W Evergreen");
XCTAssertEqualObjects(self.address.label, @"2016 W Evergreen");
XCTAssertEqualObjects(self.address.secondaryAddress, @"");
XCTAssertEqualObjects(self.address.city, @"Chicago");
XCTAssertEqualObjects(self.address.state, @"IL");
XCTAssertEqualObjects(self.address.zip, @"60622");
[expectation fulfill];
}andFailureBlock:^(NSError *error) {
XCTFail(@"Failure Block was called");
}];
}andFailureBlock: ^(NSError *error){
NSLog(@"Login Failed");
}];
[self waitForExpectationsWithTimeout:5 handler:^(NSError *error) {
}];
}
Aucun commentaire:
Enregistrer un commentaire