mirror of https://github.com/oxen-io/session-ios
				
				
				
			
			You cannot select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
	
	
		
			112 lines
		
	
	
		
			4.8 KiB
		
	
	
	
		
			Objective-C
		
	
			
		
		
	
	
			112 lines
		
	
	
		
			4.8 KiB
		
	
	
	
		
			Objective-C
		
	
//
 | 
						|
//  Copyright (c) 2018 Open Whisper Systems. All rights reserved.
 | 
						|
//
 | 
						|
 | 
						|
#import "TSOutgoingMessage.h"
 | 
						|
#import "OWSPrimaryStorage.h"
 | 
						|
#import "SSKBaseTestObjC.h"
 | 
						|
#import "TSContactThread.h"
 | 
						|
 | 
						|
NS_ASSUME_NONNULL_BEGIN
 | 
						|
 | 
						|
@interface TSOutgoingMessageTest : SSKBaseTestObjC
 | 
						|
 | 
						|
@property (nonatomic) TSContactThread *thread;
 | 
						|
 | 
						|
@end
 | 
						|
 | 
						|
@implementation TSOutgoingMessageTest
 | 
						|
 | 
						|
#ifdef BROKEN_TESTS
 | 
						|
 | 
						|
- (NSString *)contactId
 | 
						|
{
 | 
						|
    return @"fake-thread-id";
 | 
						|
}
 | 
						|
 | 
						|
- (void)setUp
 | 
						|
{
 | 
						|
    [super setUp];
 | 
						|
    self.thread = [[TSContactThread alloc] initWithUniqueId:self.contactId];
 | 
						|
}
 | 
						|
 | 
						|
- (void)testShouldNotStartExpireTimerWithMessageThatDoesNotExpire
 | 
						|
{
 | 
						|
    TSOutgoingMessage *message =
 | 
						|
        [[TSOutgoingMessage alloc] initOutgoingMessageWithTimestamp:100
 | 
						|
                                                           inThread:self.thread
 | 
						|
                                                        messageBody:nil
 | 
						|
                                                      attachmentIds:[NSMutableArray new]
 | 
						|
                                                   expiresInSeconds:0
 | 
						|
                                                    expireStartedAt:0
 | 
						|
                                                     isVoiceMessage:NO
 | 
						|
                                                   groupMetaMessage:TSGroupMetaMessageUnspecified
 | 
						|
                                                      quotedMessage:nil
 | 
						|
                                                       contactShare:nil];
 | 
						|
    [self readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
 | 
						|
        XCTAssertFalse([message shouldStartExpireTimerWithTransaction:transaction]);
 | 
						|
    }];
 | 
						|
}
 | 
						|
 | 
						|
- (void)testShouldStartExpireTimerWithSentMessage
 | 
						|
{
 | 
						|
    TSOutgoingMessage *message =
 | 
						|
        [[TSOutgoingMessage alloc] initOutgoingMessageWithTimestamp:100
 | 
						|
                                                           inThread:self.thread
 | 
						|
                                                        messageBody:nil
 | 
						|
                                                      attachmentIds:[NSMutableArray new]
 | 
						|
                                                   expiresInSeconds:10
 | 
						|
                                                    expireStartedAt:0
 | 
						|
                                                     isVoiceMessage:NO
 | 
						|
                                                   groupMetaMessage:TSGroupMetaMessageUnspecified
 | 
						|
                                                      quotedMessage:nil
 | 
						|
                                                       contactShare:nil];
 | 
						|
    [self readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
 | 
						|
        [message updateWithSentRecipient:self.contactId wasSentByUD:NO transaction:transaction];
 | 
						|
        XCTAssertTrue([message shouldStartExpireTimerWithTransaction:transaction]);
 | 
						|
    }];
 | 
						|
}
 | 
						|
 | 
						|
- (void)testShouldNotStartExpireTimerWithUnsentMessage
 | 
						|
{
 | 
						|
    TSOutgoingMessage *message =
 | 
						|
        [[TSOutgoingMessage alloc] initOutgoingMessageWithTimestamp:100
 | 
						|
                                                           inThread:self.thread
 | 
						|
                                                        messageBody:nil
 | 
						|
                                                      attachmentIds:[NSMutableArray new]
 | 
						|
                                                   expiresInSeconds:10
 | 
						|
                                                    expireStartedAt:0
 | 
						|
                                                     isVoiceMessage:NO
 | 
						|
                                                   groupMetaMessage:TSGroupMetaMessageUnspecified
 | 
						|
                                                      quotedMessage:nil
 | 
						|
                                                       contactShare:nil];
 | 
						|
    [self readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
 | 
						|
        XCTAssertFalse([message shouldStartExpireTimerWithTransaction:transaction]);
 | 
						|
    }];
 | 
						|
}
 | 
						|
 | 
						|
- (void)testShouldNotStartExpireTimerWithAttemptingOutMessage
 | 
						|
{
 | 
						|
    TSOutgoingMessage *message =
 | 
						|
        [[TSOutgoingMessage alloc] initOutgoingMessageWithTimestamp:100
 | 
						|
                                                           inThread:self.thread
 | 
						|
                                                        messageBody:nil
 | 
						|
                                                      attachmentIds:[NSMutableArray new]
 | 
						|
                                                   expiresInSeconds:10
 | 
						|
                                                    expireStartedAt:0
 | 
						|
                                                     isVoiceMessage:NO
 | 
						|
                                                   groupMetaMessage:TSGroupMetaMessageUnspecified
 | 
						|
                                                      quotedMessage:nil
 | 
						|
                                                       contactShare:nil];
 | 
						|
    [self readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
 | 
						|
        [message updateWithMarkingAllUnsentRecipientsAsSendingWithTransaction:transaction];
 | 
						|
        XCTAssertFalse([message shouldStartExpireTimerWithTransaction:transaction]);
 | 
						|
    }];
 | 
						|
}
 | 
						|
 | 
						|
#endif
 | 
						|
 | 
						|
@end
 | 
						|
 | 
						|
NS_ASSUME_NONNULL_END
 |