Introduce some helper methods in TestBase to simplify PasswordTest

This commit is contained in:
Danny Moesch 2018-12-08 18:20:00 +01:00 committed by Bob Sun
parent fa12a6f046
commit e019f6ac9d
2 changed files with 50 additions and 48 deletions

View file

@ -32,7 +32,21 @@ func getPasswordObjectWith(content: String, url: URL? = nil) -> Password {
return Password(name: "password", url: url ?? PASSWORD_URL, plainText: content)
}
func does(_ password: Password, contain field: AdditionField) -> Bool {
func assertDefaults(in password: Password, with passwordString: String, and additions: String,
at file: StaticString = #file, line: UInt = #line) {
let fileContent = (passwordString | additions).data(using: .utf8)
XCTAssertEqual(password.password, passwordString, "Actual passwords do not match.", file: file, line: line)
XCTAssertEqual(password.plainData, fileContent, "Plain data are not equal.", file: file, line: line)
XCTAssertEqual(password.additionsPlainText, additions, "Plain texts are not equal.", file: file, line: line)
XCTAssertEqual(password.otpType, .none, "OTP type is not .none.", file: file, line: line)
}
infix operator : AdditionPrecedence
func (field: AdditionField, password: Password) -> Bool {
return password.getFilteredAdditions().contains(field)
}
infix operator : AdditionPrecedence
func (field: AdditionField, password: Password) -> Bool {
return !(field password)
}