lundi 7 septembre 2015

Testing Reactive Cocoa HTTP request with Objective-C

In DataManager.m I have my function that returns a response object if successful:

+(RACSignal *)signalVerifyPin:(NSString *)pin
{
    NSString *urlBase = [DataService buildUrl:@"checkpin?pin="];
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];

    return [RACSignal createSignal:^RACDisposable *(id subscriber) {


        [manager GET: [NSString stringWithFormat:@"%@%@", urlBase, pin]  parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
            NSLog(@"JSON: %@", responseObject);

            NSDictionary *response = [responseObject objectForKey:@"response"];

            [subscriber sendNext:responseObject];
            [subscriber sendCompleted];


        } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
            NSLog(@"Error: %@", error);
            [subscriber sendError:error];
        }];

        return nil;
    }];
}

I would love to test this piece of code, but I can't find any information on how to do so.

Thanks so much!

Aucun commentaire:

Enregistrer un commentaire