@@ -3,6 +3,7 @@ import { expect } from 'chai'
33import WebSocket from 'ws'
44
55import { createEvent , sendEvent , waitForEventCount , waitForNextEvent } from '../helpers'
6+ import { EventKinds , EventTags } from '../../../../src/constants/base'
67import { Event } from '../../../../src/@types/event'
78
89When ( / ^ ( \w + ) s e n d s a p a r a m e t e r i z e d _ 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 " ( [ ^ " ] + ) " a n d t a g ( \w ) c o n t a i n i n g " ( [ ^ " ] + ) " $ / , async function (
@@ -20,6 +21,52 @@ When(/^(\w+) sends a parameterized_replaceable_event_0 event with content "([^"]
2021 this . parameters . events [ name ] . push ( event )
2122} )
2223
24+ When ( / ^ ( \w + ) s e n d s a p a r a m e t e r i z e d _ r e p l a c e a b l e _ e v e n t _ 1 e v e n t w i t h c o n t e n t " ( [ ^ " ] + ) " a n d t a g ( \w ) c o n t a i n i n g " ( [ ^ " ] + ) " $ / , async function (
25+ name : string ,
26+ content : string ,
27+ tag : string ,
28+ value : string ,
29+ ) {
30+ const ws = this . parameters . clients [ name ] as WebSocket
31+ const { pubkey, privkey } = this . parameters . identities [ name ]
32+
33+ const event : Event = await createEvent (
34+ {
35+ pubkey,
36+ kind : EventKinds . PARAMETERIZED_REPLACEABLE_FIRST + 1 ,
37+ content,
38+ tags : [ [ tag , value ] ] ,
39+ } ,
40+ privkey ,
41+ )
42+
43+ await sendEvent ( ws , event )
44+ this . parameters . events [ name ] . push ( event )
45+ } )
46+
47+ When ( / ^ ( \w + ) s e n d s a p a r a m e t e r i z e d _ r e p l a c e a b l e _ e v e n t _ 1 e v e n t w i t h c o n t e n t " ( [ ^ " ] + ) " a n d t a g ( \w ) c o n t a i n i n g " ( [ ^ " ] + ) " a n d e x p i r i n g i n t h e f u t u r e $ / , async function (
48+ name : string ,
49+ content : string ,
50+ tag : string ,
51+ value : string ,
52+ ) {
53+ const ws = this . parameters . clients [ name ] as WebSocket
54+ const { pubkey, privkey } = this . parameters . identities [ name ]
55+
56+ const event : Event = await createEvent (
57+ {
58+ pubkey,
59+ kind : EventKinds . PARAMETERIZED_REPLACEABLE_FIRST + 1 ,
60+ content,
61+ tags : [ [ tag , value ] , [ EventTags . Expiration , Math . floor ( new Date ( ) . getTime ( ) / 1000 + 10 ) . toString ( ) ] ] ,
62+ } ,
63+ privkey ,
64+ )
65+
66+ await sendEvent ( ws , event )
67+ this . parameters . events [ name ] . push ( event )
68+ } )
69+
2370Then (
2471 / ( \w + ) r e c e i v e s a p a r a m e t e r i z e 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 + ) w i t h c o n t e n t " ( [ ^ " ] + ?) " a n d t a g ( \w + ) c o n t a i n i n g " ( [ ^ " ] + ?) " / ,
2572 async function ( name : string , author : string , content : string , tagName : string , tagValue : string ) {
3380 expect ( receivedEvent . tags [ 0 ] ) . to . deep . equal ( [ tagName , tagValue ] )
3481} )
3582
83+ Then (
84+ / ( \w + ) r e c e i v e s a p a r a m e t e r i z e d _ r e p l a c e a b l e _ e v e n t _ 1 e v e n t f r o m ( \w + ) w i t h c o n t e n t " ( [ ^ " ] + ?) " a n d t a g ( \w + ) c o n t a i n i n g " ( [ ^ " ] + ?) " / ,
85+ async function ( name : string , author : string , content : string , tagName : string , tagValue : string ) {
86+ const ws = this . parameters . clients [ name ] as WebSocket
87+ const subscription = this . parameters . subscriptions [ name ] [ this . parameters . subscriptions [ name ] . length - 1 ]
88+ const receivedEvent = await waitForNextEvent ( ws , subscription . name )
89+
90+ expect ( receivedEvent . kind ) . to . equal ( 30001 )
91+ expect ( receivedEvent . pubkey ) . to . equal ( this . parameters . identities [ author ] . pubkey )
92+ expect ( receivedEvent . content ) . to . equal ( content )
93+ expect ( receivedEvent . tags [ 0 ] ) . to . deep . equal ( [ tagName , tagValue ] )
94+ } )
95+
3696Then ( / ( \w + ) r e c e i v e s ( \d + ) p a r a m e t e r i z 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 ? 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 (
3797 name : string ,
3898 count : string ,
0 commit comments