From 1adc5ce11e1540a35b176081b04a5b901d6fbbd0 Mon Sep 17 00:00:00 2001 From: Mikunj Date: Mon, 4 May 2020 10:12:00 +1000 Subject: [PATCH] Finish up migration test. --- ...K001UpdateFriendRequestStatusStorage.swift | 2 + ...UpdateFriendRequestStatusStorageTest.swift | 38 +++++++++++++++++++ SignalMessaging/profiles/OWSProfileManager.h | 1 - .../src/Protocols/ProfileManagerProtocol.h | 2 + .../src/TestUtils/OWSFakeProfileManager.m | 5 +++ 5 files changed, 47 insertions(+), 1 deletion(-) diff --git a/SignalMessaging/Loki/Migrations/LK001UpdateFriendRequestStatusStorage.swift b/SignalMessaging/Loki/Migrations/LK001UpdateFriendRequestStatusStorage.swift index 9ef49314a..ff266bf87 100644 --- a/SignalMessaging/Loki/Migrations/LK001UpdateFriendRequestStatusStorage.swift +++ b/SignalMessaging/Loki/Migrations/LK001UpdateFriendRequestStatusStorage.swift @@ -36,6 +36,8 @@ public class LK001UpdateFriendRequestStatusStorage: OWSDatabaseMigration { OWSPrimaryStorage.shared().setFriendRequestStatus(friendRequestStatus, for: thread.contactIdentifier(), transaction: transaction) } } + + completion() } } diff --git a/SignalMessaging/Loki/Migrations/LK001UpdateFriendRequestStatusStorageTest.swift b/SignalMessaging/Loki/Migrations/LK001UpdateFriendRequestStatusStorageTest.swift index 10a3a01f4..4699fc590 100644 --- a/SignalMessaging/Loki/Migrations/LK001UpdateFriendRequestStatusStorageTest.swift +++ b/SignalMessaging/Loki/Migrations/LK001UpdateFriendRequestStatusStorageTest.swift @@ -23,6 +23,44 @@ class LK001UpdateFriendRequestStatusStorageTest : XCTestCase { } func test_shouldMigrateFriendRequestStatusCorrectly() { + typealias ThreadFriendRequestStatus = NSInteger + let friendRequestMappings: [ThreadFriendRequestStatus: LKFriendRequestStatus] = [ + 0: .none, + 1: .requestSending, + 2: .requestSent, + 3: .requestReceived, + 4: .friends, + 5: .requestExpired + ]; + + var hexEncodedPublicKeyMapping: [String: ThreadFriendRequestStatus] = [:] + for (threadFriendRequestStatus, _) in friendRequestMappings { + let hexEncodedPublicKey = Curve25519.generateKeyPair().hexEncodedPublicKey + hexEncodedPublicKeyMapping[hexEncodedPublicKey] = threadFriendRequestStatus + } + + storage.dbReadWriteConnection.readWrite { transaction in + for (hexEncodedPublicKey, friendRequestStatus) in hexEncodedPublicKeyMapping { + let thread = TSContactThread.getOrCreateThread(withContactId: hexEncodedPublicKey, transaction: transaction) + thread.friendRequestStatus = friendRequestStatus + thread.save(with: transaction) + } + } + + // Wait for migration to complete + let migration = self.expectation(description: "Migration") + LK001UpdateFriendRequestStatusStorage().runUp { + migration.fulfill() + } + self.wait(for: [migration], timeout: 5.0) + + storage.dbReadWriteConnection.readWrite { transaction in + for (hexEncodedPublicKey, threadFriendRequestStatus) in hexEncodedPublicKeyMapping { + let expectedFriendRequestStatus = friendRequestMappings[threadFriendRequestStatus]! + let friendRequestStatus = self.storage.getFriendRequestStatus(for: hexEncodedPublicKey, transaction: transaction) + XCTAssertEqual(friendRequestStatus, expectedFriendRequestStatus, "Expected friend request status \(friendRequestStatus.rawValue) to match \(expectedFriendRequestStatus.rawValue)") + } + } } } diff --git a/SignalMessaging/profiles/OWSProfileManager.h b/SignalMessaging/profiles/OWSProfileManager.h index f187fc453..0dd3a97b9 100644 --- a/SignalMessaging/profiles/OWSProfileManager.h +++ b/SignalMessaging/profiles/OWSProfileManager.h @@ -40,7 +40,6 @@ extern const NSUInteger kOWSProfileManager_MaxAvatarDiameter; - (nullable UIImage *)localProfileAvatarImage; - (nullable NSData *)localProfileAvatarData; - (nullable NSString *)profilePictureURL; -- (void)ensureLocalProfileCached; // This method is used to update the "local profile" state on the client // and the service. Client state is only updated if service state is diff --git a/SignalServiceKit/src/Protocols/ProfileManagerProtocol.h b/SignalServiceKit/src/Protocols/ProfileManagerProtocol.h index d7cb222a4..3bc40c054 100644 --- a/SignalServiceKit/src/Protocols/ProfileManagerProtocol.h +++ b/SignalServiceKit/src/Protocols/ProfileManagerProtocol.h @@ -35,6 +35,8 @@ NS_ASSUME_NONNULL_BEGIN - (void)updateProfileForContactWithID:(NSString *)contactID displayName:(NSString *)displayName with:(YapDatabaseReadWriteTransaction *)transaction; - (void)updateServiceWithProfileName:(nullable NSString *)localProfileName avatarURL:(nullable NSString *)avatarURL; +- (void)ensureLocalProfileCached; + @end NS_ASSUME_NONNULL_END diff --git a/SignalServiceKit/src/TestUtils/OWSFakeProfileManager.m b/SignalServiceKit/src/TestUtils/OWSFakeProfileManager.m index ac8bd1446..9de2bbcde 100644 --- a/SignalServiceKit/src/TestUtils/OWSFakeProfileManager.m +++ b/SignalServiceKit/src/TestUtils/OWSFakeProfileManager.m @@ -90,6 +90,11 @@ NS_ASSUME_NONNULL_BEGIN // Do nothing. } +- (void)ensureLocalProfileCached +{ + // Do nothing. +} + @end #endif