MuteItemTests.swift (2581B)
1 // 2 // MuteItemTests.swift 3 // damusTests 4 // 5 // Created by Charlie Fish on 1/14/24. 6 // 7 8 import XCTest 9 @testable import damus 10 11 class MuteItemTests: XCTestCase { 12 13 override func setUpWithError() throws { 14 // Put setup code here. This method is called before the invocation of each test method in the class. 15 } 16 17 override func tearDownWithError() throws { 18 // Put teardown code here. This method is called after the invocation of each test method in the class. 19 } 20 21 // MARK: - `is_expired` 22 func test_hashtag_is_expired() throws { 23 XCTAssertTrue(MuteItem.hashtag(Hashtag(hashtag: "test"), Date(timeIntervalSince1970: 0)).is_expired()) 24 XCTAssertTrue(MuteItem.hashtag(Hashtag(hashtag: "test"), .distantPast).is_expired()) 25 XCTAssertFalse(MuteItem.hashtag(Hashtag(hashtag: "test"), .distantFuture).is_expired()) 26 } 27 func test_user_is_expired() throws { 28 XCTAssertTrue(MuteItem.user(test_pubkey, Date(timeIntervalSince1970: 0)).is_expired()) 29 XCTAssertTrue(MuteItem.user(test_pubkey, .distantPast).is_expired()) 30 XCTAssertFalse(MuteItem.user(test_pubkey, .distantFuture).is_expired()) 31 } 32 func test_word_is_expired() throws { 33 XCTAssertTrue(MuteItem.word("test", Date(timeIntervalSince1970: 0)).is_expired()) 34 XCTAssertTrue(MuteItem.word("test", .distantPast).is_expired()) 35 XCTAssertFalse(MuteItem.word("test", .distantFuture).is_expired()) 36 } 37 func test_thread_is_expired() throws { 38 XCTAssertTrue(MuteItem.thread(test_note.id, Date(timeIntervalSince1970: 0)).is_expired()) 39 XCTAssertTrue(MuteItem.thread(test_note.id, .distantPast).is_expired()) 40 XCTAssertFalse(MuteItem.thread(test_note.id, .distantFuture).is_expired()) 41 } 42 43 44 // MARK: - `tag` 45 func test_hashtag_tag() throws { 46 XCTAssertEqual(MuteItem.hashtag(Hashtag(hashtag: "test"), nil).tag, ["t", "test"]) 47 XCTAssertEqual(MuteItem.hashtag(Hashtag(hashtag: "test"), Date(timeIntervalSince1970: 1704067200)).tag, ["t", "test", "1704067200"]) 48 } 49 func test_user_tag() throws { 50 XCTAssertEqual(MuteItem.user(test_pubkey, Date(timeIntervalSince1970: 1704067200)).tag, ["p", test_pubkey.hex(), "1704067200"]) 51 } 52 func test_word_tag() throws { 53 XCTAssertEqual(MuteItem.word("test", Date(timeIntervalSince1970: 1704067200)).tag, ["word", "test", "1704067200"]) 54 } 55 func test_thread_tag() throws { 56 XCTAssertEqual(MuteItem.thread(test_note.id, Date(timeIntervalSince1970: 1704067200)).tag, ["e", test_note.id.hex(), "1704067200"]) 57 } 58 }