Skip to content

Instantly share code, notes, and snippets.

@pita5
Created October 4, 2012 16:34
Show Gist options
  • Save pita5/3834809 to your computer and use it in GitHub Desktop.
Save pita5/3834809 to your computer and use it in GitHub Desktop.
- (void)testSignupARandomUser
{
__block BOOL finished = NO;
NSString* userName = RANDOM_STRING;
NSString* name = RANDOM_STRING;
NSString* email = [NSString stringWithFormat:@"%@@me.com", userName];
NSString* password = RANDOM_STRING;
NSString* profilePicPath = [[NSBundle bundleForClass:[PLGConfiguration class]] pathForResource:@"matt" ofType:@"jpg"];
NSData* profilePicData = [NSData dataWithContentsOfFile:profilePicPath];
GTMStringEncoding* encoding = [GTMStringEncoding rfc4648Base64StringEncoding];
NSString* base64ProfilePic = [encoding encode:profilePicData];
[PLGDATA signupUserWithInfo:@{ @"userName" : userName,
@"email" : email,
@"password" : password,
@"profilePic" : base64ProfilePic,
@"name" : name }
completion:^(NSError *error, NSDictionary *responseInfo) {
// Check if there was some error encountered
STAssertNil(error, @"This should not return an error");
// Check if server responds with new token
STAssertNotNil(responseInfo, @"The server did not respond with some new session token");
NSString* token;
if (responseInfo)
{
STAssertNotNil(responseInfo[SECURITYTOKEN], @"The server did not respond with some new session token");
if (responseInfo[SECURITYTOKEN])
{
token = responseInfo[SECURITYTOKEN];
STAssertNotNil(token, @"The token was nil");
}
}
// Check the stored token in key chain
NSString* storedToken = CONFIGURATION[SECURITYTOKEN];
STAssertNotNil(storedToken, @"The service did not store the token in the keychain");
if (storedToken && token)
{
STAssertTrue([storedToken isEqualToString:token], @"The stored token and the token returned from API do not match!");
}
finished = YES;
}];
while (!finished)
{
CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0, YES);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment