Skip to content

Commit

Permalink
Merge pull request #2 from lukacs-m/feature/update-of-package-version
Browse files Browse the repository at this point in the history
feat: update package versions
  • Loading branch information
lukacs-m committed Mar 15, 2024
2 parents 82afa78 + 3c7b309 commit a41b93b
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 13 deletions.
4 changes: 2 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ let swiftSettings: [SwiftSetting] = [
let package = Package(
name: "SimpleKeychain",
platforms: [
.iOS(.v15),
.iOS(.v13),
.watchOS(.v9),
.macOS(.v13),
.macOS(.v12),
.tvOS(.v15)
],
products: [
Expand Down
40 changes: 29 additions & 11 deletions Tests/SimpleKeychainTests/SimpleKeychainTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ final class SimpleKeychainTests: XCTestCase {
func test_setAndGetString_ShouldBeValid() async throws {
let key = "testString"
try await sut.set(apiToken, for: key)
let decodedString: String = try await sut.get(key: key)
guard let decodedString: String = try await sut.get(key: key) else {
XCTFail("Should contain a String")
return
}

XCTAssertEqual(decodedString, apiToken)
}
Expand All @@ -19,7 +22,10 @@ final class SimpleKeychainTests: XCTestCase {
let key = "testBoolean"
let value = true
try await sut.set(value, for: key)
let decodedBoolean: Bool = try await sut.get(key: key)
guard let decodedBoolean: Bool = try await sut.get(key: key) else {
XCTFail("Should contain boolean")
return
}

XCTAssertTrue(decodedBoolean)
}
Expand All @@ -28,7 +34,10 @@ final class SimpleKeychainTests: XCTestCase {
let key = "testData"
let data = try JSONEncoder().encode(apiToken)
try await sut.set(data, for: key)
let decodedData: Data = try await sut.get(key: key)
guard let decodedData: Data = try await sut.get(key: key) else {
XCTFail("Should contain data")
return
}
let decodedToken = try JSONDecoder().decode(String.self, from: decodedData)

XCTAssertEqual(decodedToken, apiToken)
Expand All @@ -41,20 +50,23 @@ final class SimpleKeychainTests: XCTestCase {
let key = "testCodable"
let value = Test(title: "plop")
try await sut.set(value, for: key)
let decodedCodable: Test = try await sut.get(key: key)
let decodedCodable: Test? = try await sut.get(key: key)

XCTAssertEqual(decodedCodable.title, "plop")
XCTAssertEqual(decodedCodable?.title, "plop")
}

func test_deleteValue_ShouldBeValid() async throws {
let key = "testDeletion"
try await sut.set(apiToken, for: key)
let newToken: String = try await sut.get(key: key)

guard let newToken: String = try await sut.get(key: key) else {
XCTFail("Should contain a string")
return
}

XCTAssertEqual(newToken, apiToken)
try await sut.delete(key)
do {
try await sut.get(key: key) as String
try await sut.get(key: key) as String?
XCTFail("Error needs to be thrown")
} catch {
XCTAssertEqual(error as! SimpleKeychainError, SimpleKeychainError.itemNotFound)
Expand All @@ -65,18 +77,24 @@ final class SimpleKeychainTests: XCTestCase {
func test_updateValueForKey_ShouldBeValid() async throws {
let key = "testUpdate"
try await sut.set(apiToken, for: key)
let newToken: String = try await sut.get(key: key)
guard let newToken: String = try await sut.get(key: key) else {
XCTFail("Should contain a string")
return
}
XCTAssertEqual(newToken, apiToken)
let newValue = false
try await sut.set(newValue, for: key)
let decodedBoolean: Bool = try await sut.get(key: key)
guard let decodedBoolean: Bool = try await sut.get(key: key) else {
XCTFail("Should contain a Bool")
return
}
XCTAssertFalse(decodedBoolean)
}

func test_tryWrongTypeFetching_ShouldFail() async throws {
let key = "testUpdate"
try await sut.set(apiToken, for: key)
await xCTAssertThrowsError(try await sut.get(key: key) as Bool)
await xCTAssertThrowsError(try await sut.get(key: key) as Bool?)
}

func xCTAssertThrowsError<T>(_ expression: @autoclosure () async throws -> T) async {
Expand Down

0 comments on commit a41b93b

Please sign in to comment.