-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reorganize tests out of EventCreatingTests and EventDecodingTests int…
…o event kind specific tests
- Loading branch information
Showing
19 changed files
with
1,533 additions
and
1,363 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,76 @@ | ||
// | ||
// BookmarksListEventTests.swift | ||
// | ||
// | ||
// Created by Terry Yiu on 4/14/24. | ||
// | ||
|
||
@testable import NostrSDK | ||
import XCTest | ||
|
||
final class BookmarksListEventTests: XCTestCase, EventCreating, EventVerifying, FixtureLoading { | ||
|
||
func testCreateBookmarkList() throws { | ||
let publicCoordinates = try XCTUnwrap(try EventCoordinates(kind: .longformContent, pubkey: Keypair.test.publicKey, identifier: "the-public-one")) | ||
let publicTags: [Tag] = [ | ||
.event("test-id", otherParameters: ["wss://relay.com"]), | ||
.hashtag("nostra"), | ||
.link(URL(string: "https://www.nostr.com")!), | ||
publicCoordinates.tag | ||
] | ||
|
||
let privateCoordinates = try XCTUnwrap(try EventCoordinates(kind: .longformContent, pubkey: Keypair.test.publicKey, identifier: "the-private-one")) | ||
let privateTags: [Tag] = [ | ||
.event("test-id-private", otherParameters: ["wss://relay.com"]), | ||
.hashtag("noster"), | ||
.link(URL(string: "https://www.private.net")!), | ||
privateCoordinates.tag | ||
] | ||
|
||
let bookmarks = try bookmarksList(withPublicTags: publicTags, | ||
privateTags: privateTags, | ||
signedBy: .test) | ||
|
||
XCTAssertEqual(bookmarks.noteIds, ["test-id"]) | ||
XCTAssertEqual(bookmarks.hashtags, ["nostra"]) | ||
XCTAssertEqual(bookmarks.links, [URL(string: "https://www.nostr.com")!]) | ||
XCTAssertEqual(bookmarks.articlesCoordinates, [publicCoordinates]) | ||
|
||
XCTAssertEqual(bookmarks.privateNoteIds(using: .test), ["test-id-private"]) | ||
XCTAssertEqual(bookmarks.privateHashtags(using: .test), ["noster"]) | ||
XCTAssertEqual(bookmarks.privateLinks(using: .test), [URL(string: "https://www.private.net")!]) | ||
XCTAssertEqual(bookmarks.privateArticlesCoordinates(using: .test), [privateCoordinates]) | ||
|
||
XCTAssertEqual(bookmarks.noteTags, [Tag.event("test-id", otherParameters: ["wss://relay.com"])]) | ||
XCTAssertEqual(bookmarks.privateNoteTags(using: .test), [Tag.event("test-id-private", otherParameters: ["wss://relay.com"])]) | ||
|
||
try verifyEvent(bookmarks) | ||
} | ||
|
||
func testCreateBookmarkListFailsWithUnexpectedTag() throws { | ||
XCTAssertThrowsError(try bookmarksList(withPublicTags: [Tag(name: .title, value: "hello world")], signedBy: .test)) | ||
} | ||
|
||
func testDecodeBookmarksListEvent() throws { | ||
let event: BookmarksListEvent = try decodeFixture(filename: "bookmarks") | ||
|
||
XCTAssertEqual(event.id, "60cf106df8f7e4437db3119f3795607961d9b764a622eca67d97db60ee1313d8") | ||
XCTAssertEqual(event.pubkey, "9947f9659dd80c3682402b612f5447e28249997fb3709500c32a585eb0977340") | ||
XCTAssertEqual(event.kind, .bookmarksList) | ||
|
||
XCTAssertTrue(event.noteIds.contains("be8567dc210986fe5dc0ad04e02a8850b3b86e1d30c0ab674d102f0eefa68921")) | ||
XCTAssertTrue(event.hashtags.contains("up")) | ||
XCTAssertTrue(event.links.contains(URL(string: "https://nostr.com/")!)) | ||
let coordinates = try XCTUnwrap(EventCoordinates(kind: .longformContent, | ||
pubkey: PublicKey(hex: "599f67f7df7694c603a6d0636e15ebc610db77dcfd47d6e5d05386d821fb3ea9")!, | ||
identifier: "1700730909108", | ||
relayURL: URL(string: "wss://relay.nostr.band"))) | ||
XCTAssertTrue(event.articlesCoordinates.contains(coordinates)) | ||
|
||
XCTAssertTrue(event.privateNoteIds(using: .test).contains("65eff7eb588f169789026d2915c1fe6aaa3be0b855cebeb32b727f68c54c5a64")) | ||
XCTAssertTrue(event.privateHashtags(using: .test).contains("down")) | ||
XCTAssertTrue(event.privateLinks(using: .test).contains(URL(string: "https://www.apple.com/")!)) | ||
XCTAssertTrue(event.privateArticlesCoordinates(using: .test).contains(coordinates)) | ||
} | ||
|
||
} |
File renamed without changes.
113 changes: 113 additions & 0 deletions
113
Tests/NostrSDKTests/Events/Calendars/CalendarEventRSVPTests.swift
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 |
---|---|---|
@@ -0,0 +1,113 @@ | ||
// | ||
// CalendarEventRSVPTests.swift | ||
// | ||
// | ||
// Created by Terry Yiu on 4/14/24. | ||
// | ||
|
||
@testable import NostrSDK | ||
import XCTest | ||
|
||
final class CalendarEventRSVPTests: XCTestCase, EventCreating, EventVerifying, FixtureLoading { | ||
|
||
func testCreateDateBasedCalendarEventRSVP() throws { | ||
let timeOmittedStartDate = try XCTUnwrap(TimeOmittedDate(year: 2023, month: 12, day: 31)) | ||
let dateBasedCalendarEvent = try XCTUnwrap(dateBasedCalendarEvent(title: "New Year's Eve", startDate: timeOmittedStartDate, signedBy: Keypair.test)) | ||
let dateBasedCalendarEventCoordinates = try XCTUnwrap(dateBasedCalendarEvent.replaceableEventCoordinates(relayURL: nil)) | ||
|
||
let identifier = "hockey-practice-rsvp" | ||
let note = "Don't forget your skates!" | ||
let calendarEventRSVP = try calendarEventRSVP(withIdentifier: identifier, calendarEventCoordinates: dateBasedCalendarEventCoordinates, status: .accepted, freebusy: .busy, note: note, signedBy: Keypair.test) | ||
|
||
XCTAssertEqual(calendarEventRSVP.identifier, identifier) | ||
XCTAssertEqual(calendarEventRSVP.calendarEventCoordinates, dateBasedCalendarEventCoordinates) | ||
XCTAssertEqual(calendarEventRSVP.status, .accepted) | ||
XCTAssertEqual(calendarEventRSVP.freebusy, .busy) | ||
XCTAssertEqual(calendarEventRSVP.content, note) | ||
|
||
let expectedReplaceableEventCoordinates = try XCTUnwrap(EventCoordinates(kind: .calendarEventRSVP, pubkey: Keypair.test.publicKey, identifier: identifier)) | ||
XCTAssertEqual(calendarEventRSVP.replaceableEventCoordinates(relayURL: nil), expectedReplaceableEventCoordinates) | ||
|
||
try verifyEvent(calendarEventRSVP) | ||
} | ||
|
||
func testCreateTimeBasedCalendarEventRSVP() throws { | ||
let startTimeZone = TimeZone(identifier: "America/New_York") | ||
let startComponents = DateComponents(calendar: Calendar(identifier: .iso8601), timeZone: startTimeZone, year: 2023, month: 12, day: 20, hour: 8, minute: 0) | ||
let startDate = try XCTUnwrap(startComponents.date) | ||
let timeBasedCalendarEvent = try timeBasedCalendarEvent(title: "Hockey Practice", startTimestamp: startDate, signedBy: Keypair.test) | ||
let timeBasedCalendarEventCoordinates = try XCTUnwrap(timeBasedCalendarEvent.replaceableEventCoordinates(relayURL: nil)) | ||
|
||
let identifier = "hockey-practice-rsvp" | ||
let note = "Don't forget your skates!" | ||
let calendarEventRSVP = try calendarEventRSVP(withIdentifier: identifier, calendarEventCoordinates: timeBasedCalendarEventCoordinates, status: .accepted, freebusy: .busy, note: note, signedBy: Keypair.test) | ||
|
||
XCTAssertEqual(calendarEventRSVP.identifier, identifier) | ||
XCTAssertEqual(calendarEventRSVP.calendarEventCoordinates, timeBasedCalendarEventCoordinates) | ||
XCTAssertEqual(calendarEventRSVP.status, .accepted) | ||
XCTAssertEqual(calendarEventRSVP.freebusy, .busy) | ||
XCTAssertEqual(calendarEventRSVP.content, note) | ||
|
||
let expectedReplaceableEventCoordinates = try XCTUnwrap(EventCoordinates(kind: .calendarEventRSVP, pubkey: Keypair.test.publicKey, identifier: identifier)) | ||
XCTAssertEqual(calendarEventRSVP.replaceableEventCoordinates(relayURL: nil), expectedReplaceableEventCoordinates) | ||
|
||
try verifyEvent(calendarEventRSVP) | ||
} | ||
|
||
func testCreateCalendarEventRSVPWithInvalidCalendarEventCoordinatesShouldFail() throws { | ||
let identifier = "hockey-practice-rsvp" | ||
let note = "Don't forget your skates!" | ||
let eventCoordinates = try XCTUnwrap(EventCoordinates(kind: .longformContent, pubkey: Keypair.test.publicKey, identifier: "abc")) | ||
|
||
XCTAssertThrowsError(try calendarEventRSVP(withIdentifier: identifier, calendarEventCoordinates: eventCoordinates, status: .accepted, freebusy: .busy, note: note, signedBy: Keypair.test)) | ||
} | ||
|
||
func testCreateCalendarEventRSVPWithDeclineAndNoFreebusy() throws { | ||
let startTimeZone = TimeZone(identifier: "America/New_York") | ||
let startComponents = DateComponents(calendar: Calendar(identifier: .iso8601), timeZone: startTimeZone, year: 2023, month: 12, day: 20, hour: 8, minute: 0) | ||
let startDate = try XCTUnwrap(startComponents.date) | ||
let timeBasedCalendarEvent = try timeBasedCalendarEvent(title: "Hockey Practice", startTimestamp: startDate, signedBy: Keypair.test) | ||
let timeBasedCalendarEventCoordinates = try XCTUnwrap(timeBasedCalendarEvent.replaceableEventCoordinates(relayURL: nil)) | ||
|
||
let identifier = "hockey-practice-rsvp" | ||
let calendarEventRSVP = try calendarEventRSVP(withIdentifier: identifier, calendarEventCoordinates: timeBasedCalendarEventCoordinates, status: .declined, signedBy: Keypair.test) | ||
|
||
XCTAssertEqual(calendarEventRSVP.identifier, identifier) | ||
XCTAssertEqual(calendarEventRSVP.calendarEventCoordinates, timeBasedCalendarEventCoordinates) | ||
XCTAssertEqual(calendarEventRSVP.status, .declined) | ||
XCTAssertNil(calendarEventRSVP.freebusy) | ||
|
||
try verifyEvent(calendarEventRSVP) | ||
} | ||
|
||
func testCreateCalendarEventRSVPWithDeclineAndFreebusyShouldFail() throws { | ||
let startTimeZone = TimeZone(identifier: "America/New_York") | ||
let startComponents = DateComponents(calendar: Calendar(identifier: .iso8601), timeZone: startTimeZone, year: 2023, month: 12, day: 20, hour: 8, minute: 0) | ||
let startDate = try XCTUnwrap(startComponents.date) | ||
let timeBasedCalendarEvent = try timeBasedCalendarEvent(title: "Hockey Practice", startTimestamp: startDate, signedBy: Keypair.test) | ||
let timeBasedCalendarEventCoordinates = try XCTUnwrap(timeBasedCalendarEvent.replaceableEventCoordinates(relayURL: nil)) | ||
|
||
let identifier = "hockey-practice-rsvp" | ||
XCTAssertThrowsError(try calendarEventRSVP(withIdentifier: identifier, calendarEventCoordinates: timeBasedCalendarEventCoordinates, status: .declined, freebusy: .busy, signedBy: Keypair.test)) | ||
} | ||
|
||
func testDecodeCalendarEventRSVP() throws { | ||
let event: CalendarEventRSVP = try decodeFixture(filename: "calendar_event_rsvp") | ||
|
||
XCTAssertEqual(event.id, "1ec761bbeacd17f4ca961668725ea85a9001a0f56da37eb424856a9de1188a2d") | ||
XCTAssertEqual(event.pubkey, "9947f9659dd80c3682402b612f5447e28249997fb3709500c32a585eb0977340") | ||
XCTAssertEqual(event.kind, .calendarEventRSVP) | ||
XCTAssertEqual(event.signature, "21c58b1d759c6470cbb1931653d3c44cbc24c87be9632b794b2c4bb3a0abd27117dd9e3c8c90cf669a6f0d8204f20f92c2a20ed832a54d999d010402d2b1aa9a") | ||
XCTAssertEqual(event.createdAt, 1703052002) | ||
XCTAssertEqual(event.content, "Don't forget your skates!") | ||
XCTAssertEqual(event.identifier, "hockey-practice-rsvp") | ||
XCTAssertEqual(event.status, .accepted) | ||
XCTAssertEqual(event.freebusy, .busy) | ||
|
||
let pubkey = try XCTUnwrap(PublicKey(hex: "9947f9659dd80c3682402b612f5447e28249997fb3709500c32a585eb0977340")) | ||
let dateBasedCalendarEventCoordinates = try XCTUnwrap(EventCoordinates(kind: .dateBasedCalendarEvent, pubkey: pubkey, identifier: "D1D48740-2CF8-4483-B5F0-1E83F6D7EC50")) | ||
|
||
XCTAssertEqual(event.calendarEventCoordinates, dateBasedCalendarEventCoordinates) | ||
} | ||
|
||
} |
88 changes: 88 additions & 0 deletions
88
Tests/NostrSDKTests/Events/Calendars/CalendarListEventTests.swift
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 |
---|---|---|
@@ -0,0 +1,88 @@ | ||
// | ||
// CalendarListEventTests.swift | ||
// | ||
// | ||
// Created by Terry Yiu on 4/14/24. | ||
// | ||
|
||
@testable import NostrSDK | ||
import XCTest | ||
|
||
final class CalendarListEventTests: XCTestCase, EventCreating, EventVerifying, FixtureLoading { | ||
|
||
func testCreateCalendarListEvent() throws { | ||
let timeOmittedStartDate = try XCTUnwrap(TimeOmittedDate(year: 2023, month: 12, day: 31)) | ||
let dateBasedCalendarEvent = try XCTUnwrap(dateBasedCalendarEvent(title: "New Year's Eve", startDate: timeOmittedStartDate, signedBy: Keypair.test)) | ||
let dateBasedCalendarEventCoordinates = try XCTUnwrap(dateBasedCalendarEvent.replaceableEventCoordinates(relayURL: nil)) | ||
|
||
let startTimeZone = TimeZone(identifier: "America/New_York") | ||
let startComponents = DateComponents(calendar: Calendar(identifier: .iso8601), timeZone: startTimeZone, year: 2023, month: 12, day: 20, hour: 8, minute: 0) | ||
let startDate = try XCTUnwrap(startComponents.date) | ||
let timeBasedCalendarEvent = try timeBasedCalendarEvent(title: "Hockey Practice", startTimestamp: startDate, signedBy: Keypair.test) | ||
let timeBasedCalendarEventCoordinates = try XCTUnwrap(timeBasedCalendarEvent.replaceableEventCoordinates(relayURL: nil)) | ||
|
||
let identifier = "family-calendar" | ||
let title = "Family Calendar" | ||
let description = "All family events." | ||
let calendar = try calendarListEvent(withIdentifier: identifier, title: title, description: description, calendarEventsCoordinates: [dateBasedCalendarEventCoordinates, timeBasedCalendarEventCoordinates], signedBy: Keypair.test) | ||
|
||
XCTAssertEqual(calendar.identifier, identifier) | ||
XCTAssertEqual(calendar.title, title) | ||
XCTAssertEqual(calendar.content, description) | ||
XCTAssertEqual(calendar.calendarEventCoordinateList, [dateBasedCalendarEventCoordinates, timeBasedCalendarEventCoordinates]) | ||
|
||
let expectedReplaceableEventCoordinates = try XCTUnwrap(EventCoordinates(kind: .calendar, pubkey: Keypair.test.publicKey, identifier: identifier)) | ||
XCTAssertEqual(calendar.replaceableEventCoordinates(relayURL: nil), expectedReplaceableEventCoordinates) | ||
|
||
try verifyEvent(calendar) | ||
} | ||
|
||
func testCreateCalendarListEventWithNoCalendarEventCoordinates() throws { | ||
let identifier = "family-calendar" | ||
let title = "Family Calendar" | ||
let description = "All family events." | ||
let calendar = try calendarListEvent(withIdentifier: identifier, title: title, description: description, calendarEventsCoordinates: [], signedBy: Keypair.test) | ||
|
||
XCTAssertEqual(calendar.identifier, identifier) | ||
XCTAssertEqual(calendar.title, title) | ||
XCTAssertEqual(calendar.content, description) | ||
XCTAssertEqual(calendar.calendarEventCoordinateList, []) | ||
|
||
try verifyEvent(calendar) | ||
} | ||
|
||
func testCreateCalendarListEventWithInvalidCalendarEventCoordinatesShouldFail() throws { | ||
let identifier = "family-calendar" | ||
let title = "Family Calendar" | ||
let description = "All family events." | ||
let eventCoordinates = try XCTUnwrap(EventCoordinates(kind: .longformContent, pubkey: Keypair.test.publicKey, identifier: "abc")) | ||
|
||
XCTAssertThrowsError(try calendarListEvent(withIdentifier: identifier, title: title, description: description, calendarEventsCoordinates: [eventCoordinates], signedBy: Keypair.test)) | ||
} | ||
|
||
func testDecodeCalendarListEvent() throws { | ||
let event: CalendarListEvent = try decodeFixture(filename: "calendar") | ||
|
||
XCTAssertEqual(event.id, "1dc8b913d9d4f50a71182dc9232996d6fbc69e8c955866e43ef2c2e35185bbfa") | ||
XCTAssertEqual(event.pubkey, "9947f9659dd80c3682402b612f5447e28249997fb3709500c32a585eb0977340") | ||
XCTAssertEqual(event.kind, .calendar) | ||
XCTAssertEqual(event.signature, "24c397594fe6d8b5590ce4e7163990f4269bc515d1181487d722730144ac32e8439954d66e88f3232ad807e8d06f01791b5856ae249b139b1469df58045252a9") | ||
XCTAssertEqual(event.createdAt, 1703052671) | ||
XCTAssertEqual(event.identifier, "family-calendar") | ||
XCTAssertEqual(event.title, "Family Calendar") | ||
XCTAssertEqual(event.content, "All family events.") | ||
|
||
let pubkey = try XCTUnwrap(PublicKey(hex: "9947f9659dd80c3682402b612f5447e28249997fb3709500c32a585eb0977340")) | ||
let dateBasedCalendarEventCoordinates = try XCTUnwrap(EventCoordinates(kind: .dateBasedCalendarEvent, pubkey: pubkey, identifier: "D5EB0A5A-0B36-44DB-95C3-DB51799894E6")) | ||
let timeBasedCalendarEventCoordinates = try XCTUnwrap(EventCoordinates(kind: .timeBasedCalendarEvent, pubkey: pubkey, identifier: "1D355ED3-A45D-41A9-B3A5-709211794EFB")) | ||
|
||
XCTAssertEqual( | ||
event.calendarEventCoordinateList, | ||
[ | ||
dateBasedCalendarEventCoordinates, | ||
timeBasedCalendarEventCoordinates | ||
] | ||
) | ||
} | ||
|
||
} |
Oops, something went wrong.