tests: add ndb support to tests
stops it from crashing
This commit is contained in:
@@ -19,14 +19,14 @@ final class EventGroupViewTests: XCTestCase {
|
||||
}
|
||||
|
||||
func testEventAuthorName() {
|
||||
let damusState = test_damus_state()
|
||||
let damusState = test_damus_state
|
||||
XCTAssertEqual(event_author_name(profiles: damusState.profiles, pubkey: test_pubkey), "damus")
|
||||
XCTAssertEqual(event_author_name(profiles: damusState.profiles, pubkey: test_pubkey_2), "1rppft3m:4qxhsgnj")
|
||||
XCTAssertEqual(event_author_name(profiles: damusState.profiles, pubkey: ANON_PUBKEY), "Anonymous")
|
||||
}
|
||||
|
||||
func testEventGroupUniquePubkeys() {
|
||||
let damusState = test_damus_state()
|
||||
let damusState = test_damus_state
|
||||
|
||||
let encodedPost = "{\"id\": \"8ba545ab96959fe0ce7db31bc10f3ac3aa5353bc4428dbf1e56a7be7062516db\",\"pubkey\": \"7e27509ccf1e297e1df164912a43406218f8bd80129424c3ef798ca3ef5c8444\",\"created_at\": 1677013417,\"kind\": 1,\"tags\": [],\"content\": \"hello\",\"sig\": \"93684f15eddf11f42afbdd81828ee9fc35350344d8650c78909099d776e9ad8d959cd5c4bff7045be3b0b255144add43d0feef97940794a1bc9c309791bebe4a\"}"
|
||||
|
||||
@@ -49,7 +49,7 @@ final class EventGroupViewTests: XCTestCase {
|
||||
|
||||
func testReactingToText() throws {
|
||||
let enUsLocale = Locale(identifier: "en-US")
|
||||
let damusState = test_damus_state()
|
||||
let damusState = test_damus_state
|
||||
|
||||
let encodedPost = "{\"id\": \"8ba545ab96959fe0ce7db31bc10f3ac3aa5353bc4428dbf1e56a7be7062516db\",\"pubkey\": \"7e27509ccf1e297e1df164912a43406218f8bd80129424c3ef798ca3ef5c8444\",\"created_at\": 1677013417,\"kind\": 1,\"tags\": [],\"content\": \"hello\",\"sig\": \"93684f15eddf11f42afbdd81828ee9fc35350344d8650c78909099d776e9ad8d959cd5c4bff7045be3b0b255144add43d0feef97940794a1bc9c309791bebe4a\"}"
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ final class LongPostTests: XCTestCase {
|
||||
XCTAssertEqual(subid, "subid")
|
||||
XCTAssertTrue(ev.should_show_event)
|
||||
XCTAssertTrue(!ev.too_big)
|
||||
XCTAssertTrue(should_show_event(keypair: test_keypair, hellthreads: test_damus_state().muted_threads, contacts: contacts, ev: ev))
|
||||
XCTAssertTrue(should_show_event(keypair: test_keypair, hellthreads: test_damus_state.muted_threads, contacts: contacts, ev: ev))
|
||||
XCTAssertTrue(validate_event(ev: ev) == .ok )
|
||||
}
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ class NoteContentViewTests: XCTestCase {
|
||||
let note = NostrEvent(content: content, keypair: test_keypair, tags: [["t", "かっこいい"]])!
|
||||
let parsed: Blocks = parse_note_content(content: .init(note: note, keypair: test_keypair))
|
||||
|
||||
let testState = test_damus_state()
|
||||
let testState = test_damus_state
|
||||
|
||||
let text: NoteArtifactsSeparated = render_blocks(blocks: parsed, profiles: testState.profiles)
|
||||
let attributedText: AttributedString = text.content.attributed
|
||||
|
||||
@@ -21,24 +21,25 @@ final class ProfileViewTests: XCTestCase {
|
||||
}
|
||||
|
||||
func testFollowedByString() throws {
|
||||
let profiles = test_damus_state().profiles
|
||||
|
||||
let pk1 = test_pubkey
|
||||
let pk2 = test_pubkey_2
|
||||
let pk3 = Pubkey(hex: "b42e44b555013239a0d5dcdb09ebde0857cd8a5a57efbba5a2b6ac78833cb9f0")!
|
||||
let pk4 = Pubkey(hex: "cc590e46363d0fa66bb27081368d01f169b8ffc7c614629d4e9eef6c88b38670")!
|
||||
let pk5 = Pubkey(hex: "f2aa579bb998627e04a8f553842a09446360c9d708c6141dd119c479f6ab9d29")!
|
||||
|
||||
XCTAssertEqual(followedByString([pk1], profiles: profiles, locale: enUsLocale), "Followed by damus")
|
||||
XCTAssertEqual(followedByString([pk1, pk2], profiles: profiles, locale: enUsLocale), "Followed by damus & 1rppft3m:4qxhsgnj")
|
||||
XCTAssertEqual(followedByString([pk1, pk2, pk3], profiles: profiles, locale: enUsLocale), "Followed by damus, 1rppft3m:4qxhsgnj & 1kshyfd2:cq04aze0")
|
||||
XCTAssertEqual(followedByString([pk1, pk2, pk3, pk4,], profiles: profiles, locale: enUsLocale), "Followed by damus, 1rppft3m:4qxhsgnj, 1kshyfd2:cq04aze0 & 1 other")
|
||||
XCTAssertEqual(followedByString([pk1, pk2, pk3, pk4, pk5], profiles: profiles, locale: enUsLocale), "Followed by damus, 1rppft3m:4qxhsgnj, 1kshyfd2:cq04aze0 & 2 others")
|
||||
let ndb = Ndb(path: Ndb.db_path)!
|
||||
let txn = NdbTxn(ndb: ndb)
|
||||
|
||||
XCTAssertEqual(followedByString(txn: txn, [pk1], ndb: ndb, locale: enUsLocale), "Followed by damus")
|
||||
XCTAssertEqual(followedByString(txn: txn, [pk1, pk2], ndb: ndb, locale: enUsLocale), "Followed by damus & 1rppft3m:4qxhsgnj")
|
||||
XCTAssertEqual(followedByString(txn: txn, [pk1, pk2, pk3], ndb: ndb, locale: enUsLocale), "Followed by damus, 1rppft3m:4qxhsgnj & 1kshyfd2:cq04aze0")
|
||||
XCTAssertEqual(followedByString(txn: txn, [pk1, pk2, pk3, pk4,], ndb: ndb, locale: enUsLocale), "Followed by damus, 1rppft3m:4qxhsgnj, 1kshyfd2:cq04aze0 & 1 other")
|
||||
XCTAssertEqual(followedByString(txn: txn, [pk1, pk2, pk3, pk4, pk5], ndb: ndb, locale: enUsLocale), "Followed by damus, 1rppft3m:4qxhsgnj, 1kshyfd2:cq04aze0 & 2 others")
|
||||
|
||||
let pubkeys = [pk1, pk2, pk3, pk4, pk5, pk1, pk2, pk3, pk4, pk5]
|
||||
Bundle.main.localizations.map { Locale(identifier: $0) }.forEach {
|
||||
for count in 1...10 {
|
||||
XCTAssertNoThrow(followedByString(pubkeys.prefix(count).map { $0 }, profiles: profiles, locale: $0))
|
||||
XCTAssertNoThrow(followedByString(txn: txn, pubkeys.prefix(count).map { $0 }, ndb: ndb, locale: $0))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ import XCTest
|
||||
final class UserSearchCacheTests: XCTestCase {
|
||||
|
||||
var keypair: FullKeypair? = nil
|
||||
let damusState = DamusState.empty
|
||||
let damusState = test_damus_state
|
||||
let nip05 = "_@somedomain.com"
|
||||
|
||||
@MainActor
|
||||
@@ -55,11 +55,6 @@ final class UserSearchCacheTests: XCTestCase {
|
||||
|
||||
damusState.profiles.set_validated(keypair.pubkey, nip05: NIP05.parse(newNip05))
|
||||
|
||||
let newProfile = Profile(name: "whoami", display_name: "T-DAWG", about: nil, picture: nil, banner: nil, website: nil, lud06: nil, lud16: nil, nip05: newNip05, damus_donation: nil)
|
||||
|
||||
// Lookup to synchronize access on profiles dictionary to avoid race conditions.
|
||||
let _ = damusState.profiles.lookup(id: keypair.pubkey)
|
||||
|
||||
// Old profile attributes are removed from cache.
|
||||
XCTAssertEqual(damusState.user_search_cache.search(key: "tyiu"), [])
|
||||
XCTAssertEqual(damusState.user_search_cache.search(key: "ty"), [])
|
||||
|
||||
@@ -69,7 +69,7 @@ final class ZapTests: XCTestCase {
|
||||
XCTAssertEqual(zap.target, ZapTarget.profile(profile))
|
||||
|
||||
XCTAssertEqual(zap_notification_title(zap), "Zap")
|
||||
XCTAssertEqual(zap_notification_body(profiles: Profiles(user_search_cache: UserSearchCache(), ndb: .empty), zap: zap), "You received 1k sats from 107jk7ht:2quqncxg")
|
||||
XCTAssertEqual(zap_notification_body(profiles: Profiles(user_search_cache: UserSearchCache(), ndb: test_damus_state.ndb), zap: zap), "You received 1k sats from 107jk7ht:2quqncxg")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user