@@ -3,7 +3,13 @@ import { join } from 'path'
33import fs from 'fs'
44import os from 'os'
55
6- import { EventImportLineError , EventImportService , EventImportStats } from '../../../src/services/event-import-service'
6+ import {
7+ createEventBatchPersister ,
8+ EventImportLineError ,
9+ EventImportService ,
10+ EventImportStats ,
11+ } from '../../../src/services/event-import-service'
12+ import { EventDeduplicationMetadataKey , EventKinds , EventTags } from '../../../src/constants/base'
713import { Event } from '../../../src/@types/event'
814import { expect } from 'chai'
915import { getEvents } from '../data/events'
@@ -170,4 +176,36 @@ describe('EventImportService', () => {
170176 expect ( lineErrors . length ) . to . equal ( 0 )
171177 }
172178 } )
179+
180+ it ( 'normalizes parameterized replaceable deduplication to first d tag value' , async ( ) => {
181+ const parameterizedEvent : Event = {
182+ id : 'a' . repeat ( 64 ) ,
183+ pubkey : 'b' . repeat ( 64 ) ,
184+ created_at : 1 ,
185+ kind : EventKinds . PARAMETERIZED_REPLACEABLE_FIRST ,
186+ tags : [ [ EventTags . Deduplication , 'one' , 'two' ] ] ,
187+ content : 'hello' ,
188+ sig : 'c' . repeat ( 128 ) ,
189+ }
190+
191+ let upsertedEvents : Event [ ] = [ ]
192+
193+ const eventRepository = {
194+ create : async ( ) => 0 ,
195+ createMany : async ( ) => 0 ,
196+ upsert : async ( ) => 0 ,
197+ upsertMany : async ( events : Event [ ] ) => {
198+ upsertedEvents = events
199+ return events . length
200+ } ,
201+ deleteByPubkeyAndIds : async ( ) => 0 ,
202+ } as any
203+
204+ const persistBatch = createEventBatchPersister ( eventRepository )
205+ const inserted = await persistBatch ( [ parameterizedEvent ] )
206+
207+ expect ( inserted ) . to . equal ( 1 )
208+ expect ( upsertedEvents ) . to . have . length ( 1 )
209+ expect ( ( upsertedEvents [ 0 ] as any ) [ EventDeduplicationMetadataKey ] ) . to . deep . equal ( [ 'one' ] )
210+ } )
173211} )
0 commit comments