Kateryna Kostiuk | a23348e | 2023-03-09 14:21:55 -0500 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (C) 2023 Savoir-faire Linux Inc. |
| 3 | * |
| 4 | * Author: Kateryna Kostiuk <kateryna.kostiuk@savoirfairelinux.com> |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; either version 3 of the License, or |
| 9 | * (at your option) any later version. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program; if not, write to the Free Software |
| 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 19 | */ |
| 20 | |
| 21 | import XCTest |
| 22 | @testable import Ring |
| 23 | |
| 24 | final class ContactUtilsTests: XCTestCase { |
| 25 | |
| 26 | override func setUpWithError() throws { |
| 27 | try super.setUpWithError() |
| 28 | } |
| 29 | |
| 30 | override func tearDownWithError() throws { |
| 31 | try super.tearDownWithError() |
| 32 | } |
| 33 | |
| 34 | func testGetFinalName_FromHashOnly() { |
| 35 | let finalName = ContactsUtils.getFinalNameFrom(registeredName: "", profileName: "", hash: jamiId1) |
| 36 | XCTAssertEqual(finalName, jamiId1) |
| 37 | } |
| 38 | |
| 39 | func testGetFinalName_FromHashAndAlias() { |
| 40 | let finalName = ContactsUtils.getFinalNameFrom(registeredName: "", profileName: profileName1, hash: jamiId1) |
| 41 | XCTAssertEqual(finalName, profileName1) |
| 42 | } |
| 43 | |
| 44 | func testGetFinalName_FromHashAndRegisteredName() { |
| 45 | let finalName = ContactsUtils.getFinalNameFrom(registeredName: registeredName1, profileName: "", hash: jamiId1) |
| 46 | XCTAssertEqual(finalName, registeredName1) |
| 47 | } |
| 48 | |
| 49 | func testGetFinalName_FromHashAndRegisteredNameAndAlias() { |
| 50 | let finalName = ContactsUtils.getFinalNameFrom(registeredName: registeredName1, profileName: profileName1, hash: jamiId1) |
| 51 | XCTAssertEqual(finalName, profileName1) |
| 52 | } |
| 53 | |
| 54 | func testDesirealizeuserDetails() { |
| 55 | let userName = "username" |
| 56 | let firstName = "firstName" |
| 57 | let lastName = "lastName" |
| 58 | let organization = "organization" |
| 59 | let jamiId = "jamiId" |
| 60 | let profilePicture = "profilePicture" |
| 61 | let dictionary = ["username": userName, |
| 62 | "firstName": firstName, |
| 63 | "lastName": lastName, |
| 64 | "organization": organization, |
| 65 | "jamiId": jamiId, |
| 66 | "profilePicture": profilePicture] |
| 67 | let imageData = NSData(base64Encoded: profilePicture, options: NSData.Base64DecodingOptions.ignoreUnknownCharacters) as Data? |
| 68 | let userDetails = ContactsUtils.deserializeUser(dictionary: dictionary) |
| 69 | XCTAssertEqual(userDetails?.username, userName) |
| 70 | XCTAssertEqual(userDetails?.firstName, firstName) |
| 71 | XCTAssertEqual(userDetails?.lastName, lastName) |
| 72 | XCTAssertEqual(userDetails?.organization, organization) |
| 73 | XCTAssertEqual(userDetails?.jamiId, jamiId) |
| 74 | XCTAssertEqual(userDetails?.profilePicture, imageData) |
| 75 | } |
| 76 | |
| 77 | } |