mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2026-01-20 19:19:52 +00:00
Fixed “ivar direct access” warnings
This commit is contained in:
@@ -46,22 +46,22 @@
|
||||
static void *kInstallationIdentification = &kInstallationIdentification;
|
||||
|
||||
@interface BITAuthenticatorTests : XCTestCase
|
||||
|
||||
@property(nonatomic, strong) BITAuthenticator *sut;
|
||||
|
||||
@end
|
||||
|
||||
@implementation BITAuthenticatorTests {
|
||||
BITAuthenticator *_sut;
|
||||
BOOL _KVOCalled;
|
||||
}
|
||||
@implementation BITAuthenticatorTests
|
||||
|
||||
- (void)setUp {
|
||||
[super setUp];
|
||||
|
||||
_sut = [[BITAuthenticator alloc] initWithAppIdentifier:nil appEnvironment:BITEnvironmentOther];
|
||||
self.sut = [[BITAuthenticator alloc] initWithAppIdentifier:nil appEnvironment:BITEnvironmentOther];
|
||||
}
|
||||
|
||||
- (void)tearDown {
|
||||
[_sut cleanupInternalStorage];
|
||||
_sut = nil;
|
||||
[self.sut cleanupInternalStorage];
|
||||
self.sut = nil;
|
||||
|
||||
[super tearDown];
|
||||
}
|
||||
@@ -79,144 +79,144 @@ static void *kInstallationIdentification = &kInstallationIdentification;
|
||||
|
||||
#pragma mark - Setup Tests
|
||||
- (void) testThatItInstantiates {
|
||||
XCTAssertNotNil(_sut, @"Should be there");
|
||||
XCTAssertNotNil(self.sut, @"Should be there");
|
||||
}
|
||||
|
||||
#pragma mark - Persistence Tests
|
||||
- (void) testThatLastAuthenticatedVersionIsPersisted {
|
||||
_sut.lastAuthenticatedVersion = @"1.2.1";
|
||||
_sut = [[BITAuthenticator alloc] initWithAppIdentifier:nil appEnvironment:BITEnvironmentAppStore];
|
||||
assertThat(_sut.lastAuthenticatedVersion, equalTo(@"1.2.1"));
|
||||
self.sut.lastAuthenticatedVersion = @"1.2.1";
|
||||
self.sut = [[BITAuthenticator alloc] initWithAppIdentifier:nil appEnvironment:BITEnvironmentAppStore];
|
||||
assertThat(self.sut.lastAuthenticatedVersion, equalTo(@"1.2.1"));
|
||||
}
|
||||
|
||||
- (void) testThatCleanupWorks {
|
||||
_sut.lastAuthenticatedVersion = @"1.2";
|
||||
self.sut.lastAuthenticatedVersion = @"1.2";
|
||||
|
||||
[_sut cleanupInternalStorage];
|
||||
[self.sut cleanupInternalStorage];
|
||||
|
||||
assertThat(_sut.lastAuthenticatedVersion, equalTo(nil));
|
||||
assertThat(_sut.installationIdentifier, equalTo(nil));
|
||||
assertThat(self.sut.lastAuthenticatedVersion, equalTo(nil));
|
||||
assertThat(self.sut.installationIdentifier, equalTo(nil));
|
||||
}
|
||||
|
||||
#pragma mark - Initial defaults
|
||||
- (void) testDefaultValues {
|
||||
assertThatBool(_sut.restrictApplicationUsage, isFalse());
|
||||
assertThatBool(_sut.isIdentified, isFalse());
|
||||
assertThatBool(_sut.isValidated, isFalse());
|
||||
assertThat(_sut.authenticationSecret, equalTo(nil));
|
||||
assertThat(_sut.installationIdentifier, equalTo(nil));
|
||||
assertThat(_sut.installationIdentifierParameterString, equalTo(@"uuid"));
|
||||
assertThatBool(self.sut.restrictApplicationUsage, isFalse());
|
||||
assertThatBool(self.sut.isIdentified, isFalse());
|
||||
assertThatBool(self.sut.isValidated, isFalse());
|
||||
assertThat(self.sut.authenticationSecret, equalTo(nil));
|
||||
assertThat(self.sut.installationIdentifier, equalTo(nil));
|
||||
assertThat(self.sut.installationIdentifierParameterString, equalTo(@"uuid"));
|
||||
}
|
||||
|
||||
#pragma mark - General identification tests
|
||||
- (void) testThatIsDoesntShowMoreThanOneAuthenticationController {
|
||||
id delegateMock = mockProtocol(@protocol(BITAuthenticatorDelegate));
|
||||
_sut.delegate = delegateMock;
|
||||
_sut.identificationType = BITAuthenticatorIdentificationTypeDevice;
|
||||
self.sut.delegate = delegateMock;
|
||||
self.sut.identificationType = BITAuthenticatorIdentificationTypeDevice;
|
||||
|
||||
[_sut identifyWithCompletion:nil];
|
||||
[_sut identifyWithCompletion:nil];
|
||||
[_sut identifyWithCompletion:nil];
|
||||
[self.sut identifyWithCompletion:nil];
|
||||
[self.sut identifyWithCompletion:nil];
|
||||
[self.sut identifyWithCompletion:nil];
|
||||
|
||||
[verifyCount(delegateMock, times(1)) authenticator:_sut willShowAuthenticationController:(id)anything()];
|
||||
[verifyCount(delegateMock, times(1)) authenticator:self.sut willShowAuthenticationController:(id)anything()];
|
||||
}
|
||||
|
||||
- (void) testThatChangingIdentificationTypeResetsIdentifiedFlag {
|
||||
_sut.identified = YES;
|
||||
_sut.identificationType = BITAuthenticatorIdentificationTypeHockeyAppUser;
|
||||
assertThatBool(_sut.identified, isFalse());
|
||||
self.sut.identified = YES;
|
||||
self.sut.identificationType = BITAuthenticatorIdentificationTypeHockeyAppUser;
|
||||
assertThatBool(self.sut.identified, isFalse());
|
||||
}
|
||||
|
||||
- (void) testThatAfterChangingIdentificationTypeIdentificationIsRedone {
|
||||
[_sut storeInstallationIdentifier:@"meh" withType:BITAuthenticatorIdentificationTypeHockeyAppEmail];
|
||||
_sut.identified = YES;
|
||||
_sut.identificationType = BITAuthenticatorIdentificationTypeHockeyAppUser;
|
||||
[_sut identifyWithCompletion:nil];
|
||||
assertThatBool(_sut.identified, isFalse());
|
||||
assertThat(_sut.installationIdentifier, nilValue());
|
||||
[self.sut storeInstallationIdentifier:@"meh" withType:BITAuthenticatorIdentificationTypeHockeyAppEmail];
|
||||
self.sut.identified = YES;
|
||||
self.sut.identificationType = BITAuthenticatorIdentificationTypeHockeyAppUser;
|
||||
[self.sut identifyWithCompletion:nil];
|
||||
assertThatBool(self.sut.identified, isFalse());
|
||||
assertThat(self.sut.installationIdentifier, nilValue());
|
||||
}
|
||||
|
||||
- (void) testThatIdentifyingAnAlreadyIdentifiedInstanceDoesNothing {
|
||||
id delegateMock = mockProtocol(@protocol(BITAuthenticatorDelegate));
|
||||
_sut.delegate = delegateMock;
|
||||
self.sut.delegate = delegateMock;
|
||||
|
||||
_sut.identificationType = BITAuthenticatorIdentificationTypeHockeyAppEmail;
|
||||
[_sut storeInstallationIdentifier:@"meh" withType:BITAuthenticatorIdentificationTypeHockeyAppEmail];
|
||||
_sut.identified = YES;
|
||||
self.sut.identificationType = BITAuthenticatorIdentificationTypeHockeyAppEmail;
|
||||
[self.sut storeInstallationIdentifier:@"meh" withType:BITAuthenticatorIdentificationTypeHockeyAppEmail];
|
||||
self.sut.identified = YES;
|
||||
|
||||
[_sut identifyWithCompletion:nil];
|
||||
[self.sut identifyWithCompletion:nil];
|
||||
|
||||
[verifyCount(delegateMock, never()) authenticator:_sut willShowAuthenticationController:(id)anything()];
|
||||
[verifyCount(delegateMock, never()) authenticator:self.sut willShowAuthenticationController:(id)anything()];
|
||||
}
|
||||
|
||||
|
||||
#pragma mark - Anonymous identification type
|
||||
- (void) testAnonymousIdentification {
|
||||
_sut.identificationType = BITAuthenticatorIdentificationTypeAnonymous;
|
||||
assertThatBool(_sut.isIdentified, isFalse());
|
||||
[_sut identifyWithCompletion:^(BOOL identified, NSError *error) {
|
||||
self.sut.identificationType = BITAuthenticatorIdentificationTypeAnonymous;
|
||||
assertThatBool(self.sut.isIdentified, isFalse());
|
||||
[self.sut identifyWithCompletion:^(BOOL identified, NSError *error) {
|
||||
assertThatBool(identified, isTrue());
|
||||
assertThat(error, equalTo(nil));
|
||||
}];
|
||||
assertThatBool(_sut.isIdentified, isTrue());
|
||||
assertThat(_sut.installationIdentifier, notNilValue());
|
||||
assertThatBool(self.sut.isIdentified, isTrue());
|
||||
assertThat(self.sut.installationIdentifier, notNilValue());
|
||||
}
|
||||
|
||||
//anoynmous users can't be validated
|
||||
- (void) testAnonymousValidation {
|
||||
_sut.identificationType = BITAuthenticatorIdentificationTypeAnonymous;
|
||||
assertThatBool(_sut.isValidated, isFalse());
|
||||
[_sut validateWithCompletion:^(BOOL validated, NSError *error) {
|
||||
assertThatBool(_sut.validated, isFalse());
|
||||
self.sut.identificationType = BITAuthenticatorIdentificationTypeAnonymous;
|
||||
assertThatBool(self.sut.isValidated, isFalse());
|
||||
[self.sut validateWithCompletion:^(BOOL validated, NSError *error) {
|
||||
assertThatBool(self.sut.validated, isFalse());
|
||||
assertThat(error, notNilValue());
|
||||
}];
|
||||
assertThatBool(_sut.isValidated, isFalse());
|
||||
assertThatBool(self.sut.isValidated, isFalse());
|
||||
}
|
||||
|
||||
#pragma mark - Device identification type
|
||||
- (void) testDeviceIdentificationShowsViewController {
|
||||
_sut.identificationType = BITAuthenticatorIdentificationTypeDevice;
|
||||
self.sut.identificationType = BITAuthenticatorIdentificationTypeDevice;
|
||||
id delegateMock = mockProtocol(@protocol(BITAuthenticatorDelegate));
|
||||
_sut.delegate = delegateMock;
|
||||
self.sut.delegate = delegateMock;
|
||||
|
||||
[_sut identifyWithCompletion:nil];
|
||||
[self.sut identifyWithCompletion:nil];
|
||||
|
||||
[verifyCount(delegateMock, times(1)) authenticator:_sut willShowAuthenticationController:(id)anything()];
|
||||
[verifyCount(delegateMock, times(1)) authenticator:self.sut willShowAuthenticationController:(id)anything()];
|
||||
}
|
||||
#pragma mark - Web auth identification type
|
||||
- (void) testWebAuthIdentificationShowsViewController {
|
||||
_sut.identificationType = BITAuthenticatorIdentificationTypeWebAuth;
|
||||
self.sut.identificationType = BITAuthenticatorIdentificationTypeWebAuth;
|
||||
id delegateMock = mockProtocol(@protocol(BITAuthenticatorDelegate));
|
||||
_sut.delegate = delegateMock;
|
||||
self.sut.delegate = delegateMock;
|
||||
|
||||
[_sut identifyWithCompletion:nil];
|
||||
[self.sut identifyWithCompletion:nil];
|
||||
|
||||
[verifyCount(delegateMock, times(1)) authenticator:_sut willShowAuthenticationController:(id)anything()];
|
||||
[verifyCount(delegateMock, times(1)) authenticator:self.sut willShowAuthenticationController:(id)anything()];
|
||||
}
|
||||
|
||||
#pragma mark - Email identification type
|
||||
- (void) testEmailIdentificationFailsWithMissingSecret {
|
||||
_sut.identificationType = BITAuthenticatorIdentificationTypeHockeyAppEmail;
|
||||
[_sut identifyWithCompletion:^(BOOL identified, NSError *error) {
|
||||
self.sut.identificationType = BITAuthenticatorIdentificationTypeHockeyAppEmail;
|
||||
[self.sut identifyWithCompletion:^(BOOL identified, NSError *error) {
|
||||
assertThatBool(identified, isFalse());
|
||||
assertThat(error, notNilValue());
|
||||
}];
|
||||
}
|
||||
|
||||
- (void) testEmailIdentificationShowsViewController {
|
||||
_sut.identificationType = BITAuthenticatorIdentificationTypeHockeyAppEmail;
|
||||
_sut.authenticationSecret = @"mySecret";
|
||||
self.sut.identificationType = BITAuthenticatorIdentificationTypeHockeyAppEmail;
|
||||
self.sut.authenticationSecret = @"mySecret";
|
||||
id delegateMock = mockProtocol(@protocol(BITAuthenticatorDelegate));
|
||||
_sut.delegate = delegateMock;
|
||||
self.sut.delegate = delegateMock;
|
||||
|
||||
[_sut identifyWithCompletion:nil];
|
||||
[self.sut identifyWithCompletion:nil];
|
||||
|
||||
[verifyCount(delegateMock, times(1)) authenticator:_sut willShowAuthenticationController:(id)anything()];
|
||||
[verifyCount(delegateMock, times(1)) authenticator:self.sut willShowAuthenticationController:(id)anything()];
|
||||
}
|
||||
|
||||
- (void) testEmailValidationFailsWithMissingSecret {
|
||||
_sut.identificationType = BITAuthenticatorIdentificationTypeHockeyAppEmail;
|
||||
[_sut validateWithCompletion:^(BOOL validated, NSError *error) {
|
||||
self.sut.identificationType = BITAuthenticatorIdentificationTypeHockeyAppEmail;
|
||||
[self.sut validateWithCompletion:^(BOOL validated, NSError *error) {
|
||||
assertThatBool(validated, isFalse());
|
||||
assertThat(error, notNilValue());
|
||||
}];
|
||||
@@ -227,33 +227,33 @@ static void *kInstallationIdentification = &kInstallationIdentification;
|
||||
OCMStub([helperMock isURLSessionSupported]).andReturn(NO);
|
||||
|
||||
id httpClientMock = mock(BITHockeyAppClient.class);
|
||||
_sut.hockeyAppClient = httpClientMock;
|
||||
_sut.identificationType = BITAuthenticatorIdentificationTypeHockeyAppEmail;
|
||||
[_sut storeInstallationIdentifier:@"meh" withType:BITAuthenticatorIdentificationTypeHockeyAppEmail];
|
||||
_sut.authenticationSecret = @"double";
|
||||
self.sut.hockeyAppClient = httpClientMock;
|
||||
self.sut.identificationType = BITAuthenticatorIdentificationTypeHockeyAppEmail;
|
||||
[self.sut storeInstallationIdentifier:@"meh" withType:BITAuthenticatorIdentificationTypeHockeyAppEmail];
|
||||
self.sut.authenticationSecret = @"double";
|
||||
|
||||
[_sut authenticationViewController:nil handleAuthenticationWithEmail:@"stephan@dd.de" request:[NSURLRequest new] completion:nil];
|
||||
[self.sut authenticationViewController:nil handleAuthenticationWithEmail:@"stephan@dd.de" request:[NSURLRequest new] completion:nil];
|
||||
|
||||
[verify(httpClientMock) enqeueHTTPOperation:anything()];
|
||||
}
|
||||
|
||||
#pragma mark - User identification type
|
||||
- (void) testUserIdentificationShowsViewController {
|
||||
_sut.identificationType = BITAuthenticatorIdentificationTypeHockeyAppUser;
|
||||
self.sut.identificationType = BITAuthenticatorIdentificationTypeHockeyAppUser;
|
||||
id delegateMock = mockProtocol(@protocol(BITAuthenticatorDelegate));
|
||||
_sut.delegate = delegateMock;
|
||||
self.sut.delegate = delegateMock;
|
||||
|
||||
[_sut identifyWithCompletion:nil];
|
||||
[self.sut identifyWithCompletion:nil];
|
||||
|
||||
[verifyCount(delegateMock, times(1)) authenticator:_sut willShowAuthenticationController:(id)anything()];
|
||||
[verifyCount(delegateMock, times(1)) authenticator:self.sut willShowAuthenticationController:(id)anything()];
|
||||
}
|
||||
|
||||
|
||||
#pragma mark - Generic validation tests
|
||||
- (void) testThatValidationFailsIfNotIdentified {
|
||||
_sut.identified = NO;
|
||||
_sut.identificationType = BITAuthenticatorIdentificationTypeHockeyAppUser;
|
||||
[_sut validateWithCompletion:^(BOOL validated, NSError *error) {
|
||||
self.sut.identified = NO;
|
||||
self.sut.identificationType = BITAuthenticatorIdentificationTypeHockeyAppUser;
|
||||
[self.sut validateWithCompletion:^(BOOL validated, NSError *error) {
|
||||
assertThatBool(validated, isFalse());
|
||||
assertThatLong(error.code, equalToLong(BITAuthenticatorNotIdentified));
|
||||
}];
|
||||
@@ -263,11 +263,11 @@ static void *kInstallationIdentification = &kInstallationIdentification;
|
||||
id helperMock = OCMClassMock([BITHockeyHelper class]);
|
||||
OCMStub([helperMock isURLSessionSupported]).andReturn(NO);
|
||||
id httpClientMock = mock(BITHockeyAppClient.class);
|
||||
_sut.hockeyAppClient = httpClientMock;
|
||||
_sut.identificationType = BITAuthenticatorIdentificationTypeHockeyAppEmail;
|
||||
[_sut storeInstallationIdentifier:@"meh" withType:BITAuthenticatorIdentificationTypeHockeyAppEmail];
|
||||
_sut.authenticationSecret = @"double";
|
||||
[_sut validateWithCompletion:nil];
|
||||
self.sut.hockeyAppClient = httpClientMock;
|
||||
self.sut.identificationType = BITAuthenticatorIdentificationTypeHockeyAppEmail;
|
||||
[self.sut storeInstallationIdentifier:@"meh" withType:BITAuthenticatorIdentificationTypeHockeyAppEmail];
|
||||
self.sut.authenticationSecret = @"double";
|
||||
[self.sut validateWithCompletion:nil];
|
||||
[verify(httpClientMock) getPath:(id)anything()
|
||||
parameters:(id)anything()
|
||||
completion:(id)anything()];
|
||||
@@ -275,26 +275,26 @@ static void *kInstallationIdentification = &kInstallationIdentification;
|
||||
|
||||
#pragma mark - Authentication
|
||||
- (void) testThatEnabledRestrictionTriggersValidation {
|
||||
id mockAuthenticator = OCMPartialMock(_sut);
|
||||
_sut.authenticationSecret = @"sekret";
|
||||
_sut.restrictApplicationUsage = YES;
|
||||
_sut.identificationType = BITAuthenticatorIdentificationTypeHockeyAppEmail;
|
||||
[_sut storeInstallationIdentifier:@"asd" withType:BITAuthenticatorIdentificationTypeHockeyAppEmail];
|
||||
id mockAuthenticator = OCMPartialMock(self.sut);
|
||||
self.sut.authenticationSecret = @"sekret";
|
||||
self.sut.restrictApplicationUsage = YES;
|
||||
self.sut.identificationType = BITAuthenticatorIdentificationTypeHockeyAppEmail;
|
||||
[self.sut storeInstallationIdentifier:@"asd" withType:BITAuthenticatorIdentificationTypeHockeyAppEmail];
|
||||
|
||||
|
||||
OCMExpect([mockAuthenticator validateWithCompletion:(id)anything()]);
|
||||
[_sut authenticate];
|
||||
[self.sut authenticate];
|
||||
OCMVerifyAll(mockAuthenticator);
|
||||
}
|
||||
|
||||
- (void) testThatDisabledRestrictionDoesntTriggerValidation {
|
||||
id clientMock = mock(BITHockeyAppClient.class);
|
||||
_sut.hockeyAppClient = clientMock;
|
||||
_sut.authenticationSecret = @"sekret";
|
||||
_sut.restrictApplicationUsage = NO;
|
||||
_sut.identificationType = BITAuthenticatorIdentificationTypeHockeyAppEmail;
|
||||
[_sut storeInstallationIdentifier:@"asd" withType:BITAuthenticatorIdentificationTypeHockeyAppEmail];
|
||||
[_sut authenticate];
|
||||
self.sut.hockeyAppClient = clientMock;
|
||||
self.sut.authenticationSecret = @"sekret";
|
||||
self.sut.restrictApplicationUsage = NO;
|
||||
self.sut.identificationType = BITAuthenticatorIdentificationTypeHockeyAppEmail;
|
||||
[self.sut storeInstallationIdentifier:@"asd" withType:BITAuthenticatorIdentificationTypeHockeyAppEmail];
|
||||
[self.sut authenticate];
|
||||
|
||||
[verifyCount(clientMock, never()) getPath:(id)anything() parameters:(id)anything() completion:(id)anything()];
|
||||
}
|
||||
@@ -302,31 +302,31 @@ static void *kInstallationIdentification = &kInstallationIdentification;
|
||||
#pragma mark - Lifetime checks
|
||||
- (void) testThatValidationTriggersOnDidBecomeActive {
|
||||
id delegateMock = mockProtocol(@protocol(BITAuthenticatorDelegate));
|
||||
_sut.delegate = delegateMock;
|
||||
_sut.identificationType = BITAuthenticatorIdentificationTypeDevice;
|
||||
_sut.restrictApplicationUsage = YES;
|
||||
self.sut.delegate = delegateMock;
|
||||
self.sut.identificationType = BITAuthenticatorIdentificationTypeDevice;
|
||||
self.sut.restrictApplicationUsage = YES;
|
||||
|
||||
[_sut applicationDidBecomeActive:nil];
|
||||
[self.sut applicationDidBecomeActive:nil];
|
||||
|
||||
[verify(delegateMock) authenticator:_sut willShowAuthenticationController:(id)anything()];
|
||||
[verify(delegateMock) authenticator:self.sut willShowAuthenticationController:(id)anything()];
|
||||
}
|
||||
|
||||
#pragma mark - Validation helper checks
|
||||
- (void) testThatValidationTriggersOnNewVersion {
|
||||
_sut.restrictApplicationUsage = YES;
|
||||
_sut.restrictionEnforcementFrequency = BITAuthenticatorAppRestrictionEnforcementOnFirstLaunch;
|
||||
_sut.identificationType = BITAuthenticatorIdentificationTypeDevice;
|
||||
_sut.validated = YES;
|
||||
_sut.lastAuthenticatedVersion = @"111xxx";
|
||||
assertThatBool(_sut.needsValidation, isTrue());
|
||||
self.sut.restrictApplicationUsage = YES;
|
||||
self.sut.restrictionEnforcementFrequency = BITAuthenticatorAppRestrictionEnforcementOnFirstLaunch;
|
||||
self.sut.identificationType = BITAuthenticatorIdentificationTypeDevice;
|
||||
self.sut.validated = YES;
|
||||
self.sut.lastAuthenticatedVersion = @"111xxx";
|
||||
assertThatBool(self.sut.needsValidation, isTrue());
|
||||
}
|
||||
|
||||
- (void) testThatValidationDoesNotTriggerOnSameVersion {
|
||||
_sut.restrictApplicationUsage = YES;
|
||||
_sut.restrictionEnforcementFrequency = BITAuthenticatorAppRestrictionEnforcementOnFirstLaunch;
|
||||
_sut.validated = YES;
|
||||
_sut.lastAuthenticatedVersion = _sut.executableUUID;
|
||||
assertThatBool(_sut.needsValidation, isFalse());
|
||||
self.sut.restrictApplicationUsage = YES;
|
||||
self.sut.restrictionEnforcementFrequency = BITAuthenticatorAppRestrictionEnforcementOnFirstLaunch;
|
||||
self.sut.validated = YES;
|
||||
self.sut.lastAuthenticatedVersion = self.sut.executableUUID;
|
||||
assertThatBool(self.sut.needsValidation, isFalse());
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@@ -14,20 +14,20 @@
|
||||
|
||||
@interface BITChannelTests : XCTestCase
|
||||
|
||||
@property(nonatomic, strong) BITChannel *sut;
|
||||
@property(nonatomic, strong) BITPersistence *mockPersistence;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@implementation BITChannelTests {
|
||||
BITChannel *_sut;
|
||||
BITPersistence *_mockPersistence;
|
||||
}
|
||||
@implementation BITChannelTests
|
||||
|
||||
- (void)setUp {
|
||||
[super setUp];
|
||||
_mockPersistence = OCMPartialMock([[BITPersistence alloc] init]);
|
||||
self.mockPersistence = OCMPartialMock([[BITPersistence alloc] init]);
|
||||
BITTelemetryContext *mockContext = mock(BITTelemetryContext.class);
|
||||
|
||||
_sut = [[BITChannel alloc]initWithTelemetryContext:mockContext persistence:_mockPersistence];
|
||||
self.sut = [[BITChannel alloc]initWithTelemetryContext:mockContext persistence:self.mockPersistence];
|
||||
bit_resetSafeJsonStream(&BITSafeJsonEventsString);
|
||||
}
|
||||
|
||||
@@ -35,47 +35,47 @@
|
||||
|
||||
- (void)testNewInstanceWasInitialisedCorrectly {
|
||||
XCTAssertNotNil([BITChannel new]);
|
||||
XCTAssertNotNil(_sut.dataItemsOperations);
|
||||
XCTAssertNotNil(self.sut.dataItemsOperations);
|
||||
}
|
||||
|
||||
#pragma mark - Queue management
|
||||
|
||||
- (void)testEnqueueEnvelopeWithOneEnvelopeAndJSONStream {
|
||||
_sut = OCMPartialMock(_sut);
|
||||
_sut.maxBatchSize = 3;
|
||||
self.sut = OCMPartialMock(self.sut);
|
||||
self.sut.maxBatchSize = 3;
|
||||
BITTelemetryData *testData = [BITTelemetryData new];
|
||||
|
||||
[_sut enqueueTelemetryItem:testData];
|
||||
[self.sut enqueueTelemetryItem:testData];
|
||||
|
||||
dispatch_sync(_sut.dataItemsOperations, ^{
|
||||
assertThatUnsignedInteger(_sut.dataItemCount, equalToUnsignedInteger(1));
|
||||
dispatch_sync(self.sut.dataItemsOperations, ^{
|
||||
assertThatUnsignedInteger(self.sut.dataItemCount, equalToUnsignedInteger(1));
|
||||
XCTAssertTrue(strlen(BITSafeJsonEventsString) > 0);
|
||||
});
|
||||
}
|
||||
|
||||
- (void)testEnqueueEnvelopeWithMultipleEnvelopesAndJSONStream {
|
||||
_sut = OCMPartialMock(_sut);
|
||||
_sut.maxBatchSize = 3;
|
||||
self.sut = OCMPartialMock(self.sut);
|
||||
self.sut.maxBatchSize = 3;
|
||||
|
||||
BITTelemetryData *testData = [BITTelemetryData new];
|
||||
|
||||
assertThatUnsignedInteger(_sut.dataItemCount, equalToUnsignedInteger(0));
|
||||
assertThatUnsignedInteger(self.sut.dataItemCount, equalToUnsignedInteger(0));
|
||||
|
||||
[_sut enqueueTelemetryItem:testData];
|
||||
dispatch_sync(_sut.dataItemsOperations, ^{
|
||||
assertThatUnsignedInteger(_sut.dataItemCount, equalToUnsignedInteger(1));
|
||||
[self.sut enqueueTelemetryItem:testData];
|
||||
dispatch_sync(self.sut.dataItemsOperations, ^{
|
||||
assertThatUnsignedInteger(self.sut.dataItemCount, equalToUnsignedInteger(1));
|
||||
XCTAssertTrue(strlen(BITSafeJsonEventsString) > 0);
|
||||
});
|
||||
|
||||
[_sut enqueueTelemetryItem:testData];
|
||||
dispatch_sync(_sut.dataItemsOperations, ^{
|
||||
assertThatUnsignedInteger(_sut.dataItemCount, equalToUnsignedInteger(2));
|
||||
[self.sut enqueueTelemetryItem:testData];
|
||||
dispatch_sync(self.sut.dataItemsOperations, ^{
|
||||
assertThatUnsignedInteger(self.sut.dataItemCount, equalToUnsignedInteger(2));
|
||||
XCTAssertTrue(strlen(BITSafeJsonEventsString) > 0);
|
||||
});
|
||||
|
||||
[_sut enqueueTelemetryItem:testData];
|
||||
dispatch_sync(_sut.dataItemsOperations, ^{
|
||||
assertThatUnsignedInteger(_sut.dataItemCount, equalToUnsignedInteger(0));
|
||||
[self.sut enqueueTelemetryItem:testData];
|
||||
dispatch_sync(self.sut.dataItemsOperations, ^{
|
||||
assertThatUnsignedInteger(self.sut.dataItemCount, equalToUnsignedInteger(0));
|
||||
XCTAssertTrue(strcmp(BITSafeJsonEventsString, "") == 0);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -28,37 +28,38 @@ static NSString *const kBITCrashMetaAttachment = @"BITCrashMetaAttachment";
|
||||
@interface BITCrashManagerTests : XCTestCase
|
||||
|
||||
@property BITCrashManager *sut;
|
||||
@property BOOL startManagerInitialized;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@implementation BITCrashManagerTests {
|
||||
BOOL _startManagerInitialized;
|
||||
|
||||
}
|
||||
|
||||
- (void)setUp {
|
||||
[super setUp];
|
||||
|
||||
_startManagerInitialized = NO;
|
||||
_sut = [[BITCrashManager alloc] initWithAppIdentifier:nil appEnvironment:BITEnvironmentOther hockeyAppClient:[[BITHockeyAppClient alloc] initWithBaseURL:[NSURL URLWithString: BITHOCKEYSDK_URL]]];
|
||||
self.startManagerInitialized = NO;
|
||||
self.sut = [[BITCrashManager alloc] initWithAppIdentifier:nil appEnvironment:BITEnvironmentOther hockeyAppClient:[[BITHockeyAppClient alloc] initWithBaseURL:[NSURL URLWithString: BITHOCKEYSDK_URL]]];
|
||||
}
|
||||
|
||||
- (void)tearDown {
|
||||
[_sut cleanCrashReports];
|
||||
[self.sut cleanCrashReports];
|
||||
[super tearDown];
|
||||
}
|
||||
|
||||
#pragma mark - Private
|
||||
|
||||
- (void)startManager {
|
||||
[_sut startManager];
|
||||
[NSObject cancelPreviousPerformRequestsWithTarget:_sut selector:@selector(invokeDelayedProcessing) object:nil];
|
||||
_startManagerInitialized = YES;
|
||||
[self.sut startManager];
|
||||
[NSObject cancelPreviousPerformRequestsWithTarget:self.sut selector:@selector(invokeDelayedProcessing) object:nil];
|
||||
self.startManagerInitialized = YES;
|
||||
}
|
||||
|
||||
- (void)startManagerDisabled {
|
||||
_sut.crashManagerStatus = BITCrashManagerStatusDisabled;
|
||||
if (_startManagerInitialized) return;
|
||||
self.sut.crashManagerStatus = BITCrashManagerStatusDisabled;
|
||||
if (self.startManagerInitialized) return;
|
||||
[self startManager];
|
||||
}
|
||||
|
||||
@@ -68,15 +69,15 @@ static NSString *const kBITCrashMetaAttachment = @"BITCrashMetaAttachment";
|
||||
[given([metricsManagerMock persistence]) willReturn:[[BITPersistence alloc] init]];
|
||||
[[BITHockeyManager sharedHockeyManager] setValue:metricsManagerMock forKey:@"metricsManager"];
|
||||
|
||||
_sut.crashManagerStatus = BITCrashManagerStatusAutoSend;
|
||||
if (_startManagerInitialized) return;
|
||||
self.sut.crashManagerStatus = BITCrashManagerStatusAutoSend;
|
||||
if (self.startManagerInitialized) return;
|
||||
[self startManager];
|
||||
}
|
||||
|
||||
#pragma mark - Setup Tests
|
||||
|
||||
- (void)testThatItInstantiates {
|
||||
XCTAssertNotNil(_sut, @"Should be there");
|
||||
XCTAssertNotNil(self.sut, @"Should be there");
|
||||
}
|
||||
|
||||
#pragma mark - Getter/Setter tests
|
||||
@@ -100,14 +101,14 @@ static NSString *const kBITCrashMetaAttachment = @"BITCrashMetaAttachment";
|
||||
|
||||
- (void)testPersistUserProvidedMetaData {
|
||||
NSString *tempCrashName = @"tempCrash";
|
||||
[_sut setLastCrashFilename:tempCrashName];
|
||||
[self.sut setLastCrashFilename:tempCrashName];
|
||||
|
||||
BITCrashMetaData *metaData = [BITCrashMetaData new];
|
||||
[metaData setUserProvidedDescription:@"Test string"];
|
||||
[_sut persistUserProvidedMetaData:metaData];
|
||||
[self.sut persistUserProvidedMetaData:metaData];
|
||||
|
||||
NSError *error;
|
||||
NSString *description = [NSString stringWithContentsOfFile:[NSString stringWithFormat:@"%@.desc", [[_sut crashesDir] stringByAppendingPathComponent: tempCrashName]] encoding:NSUTF8StringEncoding error:&error];
|
||||
NSString *description = [NSString stringWithContentsOfFile:[NSString stringWithFormat:@"%@.desc", [[self.sut crashesDir] stringByAppendingPathComponent: tempCrashName]] encoding:NSUTF8StringEncoding error:&error];
|
||||
assertThat(description, equalTo(@"Test string"));
|
||||
}
|
||||
|
||||
@@ -118,11 +119,11 @@ static NSString *const kBITCrashMetaAttachment = @"BITCrashMetaAttachment";
|
||||
NSString* type = @"text/plain";
|
||||
|
||||
BITHockeyAttachment *originalAttachment = [[BITHockeyAttachment alloc] initWithFilename:filename hockeyAttachmentData:data contentType:type];
|
||||
NSString *attachmentFilename = [[_sut crashesDir] stringByAppendingPathComponent:@"testAttachment"];
|
||||
NSString *attachmentFilename = [[self.sut crashesDir] stringByAppendingPathComponent:@"testAttachment"];
|
||||
|
||||
[_sut persistAttachment:originalAttachment withFilename:attachmentFilename];
|
||||
[self.sut persistAttachment:originalAttachment withFilename:attachmentFilename];
|
||||
|
||||
BITHockeyAttachment *decodedAttachment = [_sut attachmentForCrashReport:attachmentFilename];
|
||||
BITHockeyAttachment *decodedAttachment = [self.sut attachmentForCrashReport:attachmentFilename];
|
||||
|
||||
assertThat(decodedAttachment.filename, equalTo(filename));
|
||||
assertThat(decodedAttachment.hockeyAttachmentData, equalTo(data));
|
||||
@@ -135,78 +136,78 @@ static NSString *const kBITCrashMetaAttachment = @"BITCrashMetaAttachment";
|
||||
BITHockeyManager *hm = [BITHockeyManager sharedHockeyManager];
|
||||
id delegateMock = mockProtocol(@protocol(BITHockeyManagerDelegate));
|
||||
hm.delegate = delegateMock;
|
||||
_sut.delegate = delegateMock;
|
||||
self.sut.delegate = delegateMock;
|
||||
|
||||
NSString *result = [_sut userIDForCrashReport];
|
||||
NSString *result = [self.sut userIDForCrashReport];
|
||||
|
||||
assertThat(result, notNilValue());
|
||||
|
||||
[verifyCount(delegateMock, times(1)) userIDForHockeyManager:hm componentManager:_sut];
|
||||
[verifyCount(delegateMock, times(1)) userIDForHockeyManager:hm componentManager:self.sut];
|
||||
}
|
||||
|
||||
- (void)testUserNameForCrashReport {
|
||||
BITHockeyManager *hm = [BITHockeyManager sharedHockeyManager];
|
||||
id delegateMock = mockProtocol(@protocol(BITHockeyManagerDelegate));
|
||||
hm.delegate = delegateMock;
|
||||
_sut.delegate = delegateMock;
|
||||
self.sut.delegate = delegateMock;
|
||||
|
||||
NSString *result = [_sut userNameForCrashReport];
|
||||
NSString *result = [self.sut userNameForCrashReport];
|
||||
|
||||
assertThat(result, notNilValue());
|
||||
|
||||
[verifyCount(delegateMock, times(1)) userNameForHockeyManager:hm componentManager:_sut];
|
||||
[verifyCount(delegateMock, times(1)) userNameForHockeyManager:hm componentManager:self.sut];
|
||||
}
|
||||
|
||||
- (void)testUserEmailForCrashReport {
|
||||
BITHockeyManager *hm = [BITHockeyManager sharedHockeyManager];
|
||||
id delegateMock = mockProtocol(@protocol(BITHockeyManagerDelegate));
|
||||
hm.delegate = delegateMock;
|
||||
_sut.delegate = delegateMock;
|
||||
self.sut.delegate = delegateMock;
|
||||
|
||||
NSString *result = [_sut userEmailForCrashReport];
|
||||
NSString *result = [self.sut userEmailForCrashReport];
|
||||
|
||||
assertThat(result, notNilValue());
|
||||
|
||||
[verifyCount(delegateMock, times(1)) userEmailForHockeyManager:hm componentManager:_sut];
|
||||
[verifyCount(delegateMock, times(1)) userEmailForHockeyManager:hm componentManager:self.sut];
|
||||
}
|
||||
|
||||
#pragma mark - Handle User Input
|
||||
|
||||
- (void)testHandleUserInputDontSend {
|
||||
id <BITCrashManagerDelegate> delegateMock = mockProtocol(@protocol(BITCrashManagerDelegate));
|
||||
_sut.delegate = delegateMock;
|
||||
self.sut.delegate = delegateMock;
|
||||
|
||||
assertThatBool([_sut handleUserInput:BITCrashManagerUserInputDontSend withUserProvidedMetaData:nil], isTrue());
|
||||
assertThatBool([self.sut handleUserInput:BITCrashManagerUserInputDontSend withUserProvidedMetaData:nil], isTrue());
|
||||
|
||||
[verify(delegateMock) crashManagerWillCancelSendingCrashReport:_sut];
|
||||
[verify(delegateMock) crashManagerWillCancelSendingCrashReport:self.sut];
|
||||
|
||||
}
|
||||
|
||||
- (void)testHandleUserInputSend {
|
||||
assertThatBool([_sut handleUserInput:BITCrashManagerUserInputSend withUserProvidedMetaData:nil], isTrue());
|
||||
assertThatBool([self.sut handleUserInput:BITCrashManagerUserInputSend withUserProvidedMetaData:nil], isTrue());
|
||||
}
|
||||
|
||||
- (void)testHandleUserInputAlwaysSend {
|
||||
id <BITCrashManagerDelegate> delegateMock = mockProtocol(@protocol(BITCrashManagerDelegate));
|
||||
_sut.delegate = delegateMock;
|
||||
self.sut.delegate = delegateMock;
|
||||
NSUserDefaults *mockUserDefaults = mock([NSUserDefaults class]);
|
||||
|
||||
//Test if CrashManagerStatus is unset
|
||||
[given([mockUserDefaults integerForKey:@"BITCrashManagerStatus"]) willReturn:nil];
|
||||
|
||||
//Test if method runs through
|
||||
assertThatBool([_sut handleUserInput:BITCrashManagerUserInputAlwaysSend withUserProvidedMetaData:nil], isTrue());
|
||||
assertThatBool([self.sut handleUserInput:BITCrashManagerUserInputAlwaysSend withUserProvidedMetaData:nil], isTrue());
|
||||
|
||||
//Test if correct CrashManagerStatus is now set
|
||||
[given([mockUserDefaults integerForKey:@"BITCrashManagerStauts"]) willReturnInt:BITCrashManagerStatusAutoSend];
|
||||
|
||||
//Verify that delegate method has been called
|
||||
[verify(delegateMock) crashManagerWillSendCrashReportsAlways:_sut];
|
||||
[verify(delegateMock) crashManagerWillSendCrashReportsAlways:self.sut];
|
||||
|
||||
}
|
||||
|
||||
- (void)testHandleUserInputWithInvalidInput {
|
||||
assertThatBool([_sut handleUserInput:3 withUserProvidedMetaData:nil], isFalse());
|
||||
assertThatBool([self.sut handleUserInput:3 withUserProvidedMetaData:nil], isFalse());
|
||||
}
|
||||
|
||||
#pragma mark - Debugger
|
||||
@@ -220,20 +221,20 @@ static NSString *const kBITCrashMetaAttachment = @"BITCrashMetaAttachment";
|
||||
* TODO: what to do if we do run this e.g. on Jenkins or Xcode bots ?
|
||||
*/
|
||||
- (void)testIsDebuggerAttached {
|
||||
assertThatBool([_sut isDebuggerAttached], isTrue());
|
||||
assertThatBool([self.sut isDebuggerAttached], isTrue());
|
||||
}
|
||||
#endif
|
||||
|
||||
#pragma mark - Helper
|
||||
|
||||
- (void)testHasPendingCrashReportWithNoFiles {
|
||||
_sut.crashManagerStatus = BITCrashManagerStatusAutoSend;
|
||||
assertThatBool([_sut hasPendingCrashReport], isFalse());
|
||||
self.sut.crashManagerStatus = BITCrashManagerStatusAutoSend;
|
||||
assertThatBool([self.sut hasPendingCrashReport], isFalse());
|
||||
}
|
||||
|
||||
- (void)testFirstNotApprovedCrashReportWithNoFiles {
|
||||
_sut.crashManagerStatus = BITCrashManagerStatusAutoSend;
|
||||
assertThat([_sut firstNotApprovedCrashReport], equalTo(nil));
|
||||
self.sut.crashManagerStatus = BITCrashManagerStatusAutoSend;
|
||||
assertThat([self.sut firstNotApprovedCrashReport], equalTo(nil));
|
||||
}
|
||||
|
||||
|
||||
@@ -242,7 +243,7 @@ static NSString *const kBITCrashMetaAttachment = @"BITCrashMetaAttachment";
|
||||
- (void)testStartManagerWithModuleDisabled {
|
||||
[self startManagerDisabled];
|
||||
|
||||
assertThat(_sut.plCrashReporter, equalTo(nil));
|
||||
assertThat(self.sut.plCrashReporter, equalTo(nil));
|
||||
}
|
||||
|
||||
- (void)testStartManagerWithAutoSend {
|
||||
@@ -254,128 +255,128 @@ static NSString *const kBITCrashMetaAttachment = @"BITCrashMetaAttachment";
|
||||
// to make this better testable with unit tests
|
||||
|
||||
id delegateMock = mockProtocol(@protocol(BITCrashManagerDelegate));
|
||||
_sut.delegate = delegateMock;
|
||||
self.sut.delegate = delegateMock;
|
||||
|
||||
[self startManagerAutoSend];
|
||||
|
||||
assertThat(_sut.plCrashReporter, notNilValue());
|
||||
assertThat(self.sut.plCrashReporter, notNilValue());
|
||||
|
||||
// When running from the debugger this is always nil and not the exception handler from PLCR
|
||||
NSUncaughtExceptionHandler *currentHandler = NSGetUncaughtExceptionHandler();
|
||||
|
||||
BOOL result = (_sut.exceptionHandler == currentHandler);
|
||||
BOOL result = (self.sut.exceptionHandler == currentHandler);
|
||||
|
||||
assertThatBool(result, isTrue());
|
||||
|
||||
// No files at startup
|
||||
assertThatBool([_sut hasPendingCrashReport], isFalse());
|
||||
assertThat([_sut firstNotApprovedCrashReport], equalTo(nil));
|
||||
assertThatBool([self.sut hasPendingCrashReport], isFalse());
|
||||
assertThat([self.sut firstNotApprovedCrashReport], equalTo(nil));
|
||||
|
||||
[_sut invokeDelayedProcessing];
|
||||
[self.sut invokeDelayedProcessing];
|
||||
|
||||
// handle a new empty crash report
|
||||
assertThatBool([BITTestHelper copyFixtureCrashReportWithFileName:@"live_report_empty"], isTrue());
|
||||
|
||||
[_sut handleCrashReport];
|
||||
[self.sut handleCrashReport];
|
||||
|
||||
// we should have 0 pending crash report
|
||||
assertThatBool([_sut hasPendingCrashReport], isFalse());
|
||||
assertThat([_sut firstNotApprovedCrashReport], equalTo(nil));
|
||||
assertThatBool([self.sut hasPendingCrashReport], isFalse());
|
||||
assertThat([self.sut firstNotApprovedCrashReport], equalTo(nil));
|
||||
|
||||
[_sut cleanCrashReports];
|
||||
[self.sut cleanCrashReports];
|
||||
|
||||
// handle a new signal crash report
|
||||
assertThatBool([BITTestHelper copyFixtureCrashReportWithFileName:@"live_report_signal"], isTrue());
|
||||
|
||||
[_sut handleCrashReport];
|
||||
[self.sut handleCrashReport];
|
||||
|
||||
// this old report doesn't have a marketing version present
|
||||
assertThat(_sut.lastSessionCrashDetails.appVersion, equalTo(nil));
|
||||
assertThat(self.sut.lastSessionCrashDetails.appVersion, equalTo(nil));
|
||||
|
||||
[verifyCount(delegateMock, times(1)) applicationLogForCrashManager:_sut];
|
||||
[verifyCount(delegateMock, times(1)) attachmentForCrashManager:_sut];
|
||||
[verifyCount(delegateMock, times(1)) applicationLogForCrashManager:self.sut];
|
||||
[verifyCount(delegateMock, times(1)) attachmentForCrashManager:self.sut];
|
||||
|
||||
// we should have now 1 pending crash report
|
||||
assertThatBool([_sut hasPendingCrashReport], isTrue());
|
||||
assertThat([_sut firstNotApprovedCrashReport], notNilValue());
|
||||
assertThatBool([self.sut hasPendingCrashReport], isTrue());
|
||||
assertThat([self.sut firstNotApprovedCrashReport], notNilValue());
|
||||
|
||||
// this is currently sending blindly, needs refactoring to test properly
|
||||
[_sut sendNextCrashReport];
|
||||
[verifyCount(delegateMock, times(1)) crashManagerWillSendCrashReport:_sut];
|
||||
[self.sut sendNextCrashReport];
|
||||
[verifyCount(delegateMock, times(1)) crashManagerWillSendCrashReport:self.sut];
|
||||
|
||||
[_sut cleanCrashReports];
|
||||
[self.sut cleanCrashReports];
|
||||
|
||||
// handle a new signal crash report
|
||||
assertThatBool([BITTestHelper copyFixtureCrashReportWithFileName:@"live_report_exception"], isTrue());
|
||||
|
||||
[_sut handleCrashReport];
|
||||
[self.sut handleCrashReport];
|
||||
|
||||
// this old report doesn't have a marketing version present
|
||||
assertThat(_sut.lastSessionCrashDetails.appVersion, equalTo(nil));
|
||||
assertThat(self.sut.lastSessionCrashDetails.appVersion, equalTo(nil));
|
||||
|
||||
[verifyCount(delegateMock, times(1)) applicationLogForCrashManager:_sut];
|
||||
[verifyCount(delegateMock, times(1)) attachmentForCrashManager:_sut];
|
||||
[verifyCount(delegateMock, times(1)) applicationLogForCrashManager:self.sut];
|
||||
[verifyCount(delegateMock, times(1)) attachmentForCrashManager:self.sut];
|
||||
|
||||
// we should have now 1 pending crash report
|
||||
assertThatBool([_sut hasPendingCrashReport], isTrue());
|
||||
assertThat([_sut firstNotApprovedCrashReport], notNilValue());
|
||||
assertThatBool([self.sut hasPendingCrashReport], isTrue());
|
||||
assertThat([self.sut firstNotApprovedCrashReport], notNilValue());
|
||||
|
||||
[_sut cleanCrashReports];
|
||||
[self.sut cleanCrashReports];
|
||||
|
||||
// handle a new signal crash report
|
||||
assertThatBool([BITTestHelper copyFixtureCrashReportWithFileName:@"live_report_signal_marketing"], isTrue());
|
||||
|
||||
[_sut handleCrashReport];
|
||||
[self.sut handleCrashReport];
|
||||
|
||||
// this old report doesn't have a marketing version present
|
||||
assertThat(_sut.lastSessionCrashDetails.appVersion, notNilValue());
|
||||
assertThat(self.sut.lastSessionCrashDetails.appVersion, notNilValue());
|
||||
|
||||
[verifyCount(delegateMock, times(1)) applicationLogForCrashManager:_sut];
|
||||
[verifyCount(delegateMock, times(1)) attachmentForCrashManager:_sut];
|
||||
[verifyCount(delegateMock, times(1)) applicationLogForCrashManager:self.sut];
|
||||
[verifyCount(delegateMock, times(1)) attachmentForCrashManager:self.sut];
|
||||
|
||||
// we should have now 1 pending crash report
|
||||
assertThatBool([_sut hasPendingCrashReport], isTrue());
|
||||
assertThat([_sut firstNotApprovedCrashReport], notNilValue());
|
||||
assertThatBool([self.sut hasPendingCrashReport], isTrue());
|
||||
assertThat([self.sut firstNotApprovedCrashReport], notNilValue());
|
||||
|
||||
// this is currently sending blindly, needs refactoring to test properly
|
||||
[_sut sendNextCrashReport];
|
||||
[verifyCount(delegateMock, times(1)) crashManagerWillSendCrashReport:_sut];
|
||||
[self.sut sendNextCrashReport];
|
||||
[verifyCount(delegateMock, times(1)) crashManagerWillSendCrashReport:self.sut];
|
||||
|
||||
[_sut cleanCrashReports];
|
||||
[self.sut cleanCrashReports];
|
||||
|
||||
// handle a new signal crash report
|
||||
assertThatBool([BITTestHelper copyFixtureCrashReportWithFileName:@"live_report_exception_marketing"], isTrue());
|
||||
|
||||
[_sut handleCrashReport];
|
||||
[self.sut handleCrashReport];
|
||||
|
||||
// this old report doesn't have a marketing version present
|
||||
assertThat(_sut.lastSessionCrashDetails.appVersion, notNilValue());
|
||||
assertThat(self.sut.lastSessionCrashDetails.appVersion, notNilValue());
|
||||
|
||||
[verifyCount(delegateMock, times(1)) applicationLogForCrashManager:_sut];
|
||||
[verifyCount(delegateMock, times(1)) attachmentForCrashManager:_sut];
|
||||
[verifyCount(delegateMock, times(1)) applicationLogForCrashManager:self.sut];
|
||||
[verifyCount(delegateMock, times(1)) attachmentForCrashManager:self.sut];
|
||||
|
||||
// we should have now 1 pending crash report
|
||||
assertThatBool([_sut hasPendingCrashReport], isTrue());
|
||||
assertThat([_sut firstNotApprovedCrashReport], notNilValue());
|
||||
assertThatBool([self.sut hasPendingCrashReport], isTrue());
|
||||
assertThat([self.sut firstNotApprovedCrashReport], notNilValue());
|
||||
|
||||
[_sut cleanCrashReports];
|
||||
[self.sut cleanCrashReports];
|
||||
|
||||
// handle a new xamarin crash report
|
||||
assertThatBool([BITTestHelper copyFixtureCrashReportWithFileName:@"live_report_xamarin"], isTrue());
|
||||
|
||||
[_sut handleCrashReport];
|
||||
[self.sut handleCrashReport];
|
||||
|
||||
// this old report doesn't have a marketing version present
|
||||
assertThat(_sut.lastSessionCrashDetails.appVersion, notNilValue());
|
||||
assertThat(self.sut.lastSessionCrashDetails.appVersion, notNilValue());
|
||||
|
||||
[verifyCount(delegateMock, times(1)) applicationLogForCrashManager:_sut];
|
||||
[verifyCount(delegateMock, times(1)) attachmentForCrashManager:_sut];
|
||||
[verifyCount(delegateMock, times(1)) applicationLogForCrashManager:self.sut];
|
||||
[verifyCount(delegateMock, times(1)) attachmentForCrashManager:self.sut];
|
||||
|
||||
// we should have now 1 pending crash report
|
||||
assertThatBool([_sut hasPendingCrashReport], isTrue());
|
||||
assertThat([_sut firstNotApprovedCrashReport], notNilValue());
|
||||
assertThatBool([self.sut hasPendingCrashReport], isTrue());
|
||||
assertThat([self.sut firstNotApprovedCrashReport], notNilValue());
|
||||
|
||||
[_sut cleanCrashReports];
|
||||
[self.sut cleanCrashReports];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@@ -17,21 +17,22 @@
|
||||
#import "BITTestHelper.h"
|
||||
|
||||
@interface BITHockeyAppClientTests : XCTestCase
|
||||
|
||||
@property(nonatomic, strong) BITHockeyAppClient *sut;
|
||||
|
||||
@end
|
||||
|
||||
@implementation BITHockeyAppClientTests {
|
||||
BITHockeyAppClient *_sut;
|
||||
}
|
||||
@implementation BITHockeyAppClientTests
|
||||
|
||||
- (void)setUp {
|
||||
[super setUp];
|
||||
|
||||
_sut = [[BITHockeyAppClient alloc] initWithBaseURL:[NSURL URLWithString:@"http://bitbaseurl.com"]];
|
||||
self.sut = [[BITHockeyAppClient alloc] initWithBaseURL:[NSURL URLWithString:@"http://bitbaseurl.com"]];
|
||||
}
|
||||
|
||||
- (void)tearDown {
|
||||
[_sut cancelOperationsWithPath:nil method:nil];
|
||||
_sut = nil;
|
||||
[self.sut cancelOperationsWithPath:nil method:nil];
|
||||
self.sut = nil;
|
||||
|
||||
[super tearDown];
|
||||
}
|
||||
@@ -49,32 +50,32 @@
|
||||
|
||||
#pragma mark - Setup Tests
|
||||
- (void) testThatItInstantiates {
|
||||
XCTAssertNotNil(_sut, @"Should be there");
|
||||
XCTAssertNotNil(self.sut, @"Should be there");
|
||||
}
|
||||
|
||||
#pragma mark - Networking base tests
|
||||
- (void) testThatURLRequestHasBaseURLSet {
|
||||
_sut.baseURL = [NSURL URLWithString:@"http://myserver.com"];
|
||||
NSMutableURLRequest *request = [_sut requestWithMethod:@"GET" path:nil parameters:nil];
|
||||
self.sut.baseURL = [NSURL URLWithString:@"http://myserver.com"];
|
||||
NSMutableURLRequest *request = [self.sut requestWithMethod:@"GET" path:nil parameters:nil];
|
||||
assertThat(request.URL, equalTo([NSURL URLWithString:@"http://myserver.com/"]));
|
||||
}
|
||||
|
||||
- (void) testThatURLRequestHasPathAppended {
|
||||
_sut.baseURL = [NSURL URLWithString:@"http://myserver.com"];
|
||||
NSMutableURLRequest *request = [_sut requestWithMethod:@"GET" path:@"projects" parameters:nil];
|
||||
self.sut.baseURL = [NSURL URLWithString:@"http://myserver.com"];
|
||||
NSMutableURLRequest *request = [self.sut requestWithMethod:@"GET" path:@"projects" parameters:nil];
|
||||
assertThat(request.URL, equalTo([NSURL URLWithString:@"http://myserver.com/projects"]));
|
||||
}
|
||||
|
||||
- (void) testThatURLRequestHasMethodSet {
|
||||
NSMutableURLRequest *request = [_sut requestWithMethod:@"POST" path:nil parameters:nil];
|
||||
NSMutableURLRequest *request = [self.sut requestWithMethod:@"POST" path:nil parameters:nil];
|
||||
|
||||
assertThat(request.HTTPMethod, equalTo(@"POST"));
|
||||
}
|
||||
|
||||
- (void) testThatOperationHasURLRequestSet {
|
||||
_sut.baseURL = [NSURL URLWithString:@"http://myserver.com"];
|
||||
NSURLRequest *r = [_sut requestWithMethod:@"PUT" path:@"x" parameters:nil];
|
||||
BITHTTPOperation *op = [_sut operationWithURLRequest:r
|
||||
self.sut.baseURL = [NSURL URLWithString:@"http://myserver.com"];
|
||||
NSURLRequest *r = [self.sut requestWithMethod:@"PUT" path:@"x" parameters:nil];
|
||||
BITHTTPOperation *op = [self.sut operationWithURLRequest:r
|
||||
completion:nil];
|
||||
assertThat(op.URLRequest, equalTo(r));
|
||||
}
|
||||
@@ -84,7 +85,7 @@
|
||||
@"email" : @"peter@pan.de",
|
||||
@"push" : @"pop",
|
||||
};
|
||||
NSMutableURLRequest *request = [_sut requestWithMethod:@"GET"
|
||||
NSMutableURLRequest *request = [self.sut requestWithMethod:@"GET"
|
||||
path:@"something"
|
||||
parameters:parameters];
|
||||
NSURL *url = request.URL;
|
||||
@@ -107,25 +108,25 @@
|
||||
|
||||
#pragma mark - Convenience methods
|
||||
- (void) testThatGetPathCreatesAndEnquesAnOperation {
|
||||
assertThatUnsignedLong(_sut.operationQueue.operationCount, equalToUnsignedLong(0));
|
||||
[given([_sut operationWithURLRequest:(id)anything()
|
||||
assertThatUnsignedLong(self.sut.operationQueue.operationCount, equalToUnsignedLong(0));
|
||||
[given([self.sut operationWithURLRequest:(id)anything()
|
||||
completion:nil]) willReturn:[NSOperation new]];
|
||||
|
||||
[_sut getPath:@"endpoint"
|
||||
[self.sut getPath:@"endpoint"
|
||||
parameters:nil
|
||||
completion:nil];
|
||||
assertThatUnsignedLong(_sut.operationQueue.operationCount, equalToUnsignedLong(1));
|
||||
assertThatUnsignedLong(self.sut.operationQueue.operationCount, equalToUnsignedLong(1));
|
||||
}
|
||||
|
||||
- (void) testThatPostPathCreatesAndEnquesAnOperation {
|
||||
assertThatUnsignedLong(_sut.operationQueue.operationCount, equalToUnsignedLong(0));
|
||||
[given([_sut operationWithURLRequest:nil
|
||||
assertThatUnsignedLong(self.sut.operationQueue.operationCount, equalToUnsignedLong(0));
|
||||
[given([self.sut operationWithURLRequest:nil
|
||||
completion:nil]) willReturn:[NSOperation new]];
|
||||
|
||||
[_sut postPath:@"endpoint"
|
||||
[self.sut postPath:@"endpoint"
|
||||
parameters:nil
|
||||
completion:nil];
|
||||
assertThatUnsignedLong(_sut.operationQueue.operationCount, equalToUnsignedLong(1));
|
||||
assertThatUnsignedLong(self.sut.operationQueue.operationCount, equalToUnsignedLong(1));
|
||||
}
|
||||
|
||||
#pragma mark - Completion Tests
|
||||
@@ -135,91 +136,91 @@
|
||||
|
||||
#pragma mark - HTTPOperation enqueuing / cancellation
|
||||
- (void) testThatOperationIsQueued {
|
||||
assertThatUnsignedLong(_sut.operationQueue.operationCount, equalToUnsignedLong(0));
|
||||
[_sut.operationQueue setSuspended:YES];
|
||||
assertThatUnsignedLong(self.sut.operationQueue.operationCount, equalToUnsignedLong(0));
|
||||
[self.sut.operationQueue setSuspended:YES];
|
||||
BITHTTPOperation *op = [BITHTTPOperation new];
|
||||
[_sut enqeueHTTPOperation:op];
|
||||
[self.sut enqeueHTTPOperation:op];
|
||||
|
||||
assertThatUnsignedLong(_sut.operationQueue.operationCount, equalToUnsignedLong(1));
|
||||
assertThatUnsignedLong(self.sut.operationQueue.operationCount, equalToUnsignedLong(1));
|
||||
}
|
||||
|
||||
- (void) testThatOperationCancellingMatchesAllOperationsWithNilMethod {
|
||||
[_sut.operationQueue setSuspended:YES];
|
||||
NSURLRequest *requestGet = [_sut requestWithMethod:@"GET" path:nil parameters:nil];
|
||||
NSURLRequest *requestPut = [_sut requestWithMethod:@"PUT" path:nil parameters:nil];
|
||||
NSURLRequest *requestPost = [_sut requestWithMethod:@"POST" path:nil parameters:nil];
|
||||
[_sut enqeueHTTPOperation:[_sut operationWithURLRequest:requestGet
|
||||
[self.sut.operationQueue setSuspended:YES];
|
||||
NSURLRequest *requestGet = [self.sut requestWithMethod:@"GET" path:nil parameters:nil];
|
||||
NSURLRequest *requestPut = [self.sut requestWithMethod:@"PUT" path:nil parameters:nil];
|
||||
NSURLRequest *requestPost = [self.sut requestWithMethod:@"POST" path:nil parameters:nil];
|
||||
[self.sut enqeueHTTPOperation:[self.sut operationWithURLRequest:requestGet
|
||||
completion:nil]];
|
||||
[_sut enqeueHTTPOperation:[_sut operationWithURLRequest:requestPut
|
||||
[self.sut enqeueHTTPOperation:[self.sut operationWithURLRequest:requestPut
|
||||
completion:nil]];
|
||||
[_sut enqeueHTTPOperation:[_sut operationWithURLRequest:requestPost
|
||||
[self.sut enqeueHTTPOperation:[self.sut operationWithURLRequest:requestPost
|
||||
completion:nil]];
|
||||
assertThatUnsignedLong(_sut.operationQueue.operationCount, equalToUnsignedLong(3));
|
||||
NSUInteger numCancelled = [_sut cancelOperationsWithPath:nil method:nil];
|
||||
assertThatUnsignedLong(self.sut.operationQueue.operationCount, equalToUnsignedLong(3));
|
||||
NSUInteger numCancelled = [self.sut cancelOperationsWithPath:nil method:nil];
|
||||
assertThatUnsignedLong(numCancelled, equalToUnsignedLong(3));
|
||||
}
|
||||
|
||||
- (void) testThatOperationCancellingMatchesAllOperationsWithNilPath {
|
||||
[_sut.operationQueue setSuspended:YES];
|
||||
NSURLRequest *requestGet = [_sut requestWithMethod:@"GET" path:@"test" parameters:nil];
|
||||
NSURLRequest *requestPut = [_sut requestWithMethod:@"PUT" path:@"Another/acas" parameters:nil];
|
||||
NSURLRequest *requestPost = [_sut requestWithMethod:@"POST" path:nil parameters:nil];
|
||||
[_sut enqeueHTTPOperation:[_sut operationWithURLRequest:requestGet
|
||||
[self.sut.operationQueue setSuspended:YES];
|
||||
NSURLRequest *requestGet = [self.sut requestWithMethod:@"GET" path:@"test" parameters:nil];
|
||||
NSURLRequest *requestPut = [self.sut requestWithMethod:@"PUT" path:@"Another/acas" parameters:nil];
|
||||
NSURLRequest *requestPost = [self.sut requestWithMethod:@"POST" path:nil parameters:nil];
|
||||
[self.sut enqeueHTTPOperation:[self.sut operationWithURLRequest:requestGet
|
||||
completion:nil]];
|
||||
[_sut enqeueHTTPOperation:[_sut operationWithURLRequest:requestPut
|
||||
[self.sut enqeueHTTPOperation:[self.sut operationWithURLRequest:requestPut
|
||||
completion:nil]];
|
||||
[_sut enqeueHTTPOperation:[_sut operationWithURLRequest:requestPost
|
||||
[self.sut enqeueHTTPOperation:[self.sut operationWithURLRequest:requestPost
|
||||
completion:nil]];
|
||||
assertThatUnsignedLong(_sut.operationQueue.operationCount, equalToUnsignedLong(3));
|
||||
NSUInteger numCancelled = [_sut cancelOperationsWithPath:nil method:nil];
|
||||
assertThatUnsignedLong(self.sut.operationQueue.operationCount, equalToUnsignedLong(3));
|
||||
NSUInteger numCancelled = [self.sut cancelOperationsWithPath:nil method:nil];
|
||||
assertThatUnsignedLong(numCancelled, equalToUnsignedLong(3));
|
||||
}
|
||||
|
||||
|
||||
- (void) testThatOperationCancellingMatchesAllOperationsWithSetPath {
|
||||
NSURLRequest *requestGet = [_sut requestWithMethod:@"GET" path:@"test" parameters:nil];
|
||||
NSURLRequest *requestPut = [_sut requestWithMethod:@"PUT" path:@"Another/acas" parameters:nil];
|
||||
NSURLRequest *requestPost = [_sut requestWithMethod:@"POST" path:nil parameters:nil];
|
||||
[_sut.operationQueue setSuspended:YES];
|
||||
NSURLRequest *requestGet = [self.sut requestWithMethod:@"GET" path:@"test" parameters:nil];
|
||||
NSURLRequest *requestPut = [self.sut requestWithMethod:@"PUT" path:@"Another/acas" parameters:nil];
|
||||
NSURLRequest *requestPost = [self.sut requestWithMethod:@"POST" path:nil parameters:nil];
|
||||
[self.sut.operationQueue setSuspended:YES];
|
||||
|
||||
[_sut enqeueHTTPOperation:[_sut operationWithURLRequest:requestGet
|
||||
[self.sut enqeueHTTPOperation:[self.sut operationWithURLRequest:requestGet
|
||||
completion:nil]];
|
||||
[_sut enqeueHTTPOperation:[_sut operationWithURLRequest:requestPut
|
||||
[self.sut enqeueHTTPOperation:[self.sut operationWithURLRequest:requestPut
|
||||
completion:nil]];
|
||||
[_sut enqeueHTTPOperation:[_sut operationWithURLRequest:requestPost
|
||||
[self.sut enqeueHTTPOperation:[self.sut operationWithURLRequest:requestPost
|
||||
completion:nil]];
|
||||
assertThatUnsignedLong(_sut.operationQueue.operationCount, equalToUnsignedLong(3));
|
||||
NSUInteger numCancelled = [_sut cancelOperationsWithPath:@"Another/acas" method:nil];
|
||||
assertThatUnsignedLong(self.sut.operationQueue.operationCount, equalToUnsignedLong(3));
|
||||
NSUInteger numCancelled = [self.sut cancelOperationsWithPath:@"Another/acas" method:nil];
|
||||
assertThatUnsignedLong(numCancelled, equalToUnsignedLong(1));
|
||||
}
|
||||
|
||||
- (void) testThatOperationCancellingMatchesAllOperationsWithSetMethod {
|
||||
NSURLRequest *requestGet = [_sut requestWithMethod:@"GET" path:@"test" parameters:nil];
|
||||
NSURLRequest *requestPut = [_sut requestWithMethod:@"PUT" path:@"Another/acas" parameters:nil];
|
||||
NSURLRequest *requestPost = [_sut requestWithMethod:@"POST" path:nil parameters:nil];
|
||||
[_sut enqeueHTTPOperation:[_sut operationWithURLRequest:requestGet
|
||||
NSURLRequest *requestGet = [self.sut requestWithMethod:@"GET" path:@"test" parameters:nil];
|
||||
NSURLRequest *requestPut = [self.sut requestWithMethod:@"PUT" path:@"Another/acas" parameters:nil];
|
||||
NSURLRequest *requestPost = [self.sut requestWithMethod:@"POST" path:nil parameters:nil];
|
||||
[self.sut enqeueHTTPOperation:[self.sut operationWithURLRequest:requestGet
|
||||
completion:nil]];
|
||||
[_sut enqeueHTTPOperation:[_sut operationWithURLRequest:requestPut
|
||||
[self.sut enqeueHTTPOperation:[self.sut operationWithURLRequest:requestPut
|
||||
completion:nil]];
|
||||
[_sut enqeueHTTPOperation:[_sut operationWithURLRequest:requestPost
|
||||
[self.sut enqeueHTTPOperation:[self.sut operationWithURLRequest:requestPost
|
||||
completion:nil]];
|
||||
assertThatUnsignedLong(_sut.operationQueue.operationCount, equalToUnsignedLong(3));
|
||||
NSUInteger numCancelled = [_sut cancelOperationsWithPath:nil method:@"POST"];
|
||||
assertThatUnsignedLong(self.sut.operationQueue.operationCount, equalToUnsignedLong(3));
|
||||
NSUInteger numCancelled = [self.sut cancelOperationsWithPath:nil method:@"POST"];
|
||||
assertThatUnsignedLong(numCancelled, equalToUnsignedLong(1));
|
||||
}
|
||||
|
||||
- (void) testThatOperationCancellingMatchesAllOperationsWithSetMethodAndPath {
|
||||
NSURLRequest *requestGet = [_sut requestWithMethod:@"GET" path:@"test" parameters:nil];
|
||||
NSURLRequest *requestPut = [_sut requestWithMethod:@"PUT" path:@"Another/acas" parameters:nil];
|
||||
NSURLRequest *requestPost = [_sut requestWithMethod:@"POST" path:nil parameters:nil];
|
||||
[_sut enqeueHTTPOperation:[_sut operationWithURLRequest:requestGet
|
||||
NSURLRequest *requestGet = [self.sut requestWithMethod:@"GET" path:@"test" parameters:nil];
|
||||
NSURLRequest *requestPut = [self.sut requestWithMethod:@"PUT" path:@"Another/acas" parameters:nil];
|
||||
NSURLRequest *requestPost = [self.sut requestWithMethod:@"POST" path:nil parameters:nil];
|
||||
[self.sut enqeueHTTPOperation:[self.sut operationWithURLRequest:requestGet
|
||||
completion:nil]];
|
||||
[_sut enqeueHTTPOperation:[_sut operationWithURLRequest:requestPut
|
||||
[self.sut enqeueHTTPOperation:[self.sut operationWithURLRequest:requestPut
|
||||
completion:nil]];
|
||||
[_sut enqeueHTTPOperation:[_sut operationWithURLRequest:requestPost
|
||||
[self.sut enqeueHTTPOperation:[self.sut operationWithURLRequest:requestPost
|
||||
completion:nil]];
|
||||
assertThatUnsignedLong(_sut.operationQueue.operationCount, equalToUnsignedLong(3));
|
||||
NSUInteger numCancelled = [_sut cancelOperationsWithPath:@"Another/acas" method:@"PUT"];
|
||||
assertThatUnsignedLong(self.sut.operationQueue.operationCount, equalToUnsignedLong(3));
|
||||
NSUInteger numCancelled = [self.sut cancelOperationsWithPath:@"Another/acas" method:@"PUT"];
|
||||
assertThatUnsignedLong(numCancelled, equalToUnsignedLong(1));
|
||||
}
|
||||
|
||||
|
||||
@@ -12,35 +12,35 @@
|
||||
|
||||
@interface BITSenderTests : BITTestsDependencyInjection
|
||||
|
||||
@property(nonatomic, strong) BITSender *sut;
|
||||
@property(nonatomic, strong) BITPersistence *mockPersistence;
|
||||
@property(nonatomic, strong) NSURL *testServerURL;
|
||||
|
||||
@end
|
||||
|
||||
@implementation BITSenderTests{
|
||||
BITSender *_sut;
|
||||
BITPersistence *_mockPersistence;
|
||||
NSURL *_testServerURL;
|
||||
}
|
||||
@implementation BITSenderTests
|
||||
|
||||
- (void)setUp {
|
||||
[super setUp];
|
||||
_testServerURL = [NSURL URLWithString:@"http://test.com"];
|
||||
_sut = [self newSender];
|
||||
self.testServerURL = [NSURL URLWithString:@"http://test.com"];
|
||||
self.sut = [self newSender];
|
||||
}
|
||||
|
||||
- (void)tearDown {
|
||||
_sut = nil;
|
||||
self.sut = nil;
|
||||
[super tearDown];
|
||||
}
|
||||
|
||||
- (BITSender *)newSender {
|
||||
_mockPersistence = mock(BITPersistence.class);
|
||||
return [[BITSender alloc]initWithPersistence:_mockPersistence serverURL:[_testServerURL copy]];
|
||||
self.mockPersistence = mock(BITPersistence.class);
|
||||
return [[BITSender alloc]initWithPersistence:self.mockPersistence serverURL:[self.testServerURL copy]];
|
||||
}
|
||||
|
||||
- (void)testThatItInstantiatesCorrectly {
|
||||
XCTAssertNotNil(_sut);
|
||||
XCTAssertNotNil(_sut.senderTasksQueue);
|
||||
XCTAssertEqualObjects(_sut.persistence, _mockPersistence);
|
||||
XCTAssertEqualObjects(_sut.serverURL, _testServerURL);
|
||||
XCTAssertNotNil(self.sut);
|
||||
XCTAssertNotNil(self.sut.senderTasksQueue);
|
||||
XCTAssertEqualObjects(self.sut.persistence, self.mockPersistence);
|
||||
XCTAssertEqualObjects(self.sut.serverURL, self.testServerURL);
|
||||
}
|
||||
|
||||
- (void)testRequestContainsDataItem {
|
||||
@@ -48,7 +48,7 @@
|
||||
NSData *expectedBodyData = [NSJSONSerialization dataWithJSONObject:[testItem serializeToDictionary]
|
||||
options:0
|
||||
error:nil];
|
||||
NSURLRequest *testRequest = [_sut requestForData:expectedBodyData];
|
||||
NSURLRequest *testRequest = [self.sut requestForData:expectedBodyData];
|
||||
|
||||
XCTAssertNotNil(testRequest);
|
||||
XCTAssertEqualObjects(testRequest.HTTPBody, expectedBodyData);
|
||||
@@ -56,31 +56,31 @@
|
||||
|
||||
- (void)testSendDataTriggersPlatformSpecificNetworkOperation {
|
||||
// setup
|
||||
_sut = OCMPartialMock(_sut);
|
||||
OCMStub([_sut isURLSessionSupported]).andReturn(YES);
|
||||
self.sut = OCMPartialMock(self.sut);
|
||||
OCMStub([self.sut isURLSessionSupported]).andReturn(YES);
|
||||
|
||||
NSURLRequest *testRequest = [NSURLRequest new];
|
||||
NSString *testFilePath = @"path/to/file";
|
||||
[_sut sendRequest:testRequest filePath:testFilePath];
|
||||
[self.sut sendRequest:testRequest filePath:testFilePath];
|
||||
|
||||
OCMVerify([_sut sendUsingURLSessionWithRequest:testRequest filePath:testFilePath]);
|
||||
OCMVerify([self.sut sendUsingURLSessionWithRequest:testRequest filePath:testFilePath]);
|
||||
|
||||
_sut = OCMPartialMock([self newSender]);
|
||||
OCMStub([_sut isURLSessionSupported]).andReturn(NO);
|
||||
self.sut = OCMPartialMock([self newSender]);
|
||||
OCMStub([self.sut isURLSessionSupported]).andReturn(NO);
|
||||
|
||||
[_sut sendRequest:testRequest filePath:testFilePath];
|
||||
[self.sut sendRequest:testRequest filePath:testFilePath];
|
||||
|
||||
OCMVerify([_sut sendUsingURLConnectionWithRequest:testRequest filePath:testFilePath]);
|
||||
OCMVerify([self.sut sendUsingURLConnectionWithRequest:testRequest filePath:testFilePath]);
|
||||
}
|
||||
|
||||
- (void)testSendDataVerifyDataIsGzipped {
|
||||
_sut = OCMPartialMock(_sut);
|
||||
self.sut = OCMPartialMock(self.sut);
|
||||
NSString *testFilePath = @"path/to/file";
|
||||
NSData *testData = [@"test" dataUsingEncoding:NSUTF8StringEncoding];
|
||||
|
||||
[_sut sendData:testData withFilePath:testFilePath];
|
||||
[self.sut sendData:testData withFilePath:testFilePath];
|
||||
|
||||
OCMVerify([_sut sendRequest:[OCMArg checkWithBlock:^BOOL(id obj) {
|
||||
OCMVerify([self.sut sendRequest:[OCMArg checkWithBlock:^BOOL(id obj) {
|
||||
NSMutableURLRequest *request = (NSMutableURLRequest *)obj;
|
||||
NSData *data = request.HTTPBody;
|
||||
if (data) {
|
||||
@@ -99,29 +99,29 @@
|
||||
- (void)testSendUsingURLConnection {
|
||||
|
||||
// setup
|
||||
_sut = OCMPartialMock(_sut);
|
||||
self.sut = OCMPartialMock(self.sut);
|
||||
NSString *testFilePath = @"path/to/file";
|
||||
NSURLRequest *testRequest = [NSURLRequest new];
|
||||
|
||||
// test
|
||||
[_sut sendUsingURLConnectionWithRequest:testRequest filePath:testFilePath];
|
||||
[self.sut sendUsingURLConnectionWithRequest:testRequest filePath:testFilePath];
|
||||
|
||||
//verify
|
||||
OCMVerify([_sut.operationQueue addOperation:(id)anything()]);
|
||||
OCMVerify([self.sut.operationQueue addOperation:(id)anything()]);
|
||||
}
|
||||
|
||||
- (void)testSendUsingURLSession {
|
||||
|
||||
// setup=
|
||||
_sut = OCMPartialMock(_sut);
|
||||
self.sut = OCMPartialMock(self.sut);
|
||||
NSString *testFilePath = @"path/to/file";
|
||||
NSURLRequest *testRequest = [NSURLRequest new];
|
||||
if ([_sut isURLSessionSupported]) {
|
||||
if ([self.sut isURLSessionSupported]) {
|
||||
// test
|
||||
[_sut sendUsingURLSessionWithRequest:testRequest filePath:testFilePath];
|
||||
[self.sut sendUsingURLSessionWithRequest:testRequest filePath:testFilePath];
|
||||
|
||||
//verify
|
||||
OCMVerify([_sut resumeSessionDataTask:(id)anything()]);
|
||||
OCMVerify([self.sut resumeSessionDataTask:(id)anything()]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -129,16 +129,16 @@
|
||||
|
||||
for(NSInteger statusCode = 100; statusCode <= 510; statusCode++){
|
||||
if((statusCode == 429) || (statusCode == 408) || (statusCode == 500) || (statusCode == 503) || (statusCode == 511)) {
|
||||
XCTAssertTrue([_sut shouldDeleteDataWithStatusCode:statusCode] == NO);
|
||||
XCTAssertTrue([self.sut shouldDeleteDataWithStatusCode:statusCode] == NO);
|
||||
}else{
|
||||
XCTAssertTrue([_sut shouldDeleteDataWithStatusCode:statusCode] == YES);
|
||||
XCTAssertTrue([self.sut shouldDeleteDataWithStatusCode:statusCode] == YES);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (void)testRegisterObserversOnInit {
|
||||
self.mockNotificationCenter = mock(NSNotificationCenter.class);
|
||||
_sut = [[BITSender alloc]initWithPersistence:_mockPersistence serverURL:_testServerURL];
|
||||
self.sut = [[BITSender alloc]initWithPersistence:self.mockPersistence serverURL:self.testServerURL];
|
||||
|
||||
[verify((id)self.mockNotificationCenter) addObserverForName:BITPersistenceSuccessNotification object:nil queue:nil usingBlock:(id)anything()];
|
||||
}
|
||||
@@ -146,44 +146,44 @@
|
||||
- (void)testFilesGetDeletedOnPositiveOrUnrecoverableStatusCodes {
|
||||
|
||||
// setup=
|
||||
_sut = OCMPartialMock(_sut);
|
||||
self.sut = OCMPartialMock(self.sut);
|
||||
NSInteger testStatusCode = 999;
|
||||
OCMStub([_sut shouldDeleteDataWithStatusCode:testStatusCode]).andReturn(YES);
|
||||
_sut.runningRequestsCount = 8;
|
||||
OCMStub([self.sut shouldDeleteDataWithStatusCode:testStatusCode]).andReturn(YES);
|
||||
self.sut.runningRequestsCount = 8;
|
||||
NSData *testData = [@"test" dataUsingEncoding:NSUTF8StringEncoding];
|
||||
NSString *testFilePath = @"path/to/file";
|
||||
|
||||
// Stub `sendSavedData` method so there won't be already a new running request when our test request finishes
|
||||
// Otherwise `runningRequestsCount` will already have been decreased by one and been increased by one again.
|
||||
OCMStub([_sut sendSavedData]).andDo(nil);
|
||||
OCMStub([self.sut sendSavedData]).andDo(nil);
|
||||
|
||||
// test
|
||||
[_sut handleResponseWithStatusCode:testStatusCode responseData:testData filePath:testFilePath error:[NSError errorWithDomain:@"Network error" code:503 userInfo:nil]];
|
||||
[self.sut handleResponseWithStatusCode:testStatusCode responseData:testData filePath:testFilePath error:[NSError errorWithDomain:@"Network error" code:503 userInfo:nil]];
|
||||
|
||||
//verify
|
||||
[verify(_mockPersistence) deleteFileAtPath:testFilePath];
|
||||
XCTAssertTrue(_sut.runningRequestsCount == 7);
|
||||
[verify(self.mockPersistence) deleteFileAtPath:testFilePath];
|
||||
XCTAssertTrue(self.sut.runningRequestsCount == 7);
|
||||
}
|
||||
|
||||
- (void)testFilesGetUnblockedOnRecoverableErrorCodes {
|
||||
|
||||
// setup=
|
||||
_sut = OCMPartialMock(_sut);
|
||||
self.sut = OCMPartialMock(self.sut);
|
||||
NSInteger testStatusCode = 999;
|
||||
OCMStub([_sut shouldDeleteDataWithStatusCode:testStatusCode]).andReturn(NO);
|
||||
_sut.runningRequestsCount = 8;
|
||||
OCMStub([self.sut shouldDeleteDataWithStatusCode:testStatusCode]).andReturn(NO);
|
||||
self.sut.runningRequestsCount = 8;
|
||||
NSData *testData = [@"test" dataUsingEncoding:NSUTF8StringEncoding];
|
||||
NSString *testFilePath = @"path/to/file";
|
||||
|
||||
// test
|
||||
[_sut handleResponseWithStatusCode:testStatusCode
|
||||
[self.sut handleResponseWithStatusCode:testStatusCode
|
||||
responseData:testData
|
||||
filePath:testFilePath
|
||||
error:[NSError errorWithDomain:@"Network error" code:503 userInfo:nil]];
|
||||
|
||||
//verify
|
||||
[verify(_mockPersistence) giveBackRequestedFilePath:testFilePath];
|
||||
XCTAssertTrue(_sut.runningRequestsCount == 7);
|
||||
[verify(self.mockPersistence) giveBackRequestedFilePath:testFilePath];
|
||||
XCTAssertTrue(self.sut.runningRequestsCount == 7);
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@@ -22,23 +22,23 @@
|
||||
|
||||
@interface BITStoreUpdateManagerTests : XCTestCase
|
||||
|
||||
@property(nonatomic, strong) BITStoreUpdateManager *storeUpdateManager;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@implementation BITStoreUpdateManagerTests {
|
||||
BITStoreUpdateManager *_storeUpdateManager;
|
||||
}
|
||||
@implementation BITStoreUpdateManagerTests
|
||||
|
||||
- (void)setUp {
|
||||
[super setUp];
|
||||
|
||||
// Set-up code here.
|
||||
_storeUpdateManager = [[BITStoreUpdateManager alloc] initWithAppIdentifier:nil appEnvironment:BITEnvironmentAppStore];
|
||||
self.storeUpdateManager = [[BITStoreUpdateManager alloc] initWithAppIdentifier:nil appEnvironment:BITEnvironmentAppStore];
|
||||
}
|
||||
|
||||
- (void)tearDown {
|
||||
// Tear-down code here.
|
||||
_storeUpdateManager = nil;
|
||||
self.storeUpdateManager = nil;
|
||||
|
||||
[super tearDown];
|
||||
}
|
||||
@@ -59,9 +59,9 @@
|
||||
}
|
||||
|
||||
- (void)startManager {
|
||||
_storeUpdateManager.enableStoreUpdateManager = YES;
|
||||
[_storeUpdateManager startManager];
|
||||
[NSObject cancelPreviousPerformRequestsWithTarget:_storeUpdateManager selector:@selector(checkForUpdateDelayed) object:nil];
|
||||
self.storeUpdateManager.enableStoreUpdateManager = YES;
|
||||
[self.storeUpdateManager startManager];
|
||||
[NSObject cancelPreviousPerformRequestsWithTarget:self.storeUpdateManager selector:@selector(checkForUpdateDelayed) object:nil];
|
||||
}
|
||||
|
||||
|
||||
@@ -69,11 +69,11 @@
|
||||
|
||||
- (void)testUpdateCheckDailyFirstTimeEver {
|
||||
NSUserDefaults *mockUserDefaults = mock([NSUserDefaults class]);
|
||||
_storeUpdateManager.userDefaults = mockUserDefaults;
|
||||
self.storeUpdateManager.userDefaults = mockUserDefaults;
|
||||
|
||||
[self startManager];
|
||||
|
||||
BOOL result = [_storeUpdateManager shouldAutoCheckForUpdates];
|
||||
BOOL result = [self.storeUpdateManager shouldAutoCheckForUpdates];
|
||||
|
||||
XCTAssertTrue(result, @"Checking daily first time ever");
|
||||
}
|
||||
@@ -81,36 +81,36 @@
|
||||
- (void)testUpdateCheckDailyFirstTimeTodayLastCheckPreviousDay {
|
||||
NSUserDefaults *mockUserDefaults = mock([NSUserDefaults class]);
|
||||
[given([mockUserDefaults objectForKey:@"BITStoreUpdateDateOfLastCheck"]) willReturn:[NSDate dateWithTimeIntervalSinceNow:-(60*60*24)]];
|
||||
_storeUpdateManager.userDefaults = mockUserDefaults;
|
||||
_storeUpdateManager.updateSetting = BITStoreUpdateCheckDaily;
|
||||
self.storeUpdateManager.userDefaults = mockUserDefaults;
|
||||
self.storeUpdateManager.updateSetting = BITStoreUpdateCheckDaily;
|
||||
|
||||
[self startManager];
|
||||
|
||||
BOOL result = [_storeUpdateManager shouldAutoCheckForUpdates];
|
||||
BOOL result = [self.storeUpdateManager shouldAutoCheckForUpdates];
|
||||
|
||||
XCTAssertTrue(result, @"Checking daily first time today with last check done previous day");
|
||||
}
|
||||
|
||||
- (void)testUpdateCheckDailySecondTimeOfTheDay {
|
||||
NSUserDefaults *mockUserDefaults = mock([NSUserDefaults class]);
|
||||
_storeUpdateManager.userDefaults = mockUserDefaults;
|
||||
_storeUpdateManager.lastCheck = [NSDate date];
|
||||
self.storeUpdateManager.userDefaults = mockUserDefaults;
|
||||
self.storeUpdateManager.lastCheck = [NSDate date];
|
||||
|
||||
[self startManager];
|
||||
|
||||
BOOL result = [_storeUpdateManager shouldAutoCheckForUpdates];
|
||||
BOOL result = [self.storeUpdateManager shouldAutoCheckForUpdates];
|
||||
|
||||
XCTAssertFalse(result, @"Checking daily second time of the day");
|
||||
}
|
||||
|
||||
- (void)testUpdateCheckWeeklyFirstTimeEver {
|
||||
NSUserDefaults *mockUserDefaults = mock([NSUserDefaults class]);
|
||||
_storeUpdateManager.userDefaults = mockUserDefaults;
|
||||
_storeUpdateManager.updateSetting = BITStoreUpdateCheckWeekly;
|
||||
self.storeUpdateManager.userDefaults = mockUserDefaults;
|
||||
self.storeUpdateManager.updateSetting = BITStoreUpdateCheckWeekly;
|
||||
|
||||
[self startManager];
|
||||
|
||||
BOOL result = [_storeUpdateManager shouldAutoCheckForUpdates];
|
||||
BOOL result = [self.storeUpdateManager shouldAutoCheckForUpdates];
|
||||
|
||||
XCTAssertTrue(result, @"Checking weekly first time ever");
|
||||
}
|
||||
@@ -118,12 +118,12 @@
|
||||
- (void)testUpdateCheckWeeklyFirstTimeTodayLastCheckPreviousWeek {
|
||||
NSUserDefaults *mockUserDefaults = mock([NSUserDefaults class]);
|
||||
[given([mockUserDefaults objectForKey:@"BITStoreUpdateDateOfLastCheck"]) willReturn:[NSDate dateWithTimeIntervalSinceNow:-(60*60*24*7)]];
|
||||
_storeUpdateManager.userDefaults = mockUserDefaults;
|
||||
_storeUpdateManager.updateSetting = BITStoreUpdateCheckWeekly;
|
||||
self.storeUpdateManager.userDefaults = mockUserDefaults;
|
||||
self.storeUpdateManager.updateSetting = BITStoreUpdateCheckWeekly;
|
||||
|
||||
[self startManager];
|
||||
|
||||
BOOL result = [_storeUpdateManager shouldAutoCheckForUpdates];
|
||||
BOOL result = [self.storeUpdateManager shouldAutoCheckForUpdates];
|
||||
|
||||
XCTAssertTrue(result, @"Checking weekly first time after one week");
|
||||
}
|
||||
@@ -131,24 +131,24 @@
|
||||
- (void)testUpdateCheckWeeklyFirstTimeFiveDaysAfterPreviousCheck {
|
||||
NSUserDefaults *mockUserDefaults = mock([NSUserDefaults class]);
|
||||
[given([mockUserDefaults objectForKey:@"BITStoreUpdateDateOfLastCheck"]) willReturn:[NSDate dateWithTimeIntervalSinceNow:-(60*60*24*5)]];
|
||||
_storeUpdateManager.userDefaults = mockUserDefaults;
|
||||
_storeUpdateManager.updateSetting = BITStoreUpdateCheckWeekly;
|
||||
self.storeUpdateManager.userDefaults = mockUserDefaults;
|
||||
self.storeUpdateManager.updateSetting = BITStoreUpdateCheckWeekly;
|
||||
|
||||
[self startManager];
|
||||
|
||||
BOOL result = [_storeUpdateManager shouldAutoCheckForUpdates];
|
||||
BOOL result = [self.storeUpdateManager shouldAutoCheckForUpdates];
|
||||
|
||||
XCTAssertFalse(result, @"Checking weekly first time five days after previous check");
|
||||
}
|
||||
|
||||
- (void)testUpdateCheckManuallyFirstTimeEver {
|
||||
NSUserDefaults *mockUserDefaults = mock([NSUserDefaults class]);
|
||||
_storeUpdateManager.userDefaults = mockUserDefaults;
|
||||
_storeUpdateManager.updateSetting = BITStoreUpdateCheckManually;
|
||||
self.storeUpdateManager.userDefaults = mockUserDefaults;
|
||||
self.storeUpdateManager.updateSetting = BITStoreUpdateCheckManually;
|
||||
|
||||
[self startManager];
|
||||
|
||||
BOOL result = [_storeUpdateManager shouldAutoCheckForUpdates];
|
||||
BOOL result = [self.storeUpdateManager shouldAutoCheckForUpdates];
|
||||
|
||||
XCTAssertFalse(result, @"Checking manually first time ever");
|
||||
}
|
||||
@@ -156,12 +156,12 @@
|
||||
- (void)testUpdateCheckManuallyFirstTimeTodayLastCheckDonePreviousDay {
|
||||
NSUserDefaults *mockUserDefaults = mock([NSUserDefaults class]);
|
||||
[given([mockUserDefaults objectForKey:@"BITStoreUpdateDateOfLastCheck"]) willReturn:[NSDate dateWithTimeIntervalSinceNow:-(60*60*24)]];
|
||||
_storeUpdateManager.userDefaults = mockUserDefaults;
|
||||
_storeUpdateManager.updateSetting = BITStoreUpdateCheckManually;
|
||||
self.storeUpdateManager.userDefaults = mockUserDefaults;
|
||||
self.storeUpdateManager.updateSetting = BITStoreUpdateCheckManually;
|
||||
|
||||
[self startManager];
|
||||
|
||||
BOOL result = [_storeUpdateManager shouldAutoCheckForUpdates];
|
||||
BOOL result = [self.storeUpdateManager shouldAutoCheckForUpdates];
|
||||
|
||||
XCTAssertFalse(result, @"Checking manually first time ever");
|
||||
}
|
||||
@@ -170,28 +170,28 @@
|
||||
#pragma mark - JSON Response Processing
|
||||
|
||||
- (void)testProcessStoreResponseWithEmptyData {
|
||||
BOOL result = [_storeUpdateManager processStoreResponseWithString:nil];
|
||||
BOOL result = [self.storeUpdateManager processStoreResponseWithString:nil];
|
||||
|
||||
XCTAssertFalse(result, @"Empty data was handled correctly");
|
||||
}
|
||||
|
||||
- (void)testProcessStoreResponseWithInvalidData {
|
||||
NSString *invalidString = @"8a@c&)if";
|
||||
BOOL result = [_storeUpdateManager processStoreResponseWithString:invalidString];
|
||||
BOOL result = [self.storeUpdateManager processStoreResponseWithString:invalidString];
|
||||
|
||||
XCTAssertFalse(result, @"Invalid JSON data was handled correctly");
|
||||
}
|
||||
|
||||
- (void)testProcessStoreResponseWithUnknownBundleIdentifier {
|
||||
NSString *dataString = [BITTestHelper jsonFixture:@"StoreBundleIdentifierUnknown"];
|
||||
BOOL result = [_storeUpdateManager processStoreResponseWithString:dataString];
|
||||
BOOL result = [self.storeUpdateManager processStoreResponseWithString:dataString];
|
||||
|
||||
XCTAssertFalse(result, @"Valid but empty json data was handled correctly");
|
||||
}
|
||||
|
||||
- (void)testProcessStoreResponseWithKnownBundleIdentifier {
|
||||
NSString *dataString = [BITTestHelper jsonFixture:@"StoreBundleIdentifierKnown"];
|
||||
BOOL result = [_storeUpdateManager processStoreResponseWithString:dataString];
|
||||
BOOL result = [self.storeUpdateManager processStoreResponseWithString:dataString];
|
||||
|
||||
XCTAssertTrue(result, @"Valid and correct JSON data was handled correctly");
|
||||
}
|
||||
@@ -203,13 +203,13 @@
|
||||
|
||||
- (void)testFirstStartHasNewVersionReturnsFalseWithFirstCheck {
|
||||
NSUserDefaults *mockUserDefaults = mock([NSUserDefaults class]);
|
||||
_storeUpdateManager.userDefaults = mockUserDefaults;
|
||||
self.storeUpdateManager.userDefaults = mockUserDefaults;
|
||||
|
||||
[self startManager];
|
||||
|
||||
NSDictionary *json = [self jsonFromFixture:@"StoreBundleIdentifierKnown"];
|
||||
|
||||
BOOL result = [_storeUpdateManager hasNewVersion:json];
|
||||
BOOL result = [self.storeUpdateManager hasNewVersion:json];
|
||||
|
||||
XCTAssertFalse(result, @"There is no udpate available");
|
||||
}
|
||||
@@ -218,13 +218,13 @@
|
||||
NSUserDefaults *mockUserDefaults = mock([NSUserDefaults class]);
|
||||
[given([mockUserDefaults objectForKey:@"BITStoreUpdateLastStoreVersion"]) willReturn:@"4.1.2"];
|
||||
[given([mockUserDefaults objectForKey:@"BITStoreUpdateLastUUID"]) willReturn:@""];
|
||||
_storeUpdateManager.userDefaults = mockUserDefaults;
|
||||
self.storeUpdateManager.userDefaults = mockUserDefaults;
|
||||
|
||||
[self startManager];
|
||||
|
||||
NSDictionary *json = [self jsonFromFixture:@"StoreBundleIdentifierKnown"];
|
||||
|
||||
BOOL result = [_storeUpdateManager hasNewVersion:json];
|
||||
BOOL result = [self.storeUpdateManager hasNewVersion:json];
|
||||
|
||||
XCTAssertFalse(result, @"There is no udpate available");
|
||||
}
|
||||
@@ -234,13 +234,13 @@
|
||||
NSUserDefaults *mockUserDefaults = mock([NSUserDefaults class]);
|
||||
[given([mockUserDefaults objectForKey:@"BITStoreUpdateLastStoreVersion"]) willReturn:@"4.1.2"];
|
||||
[given([mockUserDefaults objectForKey:@"BITStoreUpdateLastUUID"]) willReturn:@"1"];
|
||||
_storeUpdateManager.userDefaults = mockUserDefaults;
|
||||
self.storeUpdateManager.userDefaults = mockUserDefaults;
|
||||
|
||||
[self startManager];
|
||||
|
||||
NSDictionary *json = [self jsonFromFixture:@"StoreBundleIdentifierKnown"];
|
||||
|
||||
BOOL result = [_storeUpdateManager hasNewVersion:json];
|
||||
BOOL result = [self.storeUpdateManager hasNewVersion:json];
|
||||
|
||||
XCTAssertFalse(result, @"There is no udpate available");
|
||||
}
|
||||
@@ -249,13 +249,13 @@
|
||||
NSUserDefaults *mockUserDefaults = mock([NSUserDefaults class]);
|
||||
[given([mockUserDefaults objectForKey:@"BITStoreUpdateLastStoreVersion"]) willReturn:@"4.1.1"];
|
||||
[given([mockUserDefaults objectForKey:@"BITStoreUpdateLastUUID"]) willReturn:@""];
|
||||
_storeUpdateManager.userDefaults = mockUserDefaults;
|
||||
self.storeUpdateManager.userDefaults = mockUserDefaults;
|
||||
|
||||
[self startManager];
|
||||
|
||||
NSDictionary *json = [self jsonFromFixture:@"StoreBundleIdentifierKnown"];
|
||||
|
||||
BOOL result = [_storeUpdateManager hasNewVersion:json];
|
||||
BOOL result = [self.storeUpdateManager hasNewVersion:json];
|
||||
|
||||
XCTAssertTrue(result, @"There is an udpate available");
|
||||
}
|
||||
@@ -265,13 +265,13 @@
|
||||
NSUserDefaults *mockUserDefaults = mock([NSUserDefaults class]);
|
||||
[given([mockUserDefaults objectForKey:@"BITStoreUpdateLastStoreVersion"]) willReturn:@"4.1.3"];
|
||||
[given([mockUserDefaults objectForKey:@"BITStoreUpdateLastUUID"]) willReturn:@""];
|
||||
_storeUpdateManager.userDefaults = mockUserDefaults;
|
||||
self.storeUpdateManager.userDefaults = mockUserDefaults;
|
||||
|
||||
[self startManager];
|
||||
|
||||
NSDictionary *json = [self jsonFromFixture:@"StoreBundleIdentifierKnown"];
|
||||
|
||||
BOOL result = [_storeUpdateManager hasNewVersion:json];
|
||||
BOOL result = [self.storeUpdateManager hasNewVersion:json];
|
||||
|
||||
XCTAssertFalse(result, @"There is no udpate available");
|
||||
}
|
||||
@@ -281,13 +281,13 @@
|
||||
[given([mockUserDefaults objectForKey:@"BITStoreUpdateLastStoreVersion"]) willReturn:@"4.1.1"];
|
||||
[given([mockUserDefaults objectForKey:@"BITStoreUpdateLastUUID"]) willReturn:@""];
|
||||
[given([mockUserDefaults objectForKey:@"BITStoreUpdateIgnoredVersion"]) willReturn:@"4.1.2"];
|
||||
_storeUpdateManager.userDefaults = mockUserDefaults;
|
||||
self.storeUpdateManager.userDefaults = mockUserDefaults;
|
||||
|
||||
[self startManager];
|
||||
|
||||
NSDictionary *json = [self jsonFromFixture:@"StoreBundleIdentifierKnown"];
|
||||
|
||||
BOOL result = [_storeUpdateManager hasNewVersion:json];
|
||||
BOOL result = [self.storeUpdateManager hasNewVersion:json];
|
||||
|
||||
XCTAssertFalse(result, @"The newer version is being ignored");
|
||||
}
|
||||
@@ -297,13 +297,13 @@
|
||||
[given([mockUserDefaults objectForKey:@"BITStoreUpdateLastStoreVersion"]) willReturn:@"4.1.1"];
|
||||
[given([mockUserDefaults objectForKey:@"BITStoreUpdateLastUUID"]) willReturn:@""];
|
||||
[given([mockUserDefaults objectForKey:@"BITStoreUpdateIgnoredVersion"]) willReturn:@"4.1.1"];
|
||||
_storeUpdateManager.userDefaults = mockUserDefaults;
|
||||
self.storeUpdateManager.userDefaults = mockUserDefaults;
|
||||
|
||||
[self startManager];
|
||||
|
||||
NSDictionary *json = [self jsonFromFixture:@"StoreBundleIdentifierKnown"];
|
||||
|
||||
BOOL result = [_storeUpdateManager hasNewVersion:json];
|
||||
BOOL result = [self.storeUpdateManager hasNewVersion:json];
|
||||
|
||||
XCTAssertTrue(result, @"The newer version is not ignored");
|
||||
}
|
||||
|
||||
@@ -13,12 +13,12 @@
|
||||
|
||||
@interface BITTelemetryContextTests : XCTestCase
|
||||
|
||||
@property(nonatomic, strong) BITTelemetryContext *sut;
|
||||
@property(nonatomic, strong) BITPersistence *mockPersistence;
|
||||
|
||||
@end
|
||||
|
||||
@implementation BITTelemetryContextTests {
|
||||
BITTelemetryContext *_sut;
|
||||
BITPersistence *_mockPersistence;
|
||||
}
|
||||
@implementation BITTelemetryContextTests
|
||||
|
||||
- (void)setUp {
|
||||
[super setUp];
|
||||
@@ -31,25 +31,25 @@
|
||||
}
|
||||
|
||||
- (void)testThatContextObjectsNotNil {
|
||||
XCTAssertNotNil(_sut.device);
|
||||
XCTAssertNotNil(_sut.internal);
|
||||
XCTAssertNotNil(_sut.application);
|
||||
XCTAssertNotNil(_sut.session);
|
||||
XCTAssertNotNil(_sut.user);
|
||||
XCTAssertNotNil(_sut.appIdentifier);
|
||||
XCTAssertNotNil(self.sut.device);
|
||||
XCTAssertNotNil(self.sut.internal);
|
||||
XCTAssertNotNil(self.sut.application);
|
||||
XCTAssertNotNil(self.sut.session);
|
||||
XCTAssertNotNil(self.sut.user);
|
||||
XCTAssertNotNil(self.sut.appIdentifier);
|
||||
}
|
||||
|
||||
- (void)testUserMetaDataGetsLoadedOnInit {
|
||||
[self initDependencies];
|
||||
|
||||
[verify(_mockPersistence) metaData];
|
||||
[verify(self.mockPersistence) metaData];
|
||||
}
|
||||
|
||||
#ifndef CI
|
||||
- (void)testContextDictionaryPerformance {
|
||||
[self measureBlock:^{
|
||||
for (int i = 0; i < 1000; ++i) {
|
||||
[_sut contextDictionary];
|
||||
[self.sut contextDictionary];
|
||||
}
|
||||
}];
|
||||
}
|
||||
@@ -58,8 +58,8 @@
|
||||
#pragma mark - Setup helpers
|
||||
|
||||
- (void)initDependencies {
|
||||
_mockPersistence = mock(BITPersistence.class);
|
||||
_sut = [[BITTelemetryContext alloc] initWithAppIdentifier:@"123" persistence:_mockPersistence];
|
||||
self.mockPersistence = mock(BITPersistence.class);
|
||||
self.sut = [[BITTelemetryContext alloc] initWithAppIdentifier:@"123" persistence:self.mockPersistence];
|
||||
}
|
||||
|
||||
-(void)wait {
|
||||
|
||||
Reference in New Issue
Block a user