@@ -5,7 +5,7 @@ import WebSocket from 'ws'
55import { createEvent , sendEvent , waitForEventCount , waitForNextEvent } from '../helpers'
66import { Event } from '../../../../src/@types/event'
77
8- When ( / ^ ( \w + ) s e n d s a r e p l a c e a b l e _ e v e n t _ 0 e v e n t w i t h c o n t e n t " ( [ ^ " ] + ) " $ / , async function (
8+ When ( / ^ ( \w + ) s e n d s a r e p l a c e a b l e _ e v e n t _ 0 e v e n t w i t h c o n t e n t " ( [ ^ " ] + ) " $ / , async function (
99 name : string ,
1010 content : string ,
1111) {
@@ -20,17 +20,17 @@ When(/^(\w+) sends a replaceable_event_0 event with content "([^"]+)"$/, async f
2020
2121Then (
2222 / ( \w + ) r e c e i v e s a r e p l a c e a b l e _ e v e n t _ 0 e v e n t f r o m ( \w + ) w i t h c o n t e n t " ( [ ^ " ] + ?) " / ,
23- async function ( name : string , author : string , content : string ) {
24- const ws = this . parameters . clients [ name ] as WebSocket
25- const subscription = this . parameters . subscriptions [ name ] [ this . parameters . subscriptions [ name ] . length - 1 ]
26- const receivedEvent = await waitForNextEvent ( ws , subscription . name )
23+ async function ( name : string , author : string , content : string ) {
24+ const ws = this . parameters . clients [ name ] as WebSocket
25+ const subscription = this . parameters . subscriptions [ name ] [ this . parameters . subscriptions [ name ] . length - 1 ]
26+ const receivedEvent = await waitForNextEvent ( ws , subscription . name )
2727
28- expect ( receivedEvent . kind ) . to . equal ( 10000 )
29- expect ( receivedEvent . pubkey ) . to . equal ( this . parameters . identities [ author ] . pubkey )
30- expect ( receivedEvent . content ) . to . equal ( content )
31- } )
28+ expect ( receivedEvent . kind ) . to . equal ( 10000 )
29+ expect ( receivedEvent . pubkey ) . to . equal ( this . parameters . identities [ author ] . pubkey )
30+ expect ( receivedEvent . content ) . to . equal ( content )
31+ } )
3232
33- Then ( / ( \w + ) r e c e i v e s ( \d + ) r e p l a c e a b l e _ e v e n t _ 0 e v e n t s ? f r o m ( \w + ) w i t h c o n t e n t " ( [ ^ " ] + ?) " a n d E O S E / , async function (
33+ Then ( / ( \w + ) r e c e i v e s ( \d + ) r e p l a c e a b l e _ e v e n t _ 0 e v e n t s ? f r o m ( \w + ) w i t h c o n t e n t " ( [ ^ " ] + ?) " a n d E O S E / , async function (
3434 name : string ,
3535 count : string ,
3636 author : string ,
@@ -46,7 +46,7 @@ Then(/(\w+) receives (\d+) replaceable_event_0 events? from (\w+) with content "
4646 expect ( events [ 0 ] . content ) . to . equal ( content )
4747} )
4848
49- When ( / ^ ( \w + ) s e n d s a e p h e m e r a l _ e v e n t _ 0 e v e n t w i t h c o n t e n t " ( [ ^ " ] + ) " $ / , async function (
49+ When ( / ^ ( \w + ) s e n d s a e p h e m e r a l _ e v e n t _ 0 e v e n t w i t h c o n t e n t " ( [ ^ " ] + ) " $ / , async function (
5050 name : string ,
5151 content : string ,
5252) {
@@ -61,23 +61,66 @@ When(/^(\w+) sends a ephemeral_event_0 event with content "([^"]+)"$/, async fun
6161
6262Then (
6363 / ( \w + ) r e c e i v e s a e p h e m e r a l _ e v e n t _ 0 e v e n t f r o m ( \w + ) w i t h c o n t e n t " ( [ ^ " ] + ?) " / ,
64- async function ( name : string , author : string , content : string ) {
64+ async function ( name : string , author : string , content : string ) {
65+ const ws = this . parameters . clients [ name ] as WebSocket
66+ const subscription = this . parameters . subscriptions [ name ] [ this . parameters . subscriptions [ name ] . length - 1 ]
67+ const receivedEvent = await waitForNextEvent ( ws , subscription . name )
68+
69+ expect ( receivedEvent . kind ) . to . equal ( 20000 )
70+ expect ( receivedEvent . pubkey ) . to . equal ( this . parameters . identities [ author ] . pubkey )
71+ expect ( receivedEvent . content ) . to . equal ( content )
72+ } )
73+
74+ Then ( / ( \w + ) r e c e i v e s ( \d + ) e p h e m e r a l _ e v e n t _ 0 e v e n t s ? a n d E O S E / , async function (
75+ name : string ,
76+ count : string ,
77+ ) {
6578 const ws = this . parameters . clients [ name ] as WebSocket
6679 const subscription = this . parameters . subscriptions [ name ] [ this . parameters . subscriptions [ name ] . length - 1 ]
67- const receivedEvent = await waitForNextEvent ( ws , subscription . name )
80+ const events = await waitForEventCount ( ws , subscription . name , Number ( count ) , true )
6881
69- expect ( receivedEvent . kind ) . to . equal ( 20000 )
70- expect ( receivedEvent . pubkey ) . to . equal ( this . parameters . identities [ author ] . pubkey )
71- expect ( receivedEvent . content ) . to . equal ( content )
82+ expect ( events . length ) . to . equal ( Number ( count ) )
7283} )
7384
74- Then ( / ( \w + ) r e c e i v e s ( \d + ) e p h e m e r a l _ e v e n t _ 0 e v e n t s ? a n d E O S E / , async function (
85+ When ( / ^ ( \w + ) s e n d s t w o i d e n t i c a l l y - t i m e s t a m p e d r e p l a c e a b l e _ e v e n t _ 0 e v e n t s w h e r e t h e s e c o n d h a s a l o w e r I D $ / , async function (
86+ name : string
87+ ) {
88+ const ws = this . parameters . clients [ name ] as WebSocket
89+ const { pubkey, privkey } = this . parameters . identities [ name ]
90+
91+ const commonTimestamp = Math . floor ( Date . now ( ) / 1000 )
92+
93+ const event1 = await createEvent ( { pubkey, kind : 10000 , content : 'first content' , created_at : commonTimestamp } , privkey )
94+
95+ let nonce = 0
96+ let event2 : Event
97+ for ( ; ; ) {
98+ event2 = await createEvent ( { pubkey, kind : 10000 , content : `second content ${ nonce ++ } ` , created_at : commonTimestamp } , privkey )
99+
100+ if ( event2 . id < event1 . id ) {
101+ break
102+ }
103+ }
104+
105+ await sendEvent ( ws , event1 )
106+ await sendEvent ( ws , event2 )
107+
108+ this . parameters . events [ name ] . push ( event1 , event2 )
109+ this . parameters . lowerIdEventContent = event2 . content
110+ } )
111+
112+ Then ( / ( \w + ) r e c e i v e s ( \d + ) r e p l a c e a b l e _ e v e n t _ 0 e v e n t f r o m ( \w + ) m a t c h i n g t h e l o w e r I D e v e n t a n d E O S E / , async function (
75113 name : string ,
76114 count : string ,
115+ author : string ,
77116) {
78117 const ws = this . parameters . clients [ name ] as WebSocket
79118 const subscription = this . parameters . subscriptions [ name ] [ this . parameters . subscriptions [ name ] . length - 1 ]
80119 const events = await waitForEventCount ( ws , subscription . name , Number ( count ) , true )
81120
82121 expect ( events . length ) . to . equal ( Number ( count ) )
122+ expect ( events [ 0 ] . kind ) . to . equal ( 10000 )
123+ expect ( events [ 0 ] . pubkey ) . to . equal ( this . parameters . identities [ author ] . pubkey )
124+ expect ( events [ 0 ] . content ) . to . equal ( this . parameters . lowerIdEventContent )
83125} )
126+
0 commit comments