Skip to content

Instantly share code, notes, and snippets.

@samgreen
Created May 17, 2012 16:58
Show Gist options
  • Save samgreen/2720186 to your computer and use it in GitHub Desktop.
Save samgreen/2720186 to your computer and use it in GitHub Desktop.
//
// UserTests.m
// TomManatosJobList
//
// Created by Sam Green on 4/25/12.
// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//
#import "UserTests.h"
@implementation UserTests
static const NSTimeInterval kNetworkTimeOut = 45;
- (BOOL)waitForCompletion:(NSTimeInterval)timeoutSecs {
NSDate *timeoutDate = [NSDate dateWithTimeIntervalSinceNow:timeoutSecs];
do {
[[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:timeoutDate];
if([timeoutDate timeIntervalSinceNow] < 0.0)
break;
} while (!done);
return done;
}
- (void)setUp {
[super setUp];
done = NO;
loginUser = nil;
loginErrorString = nil;
registrationErrorString = nil;
[[UserManager sharedManager] setDelegate:self];
}
- (void)tearDown {
[[UserManager sharedManager] setDelegate:nil];
[super tearDown];
}
#pragma mark - Login
- (void)testValidLogin {
[[UserManager sharedManager] attemptLogin:@"mlawrence@questfore.com" withPassword:@"password"];
STAssertTrue([self waitForCompletion:kNetworkTimeOut], @"Login test timed out!");
STAssertNotNil(loginUser, @"Login result was nil!");
}
- (void)completedLogin:(User *)user {
loginUser = [user retain];
done = YES;
}
- (void)testInvalidLogin {
[[UserManager sharedManager] attemptLogin:@"mlawrence@questfore.com" withPassword:@"a"];
STAssertTrue([self waitForCompletion:kNetworkTimeOut], @"Invalid Login test timed out!");
STAssertNotNil(loginErrorString, @"Login error is nil with invalid credentials!");
}
- (void)failedLogin:(NSString *)error {
loginErrorString = [error copy];
done = YES;
}
#pragma mark - Registration
- (void)testEmptyRegistration {
NSDictionary *emptyRegistrationInfo = [NSDictionary dictionary];
[[UserManager sharedManager] registerUser:emptyRegistrationInfo];
STAssertTrue([self waitForCompletion:kNetworkTimeOut], @"Empty registration test timed out!");
STAssertNotNil(registrationErrorString, @"Registration error is nil with empty registration info.");
}
- (void)testMalformedRegistration {
NSDictionary *malformedRegistrationInfo = [NSDictionary dictionaryWithObjectsAndKeys:@"none@x.c", @"UserName", @"a", @"Password", nil];
[[UserManager sharedManager] registerUser:malformedRegistrationInfo];
STAssertTrue([self waitForCompletion:kNetworkTimeOut], @"Malformed registration test timed out!");
STAssertNotNil(registrationErrorString, @"Registration error is nil with malformed registration info.");
}
- (void)testExistingRegistration {
NSDictionary *existingRegistrationInfo = [NSDictionary dictionaryWithObjectsAndKeys:@"mlawrence@questfore.com", @"UserName", @"password", @"Password", nil];
[[UserManager sharedManager] registerUser:existingRegistrationInfo];
STAssertTrue([self waitForCompletion:kNetworkTimeOut], @"Existing registration test timed out!");
STAssertNotNil(registrationErrorString, @"Registration error is nil with existing registration info.");
}
- (void)failedRegistration:(NSString *)error {
registrationErrorString = [error copy];
done = YES;
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment