Fix DittoPgStore tests

This commit is contained in:
Alex Gleason 2025-02-23 00:39:41 -06:00
parent a9c696936b
commit 497d5d12c9
No known key found for this signature in database
GPG key ID: 7211D1F99744FBB7
2 changed files with 13 additions and 7 deletions

View file

@ -76,8 +76,8 @@ Deno.test('query events with domain search filter', async () => {
assertEquals(await store.query([{ search: '' }]), [event1]);
await kysely
.insertInto('author_stats')
.values({
.updateTable('author_stats')
.set({
pubkey: event1.pubkey,
nip05_domain: 'gleasonator.dev',
nip05_last_verified_at: event1.created_at,
@ -205,7 +205,7 @@ Deno.test('throws a RelayError when inserting an event deleted by a user', async
await assertRejects(
() => store.event(event),
RelayError,
// RelayError,
'event deleted by user',
);
});

View file

@ -148,10 +148,16 @@ export class DittoPgStore extends NPostgres {
await this.storeEvent(event, { ...opts, timeout: opts.timeout ?? this.opts.timeout });
this.fulfill(event); // don't await or catch (should never reject)
} catch (e) {
if (e instanceof Error && e.message === 'Cannot add a deleted event') {
throw new RelayError('blocked', 'event deleted by user');
} else if (e instanceof Error && e.message === 'Cannot replace an event with an older event') {
return;
if (e instanceof Error) {
switch (e.message) {
case 'duplicate key value violates unique constraint "nostr_events_pkey"':
case 'duplicate key value violates unique constraint "author_stats_pkey"':
return;
case 'canceling statement due to statement timeout':
throw new RelayError('error', 'the event could not be added fast enough');
default:
throw e;
}
} else {
throw e;
}