From 1fb9fa79dfefccf2322fba1450455db7238e2bee Mon Sep 17 00:00:00 2001 From: Michael Kirk Date: Sat, 3 Jun 2017 18:29:41 -0700 Subject: [PATCH] Fix up some more tests. // FREEBIE --- tests/Contacts/TSContactThreadTest.m | 7 +++++-- tests/Messages/Interactions/TSMessageTest.m | 16 ++++++++++++++-- tests/Messages/OWSMessageSenderTest.m | 5 ++++- tests/Messages/TSMessagesManagerTest.m | 8 ++++++++ tests/Storage/TSStorageIdentityKeyStoreTests.m | 4 +++- tests/TestSupport/Fakes/OWSFakeContactsManager.m | 12 +++++++++--- .../Fakes/OWSFakeNotificationsManager.m | 7 ++++--- tests/TestSupport/Fakes/OWSUnitTestEnvironment.h | 6 ++++-- tests/TestSupport/Fakes/OWSUnitTestEnvironment.m | 10 +++++++++- 9 files changed, 60 insertions(+), 15 deletions(-) diff --git a/tests/Contacts/TSContactThreadTest.m b/tests/Contacts/TSContactThreadTest.m index 6498cd4d2..4194f06cb 100644 --- a/tests/Contacts/TSContactThreadTest.m +++ b/tests/Contacts/TSContactThreadTest.m @@ -1,8 +1,10 @@ -// Created by Michael Kirk on 11/7/16. -// Copyright © 2016 Open Whisper Systems. All rights reserved. +// +// Copyright (c) 2017 Open Whisper Systems. All rights reserved. +// #import "TSContactThread.h" #import "TSStorageManager+identityKeyStore.h" +#import "OWSUnitTestEnvironment.h" #import NS_ASSUME_NONNULL_BEGIN @@ -17,6 +19,7 @@ NS_ASSUME_NONNULL_BEGIN - (void)setUp { + [OWSUnitTestEnvironment ensureSetup]; self.contactThread = [TSContactThread getOrCreateThreadWithContactId:@"fake-contact-id"]; [self.contactThread.storageManager removeIdentityKeyForRecipient:self.contactThread.contactIdentifier]; } diff --git a/tests/Messages/Interactions/TSMessageTest.m b/tests/Messages/Interactions/TSMessageTest.m index 93bb337b0..e956d485b 100644 --- a/tests/Messages/Interactions/TSMessageTest.m +++ b/tests/Messages/Interactions/TSMessageTest.m @@ -102,10 +102,9 @@ NS_ASSUME_NONNULL_BEGIN XCTAssertEqualObjects(@"📽 ATTACHMENT", actualDescription); } - - (void)testDescriptionWithAudioAttachmentId { - TSAttachment *attachment = [[TSAttachmentStream alloc] initWithContentType:@"audio/mp3" sourceFilename:nil]; + TSAttachment *attachment = [[TSAttachmentStream alloc] initWithContentType:@"audio/mp3" sourceFilename:@"some-file.mp3"]; [attachment save]; TSMessage *message = [[TSMessage alloc] initWithTimestamp:1 @@ -116,6 +115,19 @@ NS_ASSUME_NONNULL_BEGIN XCTAssertEqualObjects(@"📻 ATTACHMENT", actualDescription); } +- (void)testDescriptionWithVoiceMessageAttachmentId +{ + TSAttachment *attachment = [[TSAttachmentStream alloc] initWithContentType:@"audio/mp3" sourceFilename:nil]; + [attachment save]; + + TSMessage *message = [[TSMessage alloc] initWithTimestamp:1 + inThread:self.thread + messageBody:@"My message body" + attachmentIds:@[ attachment.uniqueId ]]; + NSString *actualDescription = [message description]; + XCTAssertEqualObjects(@"🎤 ATTACHMENT_TYPE_VOICE_MESSAGE", actualDescription); +} + - (void)testDescriptionWithUnkownAudioContentType { TSAttachment *attachment = [[TSAttachmentStream alloc] initWithContentType:@"non/sense" sourceFilename:nil]; diff --git a/tests/Messages/OWSMessageSenderTest.m b/tests/Messages/OWSMessageSenderTest.m index 4cdfcb7c0..e61bed24b 100644 --- a/tests/Messages/OWSMessageSenderTest.m +++ b/tests/Messages/OWSMessageSenderTest.m @@ -94,7 +94,10 @@ NS_ASSUME_NONNULL_BEGIN if (self.shouldSucceed) { successHandler(); } else { - failureHandler(OWSErrorMakeFailedToSendOutgoingMessageError()); + NSError *error = OWSErrorMakeFailedToSendOutgoingMessageError(); + [error setIsRetryable:NO]; + + failureHandler(error); } } diff --git a/tests/Messages/TSMessagesManagerTest.m b/tests/Messages/TSMessagesManagerTest.m index 839aad77d..6fbc01a04 100644 --- a/tests/Messages/TSMessagesManagerTest.m +++ b/tests/Messages/TSMessagesManagerTest.m @@ -18,6 +18,7 @@ #import "TSMessagesManager.h" #import "TSNetworkManager.h" #import "TSStorageManager.h" +#import "OWSUnitTestEnvironment.h" NS_ASSUME_NONNULL_BEGIN @@ -57,6 +58,13 @@ NS_ASSUME_NONNULL_BEGIN messageSender:messageSender]; } +- (void)setUp +{ + [super setUp]; + + [OWSUnitTestEnvironment ensureSetup]; +} + - (void)testIncomingSyncContactMessage { XCTestExpectation *messageWasSent = [self expectationWithDescription:@"message was sent"]; diff --git a/tests/Storage/TSStorageIdentityKeyStoreTests.m b/tests/Storage/TSStorageIdentityKeyStoreTests.m index fa34a554f..41b2fdd5d 100644 --- a/tests/Storage/TSStorageIdentityKeyStoreTests.m +++ b/tests/Storage/TSStorageIdentityKeyStoreTests.m @@ -8,6 +8,7 @@ #import "OWSUnitTestEnvironment.h" #import "SecurityUtils.h" #import "TSStorageManager+IdentityKeyStore.h" +#import "OWSRecipientIdentity.h" #import "TSStorageManager.h" #import "TextSecureKitEnv.h" @@ -19,8 +20,9 @@ - (void)setUp { [super setUp]; + [[TSStorageManager sharedManager] purgeCollection:@"TSStorageManagerTrustedKeysCollection"]; - // Put setup code here. This method is called before the invocation of each test method in the class. + [OWSRecipientIdentity removeAllObjectsInCollection]; } - (void)tearDown { diff --git a/tests/TestSupport/Fakes/OWSFakeContactsManager.m b/tests/TestSupport/Fakes/OWSFakeContactsManager.m index 5c587672e..d67e275e9 100644 --- a/tests/TestSupport/Fakes/OWSFakeContactsManager.m +++ b/tests/TestSupport/Fakes/OWSFakeContactsManager.m @@ -1,5 +1,6 @@ -// Created by Michael Kirk on 10/7/16. -// Copyright © 2016 Open Whisper Systems. All rights reserved. +// +// Copyright (c) 2017 Open Whisper Systems. All rights reserved. +// #import "OWSFakeContactsManager.h" @@ -14,7 +15,12 @@ NS_ASSUME_NONNULL_BEGIN return @"Fake name"; } -- (NSArray * _Nonnull)signalContacts +- (NSArray *)signalContacts +{ + return @[]; +} + +- (NSArray *)signalAccounts { return @[]; } diff --git a/tests/TestSupport/Fakes/OWSFakeNotificationsManager.m b/tests/TestSupport/Fakes/OWSFakeNotificationsManager.m index bcc385b70..fd96833c0 100644 --- a/tests/TestSupport/Fakes/OWSFakeNotificationsManager.m +++ b/tests/TestSupport/Fakes/OWSFakeNotificationsManager.m @@ -1,5 +1,6 @@ -// Created by Michael Kirk on 12/18/16. -// Copyright © 2016 Open Whisper Systems. All rights reserved. +// +// Copyright (c) 2017 Open Whisper Systems. All rights reserved. +// #import "OWSFakeNotificationsManager.h" @@ -8,8 +9,8 @@ NS_ASSUME_NONNULL_BEGIN @implementation OWSFakeNotificationsManager - (void)notifyUserForIncomingMessage:(TSIncomingMessage *)incomingMessage - from:(NSString *)name inThread:(TSThread *)thread + contactsManager:(id)contactsManager { NSLog(@"%s", __PRETTY_FUNCTION__); } diff --git a/tests/TestSupport/Fakes/OWSUnitTestEnvironment.h b/tests/TestSupport/Fakes/OWSUnitTestEnvironment.h index aff4171ca..67b49148a 100644 --- a/tests/TestSupport/Fakes/OWSUnitTestEnvironment.h +++ b/tests/TestSupport/Fakes/OWSUnitTestEnvironment.h @@ -1,5 +1,6 @@ -// Created by Michael Kirk on 12/18/16. -// Copyright © 2016 Open Whisper Systems. All rights reserved. +// +// Copyright (c) 2017 Open Whisper Systems. All rights reserved. +// #import "TextSecureKitEnv.h" @@ -7,6 +8,7 @@ NS_ASSUME_NONNULL_BEGIN @interface OWSUnitTestEnvironment : TextSecureKitEnv ++ (void)ensureSetup; - (instancetype)initDefault; @end diff --git a/tests/TestSupport/Fakes/OWSUnitTestEnvironment.m b/tests/TestSupport/Fakes/OWSUnitTestEnvironment.m index 89cab4a36..d04475749 100644 --- a/tests/TestSupport/Fakes/OWSUnitTestEnvironment.m +++ b/tests/TestSupport/Fakes/OWSUnitTestEnvironment.m @@ -13,7 +13,15 @@ NS_ASSUME_NONNULL_BEGIN @implementation OWSUnitTestEnvironment -- (instancetype)init ++ (void)ensureSetup +{ + static dispatch_once_t onceToken; + dispatch_once(&onceToken, ^{ + [self setSharedEnv:[[self alloc] initDefault]]; + }); +} + +- (instancetype)initDefault { return [super initWithCallMessageHandler:[OWSFakeCallMessageHandler new] contactsManager:[OWSFakeContactsManager new]