14
14
15
15
#import " OPTLYDatafileManager.h"
16
16
17
- @interface OPTLYDatafileManagerTest : XCTestCase
18
-
19
- @end
20
-
21
17
@interface OPTLYDatafileManager ()
22
18
23
19
- (void )saveDatafile : (NSData *)datafile ;
@@ -40,8 +36,47 @@ @interface OPTLYFileManager ()
40
36
static NSString *const kProjectId = @" 6372300739" ;
41
37
static NSString *const kDatamodelDatafileName = @" datafile_6372300739" ;
42
38
39
+ @interface OPTLYDatafileManagerTest : XCTestCase
40
+
41
+ @property OPTLYDataStore *dataStore;
42
+
43
+ @end
44
+
43
45
@implementation OPTLYDatafileManagerTest
44
46
47
+ + (void )setUp {
48
+ [super setUp ];
49
+
50
+ // stub all requests
51
+ [OHHTTPStubs stubRequestsPassingTest: ^BOOL (NSURLRequest * _Nonnull request) {
52
+ // every requests passes this test
53
+ return true ;
54
+ } withStubResponse: ^OHHTTPStubsResponse * _Nonnull (NSURLRequest * _Nonnull request) {
55
+ // return bad request
56
+ return [OHHTTPStubsResponse responseWithData: [[NSData alloc ] init ]
57
+ statusCode: 400
58
+ headers: @{@" Content-Type" :@" application/json" }];
59
+ }];
60
+ }
61
+
62
+ + (void )tearDown {
63
+ [super tearDown ];
64
+ // make sure we have removed all stubs
65
+ [OHHTTPStubs removeAllStubs ];
66
+ }
67
+
68
+ - (void )setUp {
69
+ [super setUp ];
70
+ self.dataStore = [OPTLYDataStore new ];
71
+ [self .dataStore removeAll: nil ];
72
+ }
73
+
74
+ - (void )tearDown {
75
+ [super tearDown ];
76
+ [self .dataStore removeAll: nil ];
77
+ self.dataStore = nil ;
78
+ }
79
+
45
80
- (void )testRequestDatafileHandlesCompletionEvenWithBadRequest {
46
81
// setup datafile manager
47
82
OPTLYDatafileManager *datafileManager = [OPTLYDatafileManager initWithBuilderBlock: ^(OPTLYDatafileManagerBuilder * _Nullable builder) {
@@ -79,12 +114,14 @@ - (void)testRequestDatafileHandlesCompletionEvenWithBadRequest {
79
114
[OHHTTPStubs removeStub: stub];
80
115
}
81
116
82
- - (void )testSaveDatafile {
83
- // setup datafile manager
117
+ - (void )testSaveDatafileMethod {
118
+ // setup datafile manager and datastore
119
+ OPTLYDataStore *dataStore = [OPTLYDataStore new ];
84
120
OPTLYDatafileManager *datafileManager = [OPTLYDatafileManager initWithBuilderBlock: ^(OPTLYDatafileManagerBuilder * _Nullable builder) {
85
121
builder.projectId = kProjectId ;
86
122
}];
87
123
XCTAssertNotNil (datafileManager);
124
+ XCTAssertFalse ([dataStore fileExists: kProjectId type: OPTLYDataStoreDataTypeDatafile]);
88
125
89
126
// get the datafile
90
127
NSData *datafile = [OPTLYTestHelper loadJSONDatafileIntoDataObject: kDatamodelDatafileName ];
@@ -93,8 +130,6 @@ - (void)testSaveDatafile {
93
130
[datafileManager saveDatafile: datafile];
94
131
95
132
// test the datafile was saved correctly
96
- // check file storage
97
- OPTLYDataStore *dataStore = [OPTLYDataStore new ];
98
133
bool fileExists = [dataStore fileExists: kProjectId type: OPTLYDataStoreDataTypeDatafile];
99
134
XCTAssertTrue (fileExists, @" save Datafile did not save the datafile to disk" );
100
135
NSError *error;
@@ -106,4 +141,13 @@ - (void)testSaveDatafile {
106
141
XCTAssertNotEqual (datafile, savedData, @" we should not be referencing the same object. Saved data should be a new NSData object created from disk." );
107
142
XCTAssertEqualObjects (datafile, savedData, @" retrieved saved data from disk should be equivilent to the datafile we wanted to save to disk" );
108
143
}
144
+
145
+ - (void )testDatafileManagerPullsDatafileOnInitialization {
146
+ // setup stubbing
147
+
148
+ // instantiate datafile manager (it should fire off a request)
149
+
150
+
151
+ }
152
+
109
153
@end
0 commit comments