1
0
mirror of git://jb55.com/damus synced 2024-09-05 21:03:51 +00:00
damus/damusTests/LikeTests.swift
William Casarin 2f8aa29e92 ndb: make NostrEvents immutable
Since we can't mutate NdbNotes, let's update the existing codebase to
generate and sign ids on NostrEvent constructions. This will allow us to
match NdbNote's constructor
2023-07-25 15:34:05 -07:00

51 lines
2.2 KiB
Swift

//
// LikeTests.swift
// damusTests
//
// Created by William Casarin on 2022-05-08.
//
import XCTest
@testable import damus
class LikeTests: 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.
}
func testLikeHasNotification() throws {
let liked = NostrEvent(content: "awesome #[0] post", keypair: test_keypair, tags: [["p", "cindy"], ["e", "bob"]])!
let id = liked.id
let like_ev = make_like_event(keypair: test_keypair_full, liked: liked)!
XCTAssertTrue(like_ev.references(id: test_keypair.pubkey, key: "p"))
XCTAssertTrue(like_ev.references(id: "cindy", key: "p"))
XCTAssertTrue(like_ev.references(id: "bob", key: "e"))
XCTAssertEqual(like_ev.last_refid()!.ref_id, id)
}
func testToReactionEmoji() {
let liked = NostrEvent(content: "awesome #[0] post", keypair: test_keypair, tags: [["p", "cindy"], ["e", "bob"]])!
let emptyReaction = make_like_event(keypair: test_keypair_full, liked: liked, content: "")!
let plusReaction = make_like_event(keypair: test_keypair_full, liked: liked, content: "+")!
let minusReaction = make_like_event(keypair: test_keypair_full, liked: liked, content: "-")!
let heartReaction = make_like_event(keypair: test_keypair_full, liked: liked, content: "❤️")!
let thumbsUpReaction = make_like_event(keypair: test_keypair_full, liked: liked, content: "👍")!
let shakaReaction = make_like_event(keypair: test_keypair_full, liked: liked, content: "🤙")!
XCTAssertEqual(to_reaction_emoji(ev: emptyReaction), "❤️")
XCTAssertEqual(to_reaction_emoji(ev: plusReaction), "❤️")
XCTAssertEqual(to_reaction_emoji(ev: minusReaction), "👎")
XCTAssertEqual(to_reaction_emoji(ev: heartReaction), "❤️")
XCTAssertEqual(to_reaction_emoji(ev: thumbsUpReaction), "👍")
XCTAssertEqual(to_reaction_emoji(ev: shakaReaction), "🤙")
}
}