fixed tests
This commit is contained in:
committed by
William Casarin
parent
909148f0be
commit
1b4e54582f
@@ -498,7 +498,7 @@ class HomeModel: ObservableObject {
|
|||||||
|
|
||||||
if !should_debounce_dms {
|
if !should_debounce_dms {
|
||||||
self.incoming_dms.append(ev)
|
self.incoming_dms.append(ev)
|
||||||
if let notifs = handle_incoming_dms(contacts: self.damus_state.contacts, prev_events: self.new_events, dms: self.dms, our_pubkey: self.damus_state.pubkey, evs: self.incoming_dms) {
|
if let notifs = handle_incoming_dms(prev_events: self.new_events, dms: self.dms, our_pubkey: self.damus_state.pubkey, evs: self.incoming_dms) {
|
||||||
self.new_events = notifs
|
self.new_events = notifs
|
||||||
}
|
}
|
||||||
self.incoming_dms = []
|
self.incoming_dms = []
|
||||||
@@ -508,7 +508,7 @@ class HomeModel: ObservableObject {
|
|||||||
incoming_dms.append(ev)
|
incoming_dms.append(ev)
|
||||||
|
|
||||||
dm_debouncer.debounce {
|
dm_debouncer.debounce {
|
||||||
if let notifs = handle_incoming_dms(contacts: self.damus_state.contacts, prev_events: self.new_events, dms: self.dms, our_pubkey: self.damus_state.pubkey, evs: self.incoming_dms) {
|
if let notifs = handle_incoming_dms(prev_events: self.new_events, dms: self.dms, our_pubkey: self.damus_state.pubkey, evs: self.incoming_dms) {
|
||||||
self.new_events = notifs
|
self.new_events = notifs
|
||||||
}
|
}
|
||||||
self.incoming_dms = []
|
self.incoming_dms = []
|
||||||
@@ -792,6 +792,7 @@ func fetch_relay_metadata(relay_id: String) async throws -> RelayMetadata? {
|
|||||||
func process_relay_metadata() {
|
func process_relay_metadata() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@discardableResult
|
||||||
func handle_incoming_dm(ev: NostrEvent, our_pubkey: String, dms: DirectMessagesModel, prev_events: NewEventsBits) -> (Bool, NewEventsBits?) {
|
func handle_incoming_dm(ev: NostrEvent, our_pubkey: String, dms: DirectMessagesModel, prev_events: NewEventsBits) -> (Bool, NewEventsBits?) {
|
||||||
var inserted = false
|
var inserted = false
|
||||||
var found = false
|
var found = false
|
||||||
@@ -824,6 +825,7 @@ func handle_incoming_dm(ev: NostrEvent, our_pubkey: String, dms: DirectMessagesM
|
|||||||
if !found {
|
if !found {
|
||||||
let model = DirectMessageModel(events: [ev], our_pubkey: our_pubkey)
|
let model = DirectMessageModel(events: [ev], our_pubkey: our_pubkey)
|
||||||
dms.dms.append((the_pk, model))
|
dms.dms.append((the_pk, model))
|
||||||
|
inserted = true
|
||||||
}
|
}
|
||||||
|
|
||||||
var new_bits: NewEventsBits? = nil
|
var new_bits: NewEventsBits? = nil
|
||||||
@@ -834,7 +836,8 @@ func handle_incoming_dm(ev: NostrEvent, our_pubkey: String, dms: DirectMessagesM
|
|||||||
return (inserted, new_bits)
|
return (inserted, new_bits)
|
||||||
}
|
}
|
||||||
|
|
||||||
func handle_incoming_dms(contacts: Contacts, prev_events: NewEventsBits, dms: DirectMessagesModel, our_pubkey: String, evs: [NostrEvent]) -> NewEventsBits? {
|
@discardableResult
|
||||||
|
func handle_incoming_dms(prev_events: NewEventsBits, dms: DirectMessagesModel, our_pubkey: String, evs: [NostrEvent]) -> NewEventsBits? {
|
||||||
var inserted = false
|
var inserted = false
|
||||||
|
|
||||||
var new_events: NewEventsBits? = nil
|
var new_events: NewEventsBits? = nil
|
||||||
|
|||||||
@@ -10,14 +10,6 @@ import XCTest
|
|||||||
|
|
||||||
final class DMTests: XCTestCase {
|
final class DMTests: 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.
|
|
||||||
}
|
|
||||||
|
|
||||||
var alice: Keypair {
|
var alice: Keypair {
|
||||||
let sec = "494c680d20f202807a116a6915815bd76a27d62802e7585806f6a2e034cb5cdb"
|
let sec = "494c680d20f202807a116a6915815bd76a27d62802e7585806f6a2e034cb5cdb"
|
||||||
let pk = "22d925632551a3299022e98de7f9c1087f79a21209f3413ec24ec219b08bd1e4"
|
let pk = "22d925632551a3299022e98de7f9c1087f79a21209f3413ec24ec219b08bd1e4"
|
||||||
@@ -52,78 +44,62 @@ final class DMTests: XCTestCase {
|
|||||||
let notif = NewEventsBits()
|
let notif = NewEventsBits()
|
||||||
let pubkey = "3efdaebb1d8923ebd99c9e7ace3b4194ab45512e2be79c1b7d68d9243e0d2681"
|
let pubkey = "3efdaebb1d8923ebd99c9e7ace3b4194ab45512e2be79c1b7d68d9243e0d2681"
|
||||||
let model = DirectMessagesModel(our_pubkey: pubkey)
|
let model = DirectMessagesModel(our_pubkey: pubkey)
|
||||||
let contacts = Contacts(our_pubkey: pubkey)
|
|
||||||
|
|
||||||
let now = Int64(Date().timeIntervalSince1970)
|
let now = Int64(Date().timeIntervalSince1970)
|
||||||
|
|
||||||
let alice_to_bob = create_dm("hi bob", to_pk: bob.pubkey, tags: [["p", bob.pubkey]], keypair: alice, created_at: now)!
|
let alice_to_bob = create_dm("hi bob", to_pk: bob.pubkey, tags: [["p", bob.pubkey]], keypair: alice, created_at: now)!
|
||||||
let _ = handle_incoming_dm(contacts: contacts, prev_events: notif, dms: model, our_pubkey: alice.pubkey, ev: alice_to_bob)
|
handle_incoming_dms(prev_events: notif, dms: model, our_pubkey: alice.pubkey, evs: [alice_to_bob])
|
||||||
|
|
||||||
XCTAssertEqual(model.dms.count, 1)
|
XCTAssertEqual(model.dms.count, 1)
|
||||||
XCTAssertEqual(model.dms[0].0, bob.pubkey)
|
XCTAssertEqual(model.dms[0].0, bob.pubkey)
|
||||||
|
|
||||||
let bob_to_alice = create_dm("hi alice", to_pk: alice.pubkey, tags: [["p", alice.pubkey]], keypair: bob, created_at: now + 1)!
|
let bob_to_alice = create_dm("hi alice", to_pk: alice.pubkey, tags: [["p", alice.pubkey]], keypair: bob, created_at: now + 1)!
|
||||||
let _ = handle_incoming_dm(contacts: contacts, prev_events: notif, dms: model, our_pubkey: alice.pubkey, ev: bob_to_alice)
|
handle_incoming_dms(prev_events: notif, dms: model, our_pubkey: alice.pubkey, evs: [bob_to_alice])
|
||||||
|
|
||||||
XCTAssertEqual(model.dms.count, 1)
|
XCTAssertEqual(model.dms.count, 1)
|
||||||
XCTAssertEqual(model.dms[0].0, bob.pubkey)
|
XCTAssertEqual(model.dms[0].0, bob.pubkey)
|
||||||
|
|
||||||
let alice_to_bob_2 = create_dm("hi bob", to_pk: bob.pubkey, tags: [["p", bob.pubkey]], keypair: alice, created_at: now + 2)!
|
let alice_to_bob_2 = create_dm("hi bob", to_pk: bob.pubkey, tags: [["p", bob.pubkey]], keypair: alice, created_at: now + 2)!
|
||||||
let _ = handle_incoming_dm(contacts: contacts, prev_events: notif, dms: model, our_pubkey: alice.pubkey, ev: alice_to_bob_2)
|
handle_incoming_dms(prev_events: notif, dms: model, our_pubkey: alice.pubkey, evs: [alice_to_bob_2])
|
||||||
|
|
||||||
XCTAssertEqual(model.dms.count, 1)
|
XCTAssertEqual(model.dms.count, 1)
|
||||||
XCTAssertEqual(model.dms[0].0, bob.pubkey)
|
XCTAssertEqual(model.dms[0].0, bob.pubkey)
|
||||||
|
|
||||||
let fiatjaf_to_alice = create_dm("hi alice", to_pk: alice.pubkey, tags: [["p", alice.pubkey]], keypair: fiatjaf, created_at: now+5)!
|
let fiatjaf_to_alice = create_dm("hi alice", to_pk: alice.pubkey, tags: [["p", alice.pubkey]], keypair: fiatjaf, created_at: now+5)!
|
||||||
let _ = handle_incoming_dm(contacts: contacts, prev_events: notif, dms: model, our_pubkey: alice.pubkey, ev: fiatjaf_to_alice)
|
handle_incoming_dms(prev_events: notif, dms: model, our_pubkey: alice.pubkey, evs: [fiatjaf_to_alice])
|
||||||
|
|
||||||
XCTAssertEqual(model.dms.count, 2)
|
XCTAssertEqual(model.dms.count, 2)
|
||||||
XCTAssertEqual(model.dms[0].0, fiatjaf.pubkey)
|
XCTAssertEqual(model.dms[0].0, fiatjaf.pubkey)
|
||||||
|
|
||||||
let dave_to_alice = create_dm("hi alice", to_pk: alice.pubkey, tags: [["p", alice.pubkey]], keypair: dave, created_at: now + 10)!
|
let dave_to_alice = create_dm("hi alice", to_pk: alice.pubkey, tags: [["p", alice.pubkey]], keypair: dave, created_at: now + 10)!
|
||||||
let _ = handle_incoming_dm(contacts: contacts, prev_events: notif, dms: model, our_pubkey: alice.pubkey, ev: dave_to_alice)
|
handle_incoming_dms(prev_events: notif, dms: model, our_pubkey: alice.pubkey, evs: [dave_to_alice])
|
||||||
|
|
||||||
XCTAssertEqual(model.dms.count, 3)
|
XCTAssertEqual(model.dms.count, 3)
|
||||||
XCTAssertEqual(model.dms[0].0, dave.pubkey)
|
XCTAssertEqual(model.dms[0].0, dave.pubkey)
|
||||||
|
|
||||||
let bob_to_alice_2 = create_dm("hi alice 2", to_pk: alice.pubkey, tags: [["p", alice.pubkey]], keypair: bob, created_at: now + 15)!
|
let bob_to_alice_2 = create_dm("hi alice 2", to_pk: alice.pubkey, tags: [["p", alice.pubkey]], keypair: bob, created_at: now + 15)!
|
||||||
let _ = handle_incoming_dm(contacts: contacts, prev_events: notif, dms: model, our_pubkey: alice.pubkey, ev: bob_to_alice_2)
|
handle_incoming_dms(prev_events: notif, dms: model, our_pubkey: alice.pubkey, evs: [bob_to_alice_2])
|
||||||
|
|
||||||
XCTAssertEqual(model.dms.count, 3)
|
XCTAssertEqual(model.dms.count, 3)
|
||||||
XCTAssertEqual(model.dms[0].0, bob.pubkey)
|
XCTAssertEqual(model.dms[0].0, bob.pubkey)
|
||||||
|
|
||||||
let charlie_to_alice = create_dm("hi alice", to_pk: alice.pubkey, tags: [["p", alice.pubkey]], keypair: charlie, created_at: now + 20)!
|
let charlie_to_alice = create_dm("hi alice", to_pk: alice.pubkey, tags: [["p", alice.pubkey]], keypair: charlie, created_at: now + 20)!
|
||||||
let _ = handle_incoming_dm(contacts: contacts, prev_events: notif, dms: model, our_pubkey: alice.pubkey, ev: charlie_to_alice)
|
handle_incoming_dms(prev_events: notif, dms: model, our_pubkey: alice.pubkey, evs: [charlie_to_alice])
|
||||||
|
|
||||||
XCTAssertEqual(model.dms.count, 4)
|
XCTAssertEqual(model.dms.count, 4)
|
||||||
XCTAssertEqual(model.dms[0].0, charlie.pubkey)
|
XCTAssertEqual(model.dms[0].0, charlie.pubkey)
|
||||||
|
|
||||||
let bob_to_alice_3 = create_dm("hi alice 3", to_pk: alice.pubkey, tags: [["p", alice.pubkey]], keypair: bob, created_at: now + 25)!
|
let bob_to_alice_3 = create_dm("hi alice 3", to_pk: alice.pubkey, tags: [["p", alice.pubkey]], keypair: bob, created_at: now + 25)!
|
||||||
let _ = handle_incoming_dm(contacts: contacts, prev_events: notif, dms: model, our_pubkey: alice.pubkey, ev: bob_to_alice_3)
|
handle_incoming_dms(prev_events: notif, dms: model, our_pubkey: alice.pubkey, evs: [bob_to_alice_3])
|
||||||
|
|
||||||
XCTAssertEqual(model.dms.count, 4)
|
XCTAssertEqual(model.dms.count, 4)
|
||||||
XCTAssertEqual(model.dms[0].0, bob.pubkey)
|
XCTAssertEqual(model.dms[0].0, bob.pubkey)
|
||||||
|
|
||||||
let charlie_to_alice_2 = create_dm("hi alice 2", to_pk: alice.pubkey, tags: [["p", alice.pubkey]], keypair: charlie, created_at: now + 30)!
|
let charlie_to_alice_2 = create_dm("hi alice 2", to_pk: alice.pubkey, tags: [["p", alice.pubkey]], keypair: charlie, created_at: now + 30)!
|
||||||
let _ = handle_incoming_dm(contacts: contacts, prev_events: notif, dms: model, our_pubkey: alice.pubkey, ev: charlie_to_alice_2)
|
handle_incoming_dms(prev_events: notif, dms: model, our_pubkey: alice.pubkey, evs: [charlie_to_alice_2])
|
||||||
|
|
||||||
XCTAssertEqual(model.dms.count, 4)
|
XCTAssertEqual(model.dms.count, 4)
|
||||||
XCTAssertEqual(model.dms[0].0, charlie.pubkey)
|
XCTAssertEqual(model.dms[0].0, charlie.pubkey)
|
||||||
|
|
||||||
|
|
||||||
//let alice_to_bob_2 = create_dm("whats up", to_pk: bob.pubkey, tags: [], keypair: alice, created_at: now + 6)
|
|
||||||
|
|
||||||
//let charlie_to_alice = create_dm("hi alice", to_pk: alice.pubkey, tags: [], keypair: charlie, created_at: now + 7)
|
|
||||||
//let alice_to_charlie = create_dm("hey charlie", to_pk: charlie.pubkey, tags[], keypair: alice, created_at: now + 8)
|
|
||||||
|
|
||||||
//handle_incoming_dm(prev_events: notif, dms: model, our_pubkey: pk, ev: ev)
|
|
||||||
}
|
|
||||||
|
|
||||||
func testPerformanceExample() throws {
|
|
||||||
// This is an example of a performance test case.
|
|
||||||
self.measure {
|
|
||||||
// Put the code you want to measure the time of here.
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user