Skip to content

Commit

Permalink
feat: Improve mParticle reset methods (#263)
Browse files Browse the repository at this point in the history
  • Loading branch information
einsteinx2 committed Mar 14, 2024
1 parent 865ddbc commit cde71a2
Show file tree
Hide file tree
Showing 54 changed files with 169 additions and 529 deletions.
8 changes: 0 additions & 8 deletions UnitTests/BracketTests.mm
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,6 @@ @interface BracketTests : MPBaseTestCase

@implementation BracketTests

- (void)setUp {
[super setUp];
}

- (void)tearDown {
[super tearDown];
}

mParticle::Bracket makeBracket() {
mParticle::Bracket bracket(LONG_MAX - 3141592, 95, 97);
return bracket;
Expand Down
8 changes: 0 additions & 8 deletions UnitTests/HasherTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,6 @@ @interface HasherTests : MPBaseTestCase

@implementation HasherTests

- (void)setUp {
[super setUp];
}

- (void)tearDown {
[super tearDown];
}

- (void)testHashingString {
NSString *referenceString = @"The Quick Brown Fox Jumps Over the Lazy Dog.";
NSString *hashedString = [MPIHasher hashString:referenceString];
Expand Down
8 changes: 0 additions & 8 deletions UnitTests/MPAliasRequestTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,6 @@ @interface MPAliasRequestTests : XCTestCase

@implementation MPAliasRequestTests

- (void)setUp {
// Put setup code here. This method is called before the invocation of each test method in the class.
}

- (void)tearDown {
// Put teardown code here. This method is called after the invocation of each test method in the class.
}

- (void)testAliasInitWithMPIDs {
MPAliasRequest *request = [MPAliasRequest requestWithSourceMPID:@1 destinationMPID:@2 startTime:[NSDate dateWithTimeIntervalSince1970:100] endTime:[NSDate dateWithTimeIntervalSince1970:200]];
XCTAssertEqualObjects(request.sourceMPID, @1);
Expand Down
8 changes: 0 additions & 8 deletions UnitTests/MPAliasResponseTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,6 @@ @interface MPAliasResponseTests : XCTestCase

@implementation MPAliasResponseTests

- (void)setUp {
// Put setup code here. This method is called before the invocation of each test method in the class.
}

- (void)tearDown {
// Put teardown code here. This method is called after the invocation of each test method in the class.
}

- (void)testAliasResponseCodeSuccess {
MPAliasResponse *response = [[MPAliasResponse alloc] init];
response.responseCode = 200;
Expand Down
8 changes: 0 additions & 8 deletions UnitTests/MPAppNotificationHandlerTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,6 @@ @interface MPAppNotificationHandlerTests : MPBaseTestCase

@implementation MPAppNotificationHandlerTests

- (void)setUp {
[super setUp];
}

- (void)tearDown {
[super tearDown];
}

#if TARGET_OS_IOS == 1

- (void)testFailedToRegisterForRemoteNotification {
Expand Down
21 changes: 4 additions & 17 deletions UnitTests/MPBackendControllerTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -114,35 +114,22 @@ @implementation MPBackendControllerTests
- (void)setUp {
[super setUp];
messageQueue = [MParticle messageQueue];

[MPPersistenceController setMpid:@1];
[MParticle sharedInstance].persistenceController = [[MPPersistenceController alloc] init];

[MParticle sharedInstance].stateMachine = [[MPStateMachine alloc] init];
MPStateMachine *stateMachine = [MParticle sharedInstance].stateMachine;
stateMachine.apiKey = @"unit_test_app_key";
stateMachine.secret = @"unit_test_secret";
[MParticle sharedInstance].stateMachine.apiKey = @"unit_test_app_key";
[MParticle sharedInstance].stateMachine.secret = @"unit_test_secret";

[MParticle sharedInstance].kitContainer = [[MPKitContainer alloc] init];

MParticle *mParticle = [MParticle sharedInstance];
mParticle.backendController = [[MPBackendController alloc] initWithDelegate:(id<MPBackendControllerDelegate>)mParticle];
[MParticle sharedInstance].backendController = [[MPBackendController alloc] initWithDelegate:(id<MPBackendControllerDelegate>)[MParticle sharedInstance]];
self.backendController = [MParticle sharedInstance].backendController;
[self notificationController];
}

- (void)tearDown {
[MParticle sharedInstance].stateMachine.launchInfo = nil;
MPPersistenceController *persistence = [MParticle sharedInstance].persistenceController;
[persistence deleteRecordsOlderThan:[[NSDate date] timeIntervalSince1970]];
NSMutableArray *sessions = [persistence fetchSessions];
for (MPSession *session in sessions) {
[persistence deleteSession:session];
}

sessions = [persistence fetchSessions];
XCTAssertEqual(sessions.count, 0, @"Sessions have not been deleted.");
[persistence closeDatabase];
[super tearDown];
}

Expand Down
9 changes: 5 additions & 4 deletions UnitTests/MPBaseTestCase.m
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,15 @@ @implementation MPTestConnectorFactory

@implementation MPBaseTestCase

- (void)setUp {
- (void)setUpWithCompletionHandler:(void (^)(NSError * _Nullable))completion {
[super setUp];
[[MParticle sharedInstance] reset];
MPNetworkCommunication.connectorFactory = [[MPTestConnectorFactory alloc] init];
[[MParticle sharedInstance] reset:^{
MPNetworkCommunication.connectorFactory = [[MPTestConnectorFactory alloc] init];
completion(nil);
}];
}

- (void)tearDown {
[[MParticle sharedInstance] reset];
MPNetworkCommunication.connectorFactory = nil;
[super tearDown];
}
Expand Down
8 changes: 0 additions & 8 deletions UnitTests/MPBase_Attribute_Event_ProjectionTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,6 @@ @interface MPBase_Attribute_Event_ProjectionTests : MPBaseTestCase

@implementation MPBase_Attribute_Event_ProjectionTests

- (void)setUp {
[super setUp];
}

- (void)tearDown {
[super tearDown];
}

- (void)testBaseInstanceEvent {
NSDictionary *configuration = @{@"action":@{@"projected_event_name":@"Projected Event"
},
Expand Down
58 changes: 25 additions & 33 deletions UnitTests/MPCCPAConsentTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -4,58 +4,50 @@

static NSTimeInterval epsilon = 0.05;

@interface MPCCPAConsentTests : MPBaseTestCase {
MPCCPAConsent *_state;
}
@interface MPCCPAConsentTests : MPBaseTestCase

@end

@implementation MPCCPAConsentTests

- (void)setUp {
[super setUp];
// Put setup code here. This method is called before the invocation of each test method in the class.
_state = [[MPCCPAConsent alloc] init];
}

- (void)tearDown {
// Put teardown code here. This method is called after the invocation of each test method in the class.
[super tearDown];
}

- (void)testInit {
XCTAssertNotNil(_state);
MPCCPAConsent *state = [[MPCCPAConsent alloc] init];
XCTAssertNotNil(state);
}

- (void)testDefaultPropertyValues {
XCTAssertFalse(_state.consented);
XCTAssertNil(_state.document);
MPCCPAConsent *state = [[MPCCPAConsent alloc] init];

XCTAssertFalse(state.consented);
XCTAssertNil(state.document);

XCTAssertNotNil(_state.timestamp);
XCTAssertLessThan(-1*_state.timestamp.timeIntervalSinceNow, epsilon);
XCTAssertNotNil(state.timestamp);
XCTAssertLessThan(-1*state.timestamp.timeIntervalSinceNow, epsilon);

XCTAssertNil(_state.location);
XCTAssertNil(_state.hardwareId);
XCTAssertNil(state.location);
XCTAssertNil(state.hardwareId);
}

- (void)testPropertySetters {
_state.consented = YES;
_state.document = @"foo-document-1";
MPCCPAConsent *state = [[MPCCPAConsent alloc] init];

state.consented = YES;
state.document = @"foo-document-1";

NSDate *date = [NSDate date];
_state.timestamp = date;
state.timestamp = date;

_state.location = @"foo-location-1";
_state.hardwareId = @"foo-hardware-id-1";
state.location = @"foo-location-1";
state.hardwareId = @"foo-hardware-id-1";

XCTAssertTrue(_state.consented);
XCTAssertEqualObjects(_state.document, @"foo-document-1");
XCTAssertEqualObjects(_state.timestamp, date);
XCTAssertEqualObjects(_state.location, @"foo-location-1");
XCTAssertEqualObjects(_state.hardwareId, @"foo-hardware-id-1");
XCTAssertTrue(state.consented);
XCTAssertEqualObjects(state.document, @"foo-document-1");
XCTAssertEqualObjects(state.timestamp, date);
XCTAssertEqualObjects(state.location, @"foo-location-1");
XCTAssertEqualObjects(state.hardwareId, @"foo-hardware-id-1");

_state.consented = NO;
XCTAssertFalse(_state.consented);
state.consented = NO;
XCTAssertFalse(state.consented);
}

@end
Expand Down
8 changes: 0 additions & 8 deletions UnitTests/MPCommerceEventTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,6 @@ @interface MPCommerceEventTests : MPBaseTestCase

@implementation MPCommerceEventTests

- (void)setUp {
[super setUp];
}

- (void)tearDown {
[super tearDown];
}

- (void)testProduct {
MPProduct *product = [[MPProduct alloc] initWithName:@"DeLorean"
sku:@"OutATime"
Expand Down
8 changes: 0 additions & 8 deletions UnitTests/MPConnectorTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,6 @@ @interface MPConnectorTests : MPBaseTestCase

@implementation MPConnectorTests

- (void)setUp {
// Put setup code here. This method is called before the invocation of each test method in the class.
}

- (void)tearDown {
// Put teardown code here. This method is called after the invocation of each test method in the class.
}

- (void)testSessionIsInvalidatedWithError {
MPConnector *connector = [[MPConnector alloc] init];
NSURLSession *mockSession = OCMClassMock([NSURLSession class]);
Expand Down
10 changes: 0 additions & 10 deletions UnitTests/MPConsentKitFilterTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,6 @@ @interface MPConsentKitFilterTests : MPBaseTestCase

@implementation MPConsentKitFilterTests

- (void)setUp {
[super setUp];
// Put setup code here. This method is called before the invocation of each test method in the class.
}

- (void)tearDown {
// Put teardown code here. This method is called after the invocation of each test method in the class.
[super tearDown];
}

- (void)testProperties {
MPConsentKitFilter *filter = [[MPConsentKitFilter alloc] init];

Expand Down
10 changes: 0 additions & 10 deletions UnitTests/MPConsentSerializationTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,6 @@ @interface MPConsentSerializationTests : MPBaseTestCase

@implementation MPConsentSerializationTests

- (void)setUp {
[super setUp];
// Put setup code here. This method is called before the invocation of each test method in the class.
}

- (void)tearDown {
// Put teardown code here. This method is called after the invocation of each test method in the class.
[super tearDown];
}

- (void)testServerDictionaryGDPR {
MPConsentState *consentState = nil;
NSDictionary *dictionary = nil;
Expand Down
5 changes: 0 additions & 5 deletions UnitTests/MPConsentStateTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,11 @@ @implementation MPConsentStateTests

- (void)setUp {
[super setUp];
// Put setup code here. This method is called before the invocation of each test method in the class.
_globalState = [[MPConsentState alloc] init];
_state = [[MPGDPRConsent alloc] init];
_ccpaState = [[MPCCPAConsent alloc] init];
}

- (void)tearDown {
// Put teardown code here. This method is called after the invocation of each test method in the class.
[super tearDown];
}

- (void)testInit {
XCTAssertNotNil(_globalState);
Expand Down
4 changes: 0 additions & 4 deletions UnitTests/MPConsumerInfoTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,6 @@ - (void)setUp {
consumerInfoDictionary = responseDictionary[kMPRemoteConfigConsumerInfoKey];
}

- (void)tearDown {
[super tearDown];
}

- (void)testInstance {
MPConsumerInfo *consumerInfo = [[MPConsumerInfo alloc] init];

Expand Down
10 changes: 0 additions & 10 deletions UnitTests/MPConvertJSTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,6 @@ @interface MPConvertJSTests : MPBaseTestCase

@implementation MPConvertJSTests

- (void)setUp {
[super setUp];
// Put setup code here. This method is called before the invocation of each test method in the class.
}

- (void)tearDown {
// Put teardown code here. This method is called after the invocation of each test method in the class.
[super tearDown];
}

- (void)testConvertTransaction {
NSDictionary *json = @{
@"Affiliation":@"Test affiliation",
Expand Down
4 changes: 0 additions & 4 deletions UnitTests/MPCustomModuleTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,6 @@ - (void)setUp {
[MPPersistenceController setMpid:@1];
}

- (void)tearDown {
[super tearDown];
}

- (void)testConfiguration {
NSData *customModuleData = [self.customModulesString dataUsingEncoding:NSUTF8StringEncoding];
XCTAssertNotNil(customModuleData, @"Should not have been nil.");
Expand Down
10 changes: 2 additions & 8 deletions UnitTests/MPDataModelTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,8 @@ @implementation MPDataModelTests
- (void)setUp {
[super setUp];

[MParticle sharedInstance].stateMachine = [[MPStateMachine alloc] init];
MPStateMachine *stateMachine = [MParticle sharedInstance].stateMachine;
stateMachine.apiKey = @"unit_test_app_key";
stateMachine.secret = @"unit_test_secret";
}

- (void)tearDown {
[super tearDown];
[MParticle sharedInstance].stateMachine.apiKey = @"unit_test_app_key";
[MParticle sharedInstance].stateMachine.secret = @"unit_test_secret";
}

- (void)testSessionInstance {
Expand Down
Loading

0 comments on commit cde71a2

Please sign in to comment.