forked from anagromataf/PinacotecaCore
-
Notifications
You must be signed in to change notification settings - Fork 4
/
PCServerAPIControllerTests.m
75 lines (56 loc) · 2.37 KB
/
PCServerAPIControllerTests.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
//
// PCServerAPIControllerTests.m
// PinacotecaCore
//
// Created by Tobias Kräntzer on 23.06.13.
// Copyright (c) 2013 Tobias Kräntzer. All rights reserved.
//
#import <SenTestingKitAsync/SenTestingKitAsync.h>
#import <OHHTTPStubs/OHHTTPStubs.h>
#import "PCServerAPIController.h"
@interface PCServerAPIControllerTests : SenTestCase
@property (nonatomic, strong) PCServerAPIController *server;
@end
@implementation PCServerAPIControllerTests
- (void)setUp
{
[super setUp];
self.server = [[PCServerAPIController alloc] init];
}
- (void)tearDown
{
[OHHTTPStubs removeAllRequestHandlers];
[super tearDown];
}
#pragma mark Tests
- (void)testFetchImageAsync
{
// Stub HTTP Requests
// ------------------
NSURL *responsesBundleURL = [[NSBundle bundleForClass:[self class]] URLForResource:@"ServerAPIResponses" withExtension:@"bundle"];
NSBundle *responsesBundle = [NSBundle bundleWithURL:responsesBundleURL];
[OHHTTPStubs stubRequestsPassingTest:^BOOL(NSURLRequest *request) {
return ([request.HTTPMethod isEqualToString:@"GET"] &&
[request.URL.absoluteString isEqualToString:@"http://api.example.com/v1/images/123"]);
} withStubResponse:^OHHTTPStubsResponse *(NSURLRequest *request) {
return [OHHTTPStubsResponse responseNamed:@"images/123"
fromBundle:responsesBundle
responseTime:0.1];
}];
// Fetch Image
// -----------
NSOperationQueue *queue = [NSOperationQueue mainQueue];
[self.server fetchImageWithId:@"123"
queue:queue
completionHandler:^(id imageData, NSError *error) {
STAssertEqualObjects([NSOperationQueue currentQueue], queue, nil);
STAssertNil(error, [error localizedDescription]);
STAssertTrue([imageData isKindOfClass:[NSDictionary class]], nil);
STAssertEqualObjects(imageData[@"id"], @"123", nil);
STAssertEqualObjects(imageData[@"title"], @"My first Image", nil);
STAssertEqualObjects(imageData[@"url"], @"http://data.example.com/239f8z3z48g3.jpeg", nil);
STSuccess();
}];
STFailAfter(2.0, nil);
}
@end