forked from nostr-sdk/nostr-sdk-ios
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add missing fields to UserMetadataEvent and enable MetadataEvents to …
…be updated without wiping out existing fields (nostr-sdk#165)
- Loading branch information
1 parent
9abb296
commit 24a0f9b
Showing
2 changed files
with
72 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,7 +17,18 @@ final class MetadataEventTests: XCTestCase, EventCreating, EventVerifying, Fixtu | |
website: URL(string: "https://github.com/nostr-sdk/nostr-sdk-ios"), | ||
nostrAddress: "[email protected]", | ||
pictureURL: URL(string: "https://nostrsdk.com/picture.png"), | ||
bannerPictureURL: URL(string: "https://nostrsdk.com/banner.png")) | ||
bannerPictureURL: URL(string: "https://nostrsdk.com/banner.png"), | ||
isBot: true, | ||
lightningURLString: "LNURL1234567890", | ||
lightningAddress: "[email protected]") | ||
|
||
let rawUserMetadata: [String: Any] = [ | ||
"foo": "string", | ||
"bool": true, | ||
"number": 123, | ||
"name": "This field should be ignored.", | ||
"lud16": "[email protected]" | ||
] | ||
|
||
let ostrichImageURL = try XCTUnwrap(URL(string: "https://nostrsdk.com/ostrich.png")) | ||
let appleImageURL = try XCTUnwrap(URL(string: "https://nostrsdk.com/apple.png")) | ||
|
@@ -31,7 +42,7 @@ final class MetadataEventTests: XCTestCase, EventCreating, EventVerifying, Fixtu | |
Tag(name: .emoji, value: "apple", otherParameters: ["https://nostrsdk.com/apple.png"]) | ||
] | ||
|
||
let event = try metadataEvent(withUserMetadata: meta, customEmojis: customEmojis, signedBy: Keypair.test) | ||
let event = try metadataEvent(withUserMetadata: meta, rawUserMetadata: rawUserMetadata, customEmojis: customEmojis, signedBy: Keypair.test) | ||
let expectedReplaceableEventCoordinates = try XCTUnwrap(EventCoordinates(kind: .metadata, pubkey: Keypair.test.publicKey)) | ||
|
||
XCTAssertEqual(event.userMetadata?.name, "Nostr SDK Test :ostrich:") | ||
|
@@ -41,6 +52,14 @@ final class MetadataEventTests: XCTestCase, EventCreating, EventVerifying, Fixtu | |
XCTAssertEqual(event.userMetadata?.nostrAddress, "[email protected]") | ||
XCTAssertEqual(event.userMetadata?.pictureURL, URL(string: "https://nostrsdk.com/picture.png")) | ||
XCTAssertEqual(event.userMetadata?.bannerPictureURL, URL(string: "https://nostrsdk.com/banner.png")) | ||
XCTAssertEqual(event.userMetadata?.isBot, true) | ||
XCTAssertEqual(event.userMetadata?.lightningURLString, "LNURL1234567890") | ||
XCTAssertEqual(event.userMetadata?.lightningAddress, "[email protected]") | ||
XCTAssertEqual(event.rawUserMetadata["foo"] as? String, "string") | ||
XCTAssertEqual(event.rawUserMetadata["bool"] as? Bool, true) | ||
XCTAssertEqual(event.rawUserMetadata["number"] as? Int, 123) | ||
XCTAssertEqual(event.rawUserMetadata["name"] as? String, "Nostr SDK Test :ostrich:") | ||
XCTAssertEqual(event.rawUserMetadata["lud16"] as? String, "[email protected]") | ||
XCTAssertEqual(event.customEmojis, customEmojis) | ||
XCTAssertEqual(event.replaceableEventCoordinates(relayURL: nil), expectedReplaceableEventCoordinates) | ||
XCTAssertEqual(event.tags, customEmojiTags) | ||
|
@@ -68,6 +87,7 @@ final class MetadataEventTests: XCTestCase, EventCreating, EventVerifying, Fixtu | |
XCTAssertEqual(event.rawUserMetadata["nip05"] as? String, "[email protected]") | ||
XCTAssertEqual(event.rawUserMetadata["picture"] as? String, "https://nostr.build/i/9396d5cd901304726883aea7363543f121e1d53964dd3149cadecd802608aebe.jpg") | ||
XCTAssertEqual(event.rawUserMetadata["banner"] as? String, "https://nostr.build/i/nostr.build_90a51a2e50c9f42288260d01b3a2a4a1c7a9df085423abad7809e76429da7cdc.gif") | ||
XCTAssertEqual(event.rawUserMetadata["lud16"] as? String, "[email protected]") | ||
|
||
// access metadata properties from decoded object | ||
let userMetadata = try XCTUnwrap(event.userMetadata) | ||
|
@@ -77,6 +97,7 @@ final class MetadataEventTests: XCTestCase, EventCreating, EventVerifying, Fixtu | |
XCTAssertEqual(userMetadata.nostrAddress, "[email protected]") | ||
XCTAssertEqual(userMetadata.pictureURL, URL(string: "https://nostr.build/i/9396d5cd901304726883aea7363543f121e1d53964dd3149cadecd802608aebe.jpg")) | ||
XCTAssertEqual(userMetadata.bannerPictureURL, URL(string: "https://nostr.build/i/nostr.build_90a51a2e50c9f42288260d01b3a2a4a1c7a9df085423abad7809e76429da7cdc.gif")) | ||
XCTAssertEqual(userMetadata.lightningAddress, "[email protected]") | ||
} | ||
|
||
func testDecodeMetadataWithEmptyWebsite() throws { | ||
|