Commit 37f3359d authored by Romain Bertozzi's avatar Romain Bertozzi

accountModelHelper: add unit tests

This patch adds tests for the accountModelHelper.
It will help to verify continuously the correct behaviour of this
helper class.

Tuleap: #1542
Change-Id: I3e7413ad756632334de3ef35515b24a24033f798
Reviewed-by: default avatarSilbino Gonçalves Matado <silbino.gmatado@savoirfairelinux.com>
parent de1d0386
......@@ -102,6 +102,12 @@
04399B151D1C341A00E99CD9 /* libyaml-cpp.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 04399AE31D1C341A00E99CD9 /* libyaml-cpp.a */; };
5516C29F1E71CEFF009D3D2D /* AccountModelHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5516C29E1E71CEFF009D3D2D /* AccountModelHelper.swift */; };
56AC64D51E7C7F4000EA1AA9 /* WelcomeViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56AC64D41E7C7F4000EA1AA9 /* WelcomeViewController.swift */; };
5557FD4A1E81AE850043E394 /* AccountModelHelperTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5557FD491E81AE850043E394 /* AccountModelHelperTests.swift */; };
5557FD4B1E81AECF0043E394 /* AccountModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 02B22DFA1DF755BB000358C9 /* AccountModel.swift */; };
5557FD4C1E81AF840043E394 /* AccountConfigModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 02DD80C71E1EAD70009A3510 /* AccountConfigModel.swift */; };
5557FD4D1E81AFF50043E394 /* ConfigKeyModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 02DD80CC1E1EB2E4009A3510 /* ConfigKeyModel.swift */; };
5557FD4E1E81B1F20043E394 /* AccountModelHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5516C29E1E71CEFF009D3D2D /* AccountModelHelper.swift */; };
5557FD4F1E81B2990043E394 /* AccountCredentialsModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 02DD80C91E1EAF1A009A3510 /* AccountCredentialsModel.swift */; };
/* End PBXBuildFile section */
/* Begin PBXContainerItemProxy section */
......@@ -231,6 +237,7 @@
04399AE31D1C341A00E99CD9 /* libyaml-cpp.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = "libyaml-cpp.a"; path = "../fat/lib/libyaml-cpp.a"; sourceTree = "<group>"; };
5516C29E1E71CEFF009D3D2D /* AccountModelHelper.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = AccountModelHelper.swift; path = Account/AccountModelHelper.swift; sourceTree = "<group>"; };
56AC64D41E7C7F4000EA1AA9 /* WelcomeViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = WelcomeViewController.swift; sourceTree = "<group>"; };
5557FD491E81AE850043E394 /* AccountModelHelperTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AccountModelHelperTests.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
......@@ -486,6 +493,7 @@
04399A0F1D1C2D9D00E99CD9 /* RingTests */ = {
isa = PBXGroup;
children = (
5557FD491E81AE850043E394 /* AccountModelHelperTests.swift */,
024B612B1DF7654F00C4F9DE /* DaemonServiceTests.swift */,
029CE9D61E1D8C860000C8E1 /* ServiceEventTests.swift */,
028568301DF610A9003A8D8D /* RingTests-Bridging-Header.h */,
......@@ -763,9 +771,15 @@
buildActionMask = 2147483647;
files = (
024B61311DF7656A00C4F9DE /* FixtureFailInitDRingAdapter.mm in Sources */,
5557FD4E1E81B1F20043E394 /* AccountModelHelper.swift in Sources */,
5557FD4F1E81B2990043E394 /* AccountCredentialsModel.swift in Sources */,
5557FD4B1E81AECF0043E394 /* AccountModel.swift in Sources */,
5557FD4A1E81AE850043E394 /* AccountModelHelperTests.swift in Sources */,
5557FD4C1E81AF840043E394 /* AccountConfigModel.swift in Sources */,
024B61331DF765CA00C4F9DE /* DaemonService.swift in Sources */,
04399A111D1C2D9D00E99CD9 /* RingTests.swift in Sources */,
029CE9D71E1D8C860000C8E1 /* ServiceEventTests.swift in Sources */,
5557FD4D1E81AFF50043E394 /* ConfigKeyModel.swift in Sources */,
024B612C1DF7654F00C4F9DE /* DaemonServiceTests.swift in Sources */,
029CE9D81E1D8DC70000C8E1 /* ServiceEvent.swift in Sources */,
024B61321DF7656A00C4F9DE /* FixtureFailStartDRingAdapter.mm in Sources */,
......
/*
* Copyright (C) 2017 Savoir-faire Linux Inc.
*
* Author: Romain Bertozzi <romain.bertozzi@savoirfairelinux.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
import XCTest
/**
A test class designed to validate that the AccountModel helper runs as expected.
*/
class AccountModelHelperTests: XCTestCase {
/// The account used for the tests.
var account: AccountModel?
override func setUp() {
super.setUp()
//~ Dummy account
account = AccountModel(withAccountId: "identifier")
}
override func tearDown() {
// Put teardown code here. This method is called after the invocation of each test method in the class.
super.tearDown()
}
/**
Tests that the SIP account type is properly detected.
*/
func testIsSip() {
var data = Dictionary<String, String>()
data[ConfigKey.AccountType.rawValue] = AccountType.SIP.rawValue
var config = AccountConfigModel(withDetails: data)
account?.details = config
var helper = AccountModelHelper(withAccount: account!)
XCTAssertTrue(helper.isAccountSip())
data[ConfigKey.AccountType.rawValue] = AccountType.Ring.rawValue
config = AccountConfigModel(withDetails: data)
account?.details = config
helper = AccountModelHelper(withAccount: account!)
XCTAssertFalse(helper.isAccountSip())
}
/**
Tests that the Ring account type is properly detected.
*/
func testIsRing() {
var data = Dictionary<String, String>()
data[ConfigKey.AccountType.rawValue] = AccountType.Ring.rawValue
var config = AccountConfigModel(withDetails: data)
account?.details = config
var helper = AccountModelHelper(withAccount: account!)
XCTAssertTrue(helper.isAccountRing())
data[ConfigKey.AccountType.rawValue] = AccountType.SIP.rawValue
config = AccountConfigModel(withDetails: data)
account?.details = config
helper = AccountModelHelper(withAccount: account!)
XCTAssertFalse(helper.isAccountRing())
}
/**
Tests that the account's enabled state is properly detected.
*/
func testIsEnabled() {
var data = Dictionary<String, String>()
data[ConfigKey.AccountEnable.rawValue] = "true"
var config = AccountConfigModel(withDetails: data)
account?.details = config
var helper = AccountModelHelper(withAccount: account!)
XCTAssertTrue(helper.isEnabled())
data[ConfigKey.AccountEnable.rawValue] = "false"
config = AccountConfigModel(withDetails: data)
account?.details = config
helper = AccountModelHelper(withAccount: account!)
XCTAssertFalse(helper.isEnabled())
data.removeValue(forKey: ConfigKey.AccountEnable.rawValue)
config = AccountConfigModel(withDetails: data)
account?.details = config
helper = AccountModelHelper(withAccount: account!)
XCTAssertFalse(helper.isEnabled())
}
/**
Tests that the account's registration state is properly detected.
*/
func testRegistrationState() {
var data = Dictionary<String, String>()
data[ConfigKey.AccountRegistrationStatus.rawValue] = AccountState.Registered.rawValue
var config = AccountConfigModel(withDetails: data)
account?.volatileDetails = config
var helper = AccountModelHelper(withAccount: account!)
XCTAssertEqual(helper.getRegistrationState(), AccountState.Registered.rawValue)
data[ConfigKey.AccountRegistrationStatus.rawValue] = AccountState.Error.rawValue
config = AccountConfigModel(withDetails: data)
account?.volatileDetails = config
helper = AccountModelHelper(withAccount: account!)
XCTAssertNotEqual(helper.getRegistrationState(), AccountState.Registered.rawValue)
}
/**
Tests that the account's error state is properly detected.
*/
func testIsInError() {
var data = Dictionary<String, String>()
data[ConfigKey.AccountRegistrationStatus.rawValue] = AccountState.Registered.rawValue
var config = AccountConfigModel(withDetails: data)
account?.volatileDetails = config
var helper = AccountModelHelper(withAccount: account!)
XCTAssertFalse(helper.isInError());
data[ConfigKey.AccountRegistrationStatus.rawValue] = AccountState.Error.rawValue
config = AccountConfigModel(withDetails: data)
account?.volatileDetails = config
helper = AccountModelHelper(withAccount: account!)
XCTAssertTrue(helper.isInError())
}
/**
Tests that the account's credentials are properly inserted and retrieved.
*/
func testCredentials() {
let username = "username"
let password = "password"
let realm = "realm"
var credentials = Array<Dictionary<String, String>>()
var credential = Dictionary<String, String>()
credential[ConfigKey.AccountUsername.rawValue] = username
credential[ConfigKey.AccountPassword.rawValue] = password
credential[ConfigKey.AccountRealm.rawValue] = realm
credentials.append(credential)
var helper = AccountModelHelper(withAccount: account!)
var modifiedAccount = helper.setCredentials(credentials)
XCTAssertEqual(modifiedAccount.credentialDetails.count, 1)
XCTAssertEqual(modifiedAccount.credentialDetails[0].username, username)
XCTAssertEqual(modifiedAccount.credentialDetails[0].password, password)
XCTAssertEqual(modifiedAccount.credentialDetails[0].realm, realm)
modifiedAccount = helper.setCredentials(nil)
XCTAssertEqual(modifiedAccount.credentialDetails.count, 0)
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment