Skip to content

Commit

Permalink
filter: fix tests (remove prefix tests).
Browse files Browse the repository at this point in the history
  • Loading branch information
fiatjaf committed May 19, 2024
1 parent fa31fdc commit 1cd9847
Showing 1 changed file with 0 additions and 41 deletions.
41 changes: 0 additions & 41 deletions filter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,47 +13,28 @@ describe('Filter', () => {
until: 200,
'#tag': ['value'],
}

const event = buildEvent({
id: '123',
kind: 1,
pubkey: 'abc',
created_at: 150,
tags: [['tag', 'value']],
})

const result = matchFilter(filter, event)

expect(result).toEqual(true)
})

test('should return false when the event id is not in the filter', () => {
const filter = { ids: ['123', '456'] }

const event = buildEvent({ id: '789' })

const result = matchFilter(filter, event)

expect(result).toEqual(false)
})

test('should return true when the event id starts with a prefix', () => {
const filter = { ids: ['22', '00'] }

const event = buildEvent({ id: '001' })

const result = matchFilter(filter, event)

expect(result).toEqual(true)
})

test('should return false when the event kind is not in the filter', () => {
const filter = { kinds: [1, 2, 3] }

const event = buildEvent({ kind: 4 })

const result = matchFilter(filter, event)

expect(result).toEqual(false)
})

Expand Down Expand Up @@ -154,25 +135,8 @@ describe('Filter', () => {
{ ids: ['456'], kinds: [2], authors: ['def'] },
{ ids: ['789'], kinds: [3], authors: ['ghi'] },
]

const event = buildEvent({ id: '789', kind: 3, pubkey: 'ghi' })

const result = matchFilters(filters, event)

expect(result).toEqual(true)
})

test('should return true when at least one prefix matches the event', () => {
const filters = [
{ ids: ['1'], kinds: [1], authors: ['a'] },
{ ids: ['4'], kinds: [2], authors: ['d'] },
{ ids: ['9'], kinds: [3], authors: ['g'] },
]

const event = buildEvent({ id: '987', kind: 3, pubkey: 'ghi' })

const result = matchFilters(filters, event)

expect(result).toEqual(true)
})

Expand Down Expand Up @@ -201,11 +165,8 @@ describe('Filter', () => {
{ ids: ['456'], kinds: [2], authors: ['def'] },
{ ids: ['789'], kinds: [3], authors: ['ghi'] },
]

const event = buildEvent({ id: '100', kind: 4, pubkey: 'jkl' })

const result = matchFilters(filters, event)

expect(result).toEqual(false)
})

Expand All @@ -221,9 +182,7 @@ describe('Filter', () => {
pubkey: 'def',
created_at: 200,
})

const result = matchFilters(filters, event)

expect(result).toEqual(false)
})
})
Expand Down

0 comments on commit 1cd9847

Please sign in to comment.