mute: adding new structs/enums for new mute list
- Adding MuteItem & DamusDuration
- Changing RefId hashtag associated type from TagElem to Hashtag
- This is done because in MuteItem, we can not create a RefId.hashtag TagElem instance since we don’t have a note associated with a given hashtag mute item.
Related: https://github.com/damus-io/damus/issues/1718
Related: https://github.com/damus-io/damus/issues/856
Lighting Address: fishcharlie@strike.me
Signed-off-by: Charlie Fish <contact@charlie.fish>
Reviewed-by: William Casarin <jb55@jb55.com>
Signed-off-by: William Casarin <jb55@jb55.com>
This commit is contained in:
committed by
William Casarin
parent
f13267aeb2
commit
068b89d087
58
damusTests/Models/MuteItemTests.swift
Normal file
58
damusTests/Models/MuteItemTests.swift
Normal file
@@ -0,0 +1,58 @@
|
||||
//
|
||||
// MuteItemTests.swift
|
||||
// damusTests
|
||||
//
|
||||
// Created by Charlie Fish on 1/14/24.
|
||||
//
|
||||
|
||||
import XCTest
|
||||
@testable import damus
|
||||
|
||||
class MuteItemTests: XCTestCase {
|
||||
|
||||
override func setUpWithError() throws {
|
||||
// Put setup code here. This method is called before the invocation of each test method in the class.
|
||||
}
|
||||
|
||||
override func tearDownWithError() throws {
|
||||
// Put teardown code here. This method is called after the invocation of each test method in the class.
|
||||
}
|
||||
|
||||
// MARK: - `is_expired`
|
||||
func test_hashtag_is_expired() throws {
|
||||
XCTAssertTrue(MuteItem.hashtag(Hashtag(hashtag: "test"), Date(timeIntervalSince1970: 0)).is_expired())
|
||||
XCTAssertTrue(MuteItem.hashtag(Hashtag(hashtag: "test"), .distantPast).is_expired())
|
||||
XCTAssertFalse(MuteItem.hashtag(Hashtag(hashtag: "test"), .distantFuture).is_expired())
|
||||
}
|
||||
func test_user_is_expired() throws {
|
||||
XCTAssertTrue(MuteItem.user(test_pubkey, Date(timeIntervalSince1970: 0)).is_expired())
|
||||
XCTAssertTrue(MuteItem.user(test_pubkey, .distantPast).is_expired())
|
||||
XCTAssertFalse(MuteItem.user(test_pubkey, .distantFuture).is_expired())
|
||||
}
|
||||
func test_word_is_expired() throws {
|
||||
XCTAssertTrue(MuteItem.word("test", Date(timeIntervalSince1970: 0)).is_expired())
|
||||
XCTAssertTrue(MuteItem.word("test", .distantPast).is_expired())
|
||||
XCTAssertFalse(MuteItem.word("test", .distantFuture).is_expired())
|
||||
}
|
||||
func test_thread_is_expired() throws {
|
||||
XCTAssertTrue(MuteItem.thread(test_note.id, Date(timeIntervalSince1970: 0)).is_expired())
|
||||
XCTAssertTrue(MuteItem.thread(test_note.id, .distantPast).is_expired())
|
||||
XCTAssertFalse(MuteItem.thread(test_note.id, .distantFuture).is_expired())
|
||||
}
|
||||
|
||||
|
||||
// MARK: - `tag`
|
||||
func test_hashtag_tag() throws {
|
||||
XCTAssertEqual(MuteItem.hashtag(Hashtag(hashtag: "test"), nil).tag, ["t", "test"])
|
||||
XCTAssertEqual(MuteItem.hashtag(Hashtag(hashtag: "test"), Date(timeIntervalSince1970: 1704067200)).tag, ["t", "test", "1704067200"])
|
||||
}
|
||||
func test_user_tag() throws {
|
||||
XCTAssertEqual(MuteItem.user(test_pubkey, Date(timeIntervalSince1970: 1704067200)).tag, ["p", test_pubkey.hex(), "1704067200"])
|
||||
}
|
||||
func test_word_tag() throws {
|
||||
XCTAssertEqual(MuteItem.word("test", Date(timeIntervalSince1970: 1704067200)).tag, ["word", "test", "1704067200"])
|
||||
}
|
||||
func test_thread_tag() throws {
|
||||
XCTAssertEqual(MuteItem.thread(test_note.id, Date(timeIntervalSince1970: 1704067200)).tag, ["e", test_note.id.hex(), "1704067200"])
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user