Skip to content

Commit 4e63827

Browse files
committed
* add OPTLYFileManager.h to OptimizelySDKShared.h umbrella header
* remove duplicate initWithBaseDir call in OPTLYDatabase class * add setup and teardown to OPTLYDatafileManagerTest * check the datafilemanager does not have a datafile stored before we utilize the save datafile method
1 parent 7fa63f2 commit 4e63827

File tree

3 files changed

+53
-16
lines changed

3 files changed

+53
-16
lines changed

OptimizelySDKDatafileManager/OptimizelySDKDatafileManagerTests/OPTLYDatafileManagerTest.m

Lines changed: 52 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,6 @@
1414

1515
#import "OPTLYDatafileManager.h"
1616

17-
@interface OPTLYDatafileManagerTest : XCTestCase
18-
19-
@end
20-
2117
@interface OPTLYDatafileManager ()
2218

2319
- (void)saveDatafile:(NSData *)datafile;
@@ -40,8 +36,47 @@ @interface OPTLYFileManager ()
4036
static NSString *const kProjectId = @"6372300739";
4137
static NSString *const kDatamodelDatafileName = @"datafile_6372300739";
4238

39+
@interface OPTLYDatafileManagerTest : XCTestCase
40+
41+
@property OPTLYDataStore *dataStore;
42+
43+
@end
44+
4345
@implementation OPTLYDatafileManagerTest
4446

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+
4580
- (void)testRequestDatafileHandlesCompletionEvenWithBadRequest {
4681
// setup datafile manager
4782
OPTLYDatafileManager *datafileManager = [OPTLYDatafileManager initWithBuilderBlock:^(OPTLYDatafileManagerBuilder * _Nullable builder) {
@@ -79,12 +114,14 @@ - (void)testRequestDatafileHandlesCompletionEvenWithBadRequest {
79114
[OHHTTPStubs removeStub:stub];
80115
}
81116

82-
- (void)testSaveDatafile {
83-
// setup datafile manager
117+
- (void)testSaveDatafileMethod {
118+
// setup datafile manager and datastore
119+
OPTLYDataStore *dataStore = [OPTLYDataStore new];
84120
OPTLYDatafileManager *datafileManager = [OPTLYDatafileManager initWithBuilderBlock:^(OPTLYDatafileManagerBuilder * _Nullable builder) {
85121
builder.projectId = kProjectId;
86122
}];
87123
XCTAssertNotNil(datafileManager);
124+
XCTAssertFalse([dataStore fileExists:kProjectId type:OPTLYDataStoreDataTypeDatafile]);
88125

89126
// get the datafile
90127
NSData *datafile = [OPTLYTestHelper loadJSONDatafileIntoDataObject:kDatamodelDatafileName];
@@ -93,8 +130,6 @@ - (void)testSaveDatafile {
93130
[datafileManager saveDatafile:datafile];
94131

95132
// test the datafile was saved correctly
96-
// check file storage
97-
OPTLYDataStore *dataStore = [OPTLYDataStore new];
98133
bool fileExists = [dataStore fileExists:kProjectId type:OPTLYDataStoreDataTypeDatafile];
99134
XCTAssertTrue(fileExists, @"save Datafile did not save the datafile to disk");
100135
NSError *error;
@@ -106,4 +141,13 @@ - (void)testSaveDatafile {
106141
XCTAssertNotEqual(datafile, savedData, @"we should not be referencing the same object. Saved data should be a new NSData object created from disk.");
107142
XCTAssertEqualObjects(datafile, savedData, @"retrieved saved data from disk should be equivilent to the datafile we wanted to save to disk");
108143
}
144+
145+
- (void)testDatafileManagerPullsDatafileOnInitialization {
146+
// setup stubbing
147+
148+
// instantiate datafile manager (it should fire off a request)
149+
150+
151+
}
152+
109153
@end

OptimizelySDKShared/OptimizelySDKShared/OPTLYDatabase.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,6 @@
4444
- (void)createTable:(nonnull NSString *)tableName
4545
error:(NSError * _Nullable * _Nullable)error;
4646

47-
/**
48-
* File manager initializer.
49-
*
50-
* @param baseDir The base directory where the database will be stored.
51-
* @return an instance of OPTLYDatabase.
52-
**/
53-
- (nullable instancetype)initWithBaseDir:(nonnull NSString *)baseDir;
54-
5547
/**
5648
* Inserts data into a database table.
5749
*

OptimizelySDKShared/OptimizelySDKShared/OptimizelySDKShared.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#import "OPTLYNetworkService.h"
2121
#import "OPTLYDataStore.h"
2222
#import "OPTLYClient.h"
23+
#import "OPTLYFileManager.h"
2324
#if TARGET_OS_IOS
2425
#import "OPTLYDatabase.h"
2526
#import "OPTLYDatabaseEntity.h"

0 commit comments

Comments
 (0)