2525
2626#import < XCTest/XCTest.h>
2727#import < UIKit/UIKit.h>
28+ #import < OCMock/OCMock.h>
2829#import < OHHTTPStubs/OHHTTPStubs.h>
2930#import < OHHTTPStubs/OHPathHelpers.h>
3031#import " LeanplumHelper.h"
@@ -46,6 +47,7 @@ @interface Leanplum (Test)
4647
4748+ (NSSet <NSString *> *)parseEnabledCountersFromResponse : (NSDictionary *)response ;
4849+ (NSSet <NSString *> *)parseEnabledFeatureFlagsFromResponse : (NSDictionary *)response ;
50+ + (void )triggerMessageDisplayed : (LPActionContext *)context ;
4951
5052@end
5153
@@ -1781,4 +1783,40 @@ - (void)on_start_response:(BOOL) success
17811783 XCTAssertTrue (success);
17821784}
17831785
1786+ /* *
1787+ * Test that method triggerMessageDisplayed calls user defined callback
1788+ */
1789+ -(void )test_triggerMessageDisplayedCallsCallback
1790+ {
1791+ __block BOOL blockCalled = NO ;
1792+
1793+ NSString *messageID = @" testMessageID" ;
1794+ NSString *messageBody = @" testMessageBody" ;
1795+ NSString *recipientUserID = @" recipientUserID" ;
1796+
1797+ LPActionContext *actionContext = [[LPActionContext alloc ] init ];
1798+ id actionContextMock = OCMPartialMock (actionContext);
1799+
1800+ OCMStub ([actionContextMock messageId ]).andReturn (messageID);
1801+ OCMStub ([actionContextMock args ]).andReturn (@{@" Message" :messageBody});
1802+
1803+ id leanplumMock = OCMClassMock ([Leanplum class ]);
1804+ OCMStub ([leanplumMock userId ]).andReturn (recipientUserID);
1805+
1806+ LeanplumMessageDisplayedCallbackBlock block =
1807+ ^void (LPMessageArchiveData *messageArchiveData) {
1808+ blockCalled = YES ;
1809+ XCTAssertEqual (messageArchiveData.messageID , messageID);
1810+ XCTAssertEqual (messageArchiveData.messageBody , messageBody);
1811+ XCTAssertEqual (messageArchiveData.recipientUserID , recipientUserID);
1812+ NSDate *now = [NSDate date ];
1813+ NSTimeInterval interval = [now timeIntervalSinceDate: messageArchiveData.deliveryDateTime];
1814+ XCTAssertTrue (interval < 1000 );
1815+ };
1816+ [Leanplum onMessageDisplayed: block];
1817+ [Leanplum triggerMessageDisplayed: actionContext];
1818+
1819+ XCTAssertTrue (blockCalled);
1820+ }
1821+
17841822@end
0 commit comments