Skip to content

Commit

Permalink
cursor tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rcarver committed Apr 24, 2024
1 parent 5fdd682 commit c4d5fb8
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions Tests/GraphQLPaginationTests/CursorTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import CustomDump
import XCTest

@testable import GraphQLPagination

final class CursorTests: XCTestCase {

func test_string() throws {
let id = Cursor(rawValue: "testing123")

XCTAssertEqual(id.rawValue, "testing123")
XCTAssertEqual(id.description, "dGVzdGluZzEyMw==")

XCTAssertEqual(
String(data: try JSONEncoder().encode(id), encoding: .utf8),
"""
"dGVzdGluZzEyMw=="
"""
)
}

func test_intValue() throws {
let id = Cursor(intValue: 3)

XCTAssertEqual(id.rawValue, "3")
XCTAssertEqual(id.description, "Mw==")

XCTAssertEqual(
String(data: try JSONEncoder().encode(id), encoding: .utf8),
"""
"Mw=="
"""
)
}

func test_coding_roundtrip() throws {
let id = Cursor(rawValue: "testing123")
let encoded = try JSONEncoder().encode(id)
let decoded = try JSONDecoder().decode(Cursor.self, from: encoded)
XCTAssertNoDifference(id, decoded)
}

func test_intValue_valid() {
let id = Cursor(intValue: 3)
XCTAssertEqual(id.intValue(), 3)
}
func test_intValue_invalid() {
let id = Cursor(rawValue: "foo")
XCTAssertEqual(id.intValue(), nil)
}
}

0 comments on commit c4d5fb8

Please sign in to comment.