Fix up some more tests.

// FREEBIE
pull/1/head
Michael Kirk 8 years ago
parent 13c5bdb8c5
commit 1fb9fa79df

@ -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 <XCTest/XCTest.h>
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];
}

@ -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];

@ -94,7 +94,10 @@ NS_ASSUME_NONNULL_BEGIN
if (self.shouldSucceed) {
successHandler();
} else {
failureHandler(OWSErrorMakeFailedToSendOutgoingMessageError());
NSError *error = OWSErrorMakeFailedToSendOutgoingMessageError();
[error setIsRetryable:NO];
failureHandler(error);
}
}

@ -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"];

@ -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 {

@ -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<Contact *> * _Nonnull)signalContacts
- (NSArray<Contact *> *)signalContacts
{
return @[];
}
- (NSArray<SignalAccount *> *)signalAccounts
{
return @[];
}

@ -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<ContactsManagerProtocol>)contactsManager
{
NSLog(@"%s", __PRETTY_FUNCTION__);
}

@ -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

@ -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]

Loading…
Cancel
Save