NetNewsWire/Frameworks/Account/AccountTests/AccountCredentialsTest.swift

97 lines
2.1 KiB
Swift
Raw Normal View History

//
// AccountCredentialsTest.swift
// AccountTests
//
// Created by Maurice Parker on 5/4/19.
// Copyright © 2019 Ranchero Software, LLC. All rights reserved.
//
import XCTest
2019-05-04 22:14:49 +02:00
import RSWeb
@testable import Account
class AccountCredentialsTest: XCTestCase {
private var account: Account!
override func setUp() {
account = TestAccountManager.shared.createAccount(type: .feedbin, transport: NilTransport())
}
override func tearDown() {
TestAccountManager.shared.deleteAccount(account)
}
2019-05-04 22:14:49 +02:00
func testCreateRetrieveDelete() {
2019-05-04 22:14:49 +02:00
// Make sure any left over from failed tests are gone
do {
2019-05-05 10:25:21 +02:00
try account.removeBasicCredentials()
2019-05-04 22:14:49 +02:00
} catch {
XCTFail(error.localizedDescription)
}
2019-05-05 10:25:21 +02:00
var credentials: Credentials? = Credentials.basic(username: "maurice", password: "hardpasswd")
2019-05-04 22:14:49 +02:00
// Store the credentials
do {
try account.storeCredentials(credentials!)
} catch {
XCTFail(error.localizedDescription)
}
// Retrieve them
credentials = nil
do {
2019-05-05 10:25:21 +02:00
credentials = try account.retrieveBasicCredentials()
2019-05-04 22:14:49 +02:00
} catch {
XCTFail(error.localizedDescription)
}
2019-05-05 10:25:21 +02:00
switch credentials! {
case .basic(let username, let password):
XCTAssertEqual("maurice", username)
XCTAssertEqual("hardpasswd", password)
}
2019-05-04 22:14:49 +02:00
// Update them
2019-05-05 10:25:21 +02:00
credentials = Credentials.basic(username: "maurice", password: "easypasswd")
2019-05-04 22:14:49 +02:00
do {
try account.storeCredentials(credentials!)
} catch {
XCTFail(error.localizedDescription)
}
// Retrieve them again
credentials = nil
do {
2019-05-05 10:25:21 +02:00
credentials = try account.retrieveBasicCredentials()
2019-05-04 22:14:49 +02:00
} catch {
XCTFail(error.localizedDescription)
}
2019-05-05 10:25:21 +02:00
switch credentials! {
case .basic(let username, let password):
XCTAssertEqual("maurice", username)
XCTAssertEqual("easypasswd", password)
}
2019-05-04 22:14:49 +02:00
// Delete them
do {
2019-05-05 10:25:21 +02:00
try account.removeBasicCredentials()
2019-05-04 22:14:49 +02:00
} catch {
XCTFail(error.localizedDescription)
}
// Make sure they are gone
do {
2019-05-05 10:25:21 +02:00
try credentials = account.retrieveBasicCredentials()
2019-05-04 22:14:49 +02:00
} catch {
XCTFail(error.localizedDescription)
}
XCTAssertNil(credentials)
}
}