Skip to content

Commit 587fc1a

Browse files
committed
stop getting JSON Data each time. load it into memory when we start the test suite
1 parent 755792b commit 587fc1a

File tree

1 file changed

+10
-13
lines changed

1 file changed

+10
-13
lines changed

OptimizelySDKDatafileManager/OptimizelySDKDatafileManagerTests/OPTLYDatafileManagerTest.m

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
static NSString *const kDatamodelDatafileName = @"datafile_6372300739";
2626
static NSTimeInterval kDatafileDownloadInteval = 5; // in seconds
2727
static NSString *const kLastModifiedDate = @"Mon, 28 Nov 2016 06:10:59 GMT";
28+
static NSData *kDatafileData;
2829

2930
@interface OPTLYDatafileManager(test)
3031
@property (nonatomic, strong) NSTimer *datafileDownloadTimer;
@@ -43,6 +44,8 @@ @implementation OPTLYDatafileManagerTest
4344
+ (void)setUp {
4445
[super setUp];
4546

47+
kDatafileData = [OPTLYTestHelper loadJSONDatafileIntoDataObject:kDatamodelDatafileName];
48+
4649
// stub all requests
4750
[OHHTTPStubs stubRequestsPassingTest:^BOOL(NSURLRequest * _Nonnull request) {
4851
// every requests passes this test
@@ -108,11 +111,8 @@ - (void)testSaveDatafileMethod {
108111
XCTAssertNotNil(self.datafileManager);
109112
XCTAssertFalse([self.dataStore fileExists:kProjectId type:OPTLYDataStoreDataTypeDatafile]);
110113

111-
// get the datafile
112-
NSData *datafile = [OPTLYTestHelper loadJSONDatafileIntoDataObject:kDatamodelDatafileName];
113-
114114
// save the datafile
115-
[self.datafileManager saveDatafile:datafile];
115+
[self.datafileManager saveDatafile:kDatafileData];
116116

117117
// test the datafile was saved correctly
118118
bool fileExists = [self.dataStore fileExists:kProjectId type:OPTLYDataStoreDataTypeDatafile];
@@ -123,8 +123,8 @@ - (void)testSaveDatafileMethod {
123123
error:&error];
124124
XCTAssertNil(error);
125125
XCTAssertNotNil(savedData);
126-
XCTAssertNotEqual(datafile, savedData, @"we should not be referencing the same object. Saved data should be a new NSData object created from disk.");
127-
XCTAssertEqualObjects(datafile, savedData, @"retrieved saved data from disk should be equivalent to the datafile we wanted to save to disk");
126+
XCTAssertNotEqual(kDatafileData, savedData, @"we should not be referencing the same object. Saved data should be a new NSData object created from disk.");
127+
XCTAssertEqualObjects(kDatafileData, savedData, @"retrieved saved data from disk should be equivalent to the datafile we wanted to save to disk");
128128
}
129129

130130
// if 200 response, save the {projectID : lastModifiedDate} and datafile
@@ -191,11 +191,8 @@ - (void)testIsDatafileCachedFlag
191191
{
192192
XCTAssertFalse(self.datafileManager.isDatafileCached, @"Datafile cached flag should be false.");
193193

194-
// get the datafile
195-
NSData *datafile = [OPTLYTestHelper loadJSONDatafileIntoDataObject:kDatamodelDatafileName];
196-
197194
// save the datafile
198-
[self.datafileManager saveDatafile:datafile];
195+
[self.datafileManager saveDatafile:kDatafileData];
199196

200197
XCTAssertTrue(self.datafileManager.isDatafileCached, @"Datafile cached flag should be true.");
201198
}
@@ -225,7 +222,7 @@ - (void)test304Response
225222
[self.datafileManager downloadDatafile:kProjectId completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
226223
XCTAssertEqual(((NSHTTPURLResponse *)response).statusCode, 304);
227224
XCTAssertNotNil(data);
228-
XCTAssertEqualObjects(data, [OPTLYTestHelper loadJSONDatafileIntoDataObject:kDatamodelDatafileName]);
225+
XCTAssertEqualObjects(data, kDatafileData);
229226
[expect304 fulfill];
230227
}];
231228

@@ -243,7 +240,7 @@ - (void)test304Response
243240
return [OHHTTPStubs stubRequestsPassingTest:^BOOL (NSURLRequest *request) {
244241
return [request.URL.host isEqualToString:hostName];
245242
} withStubResponse:^OHHTTPStubsResponse *(NSURLRequest *request) {
246-
return [OHHTTPStubsResponse responseWithData:[OPTLYTestHelper loadJSONDatafileIntoDataObject:kDatamodelDatafileName]
243+
return [OHHTTPStubsResponse responseWithData:kDatafileData
247244
statusCode:200
248245
headers:@{@"Content-Type":@"application/json",
249246
@"Last-Modified":kLastModifiedDate}];
@@ -265,7 +262,7 @@ - (void)test304Response
265262
@"Last-Modified":kLastModifiedDate}];
266263
}
267264
else {
268-
return [OHHTTPStubsResponse responseWithData:[OPTLYTestHelper loadJSONDatafileIntoDataObject:kDatamodelDatafileName]
265+
return [OHHTTPStubsResponse responseWithData:kDatafileData
269266
statusCode:200
270267
headers:@{@"Content-Type":@"application/json",
271268
@"Last-Modified":kLastModifiedDate}];

0 commit comments

Comments
 (0)