import XCTest @testable import iPX final class BadgeTests: XCTestCase { private func count(_ json: String) -> Int? { Badge.unread(inAll: Data(json.utf8)) } func testItCountsTheUnreadOfFeedsInAll() { XCTAssertEqual(count(#"[{"id":"a","unread":3},{"id":"b","unread":4,"hide_from_all":false}]"#), 7) } func testAFeedHiddenFromAllIsLeftOut() { XCTAssertEqual(count(#"[{"id":"a","unread":3},{"id":"b","unread":4,"hide_from_all":true}]"#), 3) } func testAFeedFromAnOPMLHiddenFromAllIsLeftOut() { let json = #"[{"id":"o","unread":0,"hide_from_all":true},{"id":"a","unread":5,"group":"o"},{"id":"b","unread":2}]"# XCTAssertEqual(count(json), 2) } func testAnErrorBodyIsNotAFeedListAndIsNotZero() { XCTAssertNil(count(#"{"error":"unauthorised"}"#)) XCTAssertNil(count("sign in")) } }