Skip to content

Commit 18a0bef

Browse files
committed
✅ Add tests for invalid types decoding
1 parent 474eb76 commit 18a0bef

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

Tests/PrefixedTests/PrefixedTests.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,14 @@ final class PrefixedTests: XCTestCase {
7171
XCTAssertNoThrow(try JSONDecoder().decode(InsensitiveUser.self, from: data))
7272
}
7373

74+
func testDecodeWithInvalidTypeUUID() {
75+
let data = """
76+
{"id": "user_ABCD"}
77+
""".data(using: .utf8)!
78+
79+
XCTAssertThrowsError(try JSONDecoder().decode(User.self, from: data))
80+
}
81+
7482
func testEncode() throws {
7583
let int = Int.random(in: 0...9999)
7684
let user = User(id: Prefixed(base: int))

Tests/PrefixedTests/PrefixedUUIDTests.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,14 @@ final class PrefixedUUIDTests: XCTestCase {
6767
XCTAssertNoThrow(try JSONDecoder().decode(InsensitiveUser.self, from: data))
6868
}
6969

70+
func testDecodeWithInvalidType() {
71+
let data = """
72+
{"id": "user_56C68C54"}
73+
""".data(using: .utf8)!
74+
75+
XCTAssertThrowsError(try JSONDecoder().decode(User.self, from: data))
76+
}
77+
7078
func testEncode() throws {
7179
let uuid = UUID()
7280
let user = User(id: PrefixedUUID(uuid: uuid))

0 commit comments

Comments
 (0)