mirror of
https://github.com/nbd-wtf/nostr-tools.git
synced 2025-12-08 16:28:49 +00:00
add a bunch of tests.
This commit is contained in:
42
filter.test.js
Normal file
42
filter.test.js
Normal file
@@ -0,0 +1,42 @@
|
||||
/* eslint-env jest */
|
||||
|
||||
const {matchFilters} = require('./cjs')
|
||||
|
||||
test('test if filters match', () => {
|
||||
;[
|
||||
{
|
||||
filters: [{ids: ['i']}],
|
||||
good: [{id: 'i'}],
|
||||
bad: [{id: 'j'}]
|
||||
},
|
||||
{
|
||||
filters: [{authors: ['abc']}, {kinds: [1, 3]}],
|
||||
good: [
|
||||
{pubkey: 'xyz', kind: 3},
|
||||
{pubkey: 'abc', kind: 12},
|
||||
{pubkey: 'abc', kind: 1}
|
||||
],
|
||||
bad: [{pubkey: 'hhh', kind: 12}]
|
||||
},
|
||||
{
|
||||
filters: [{'#e': ['yyy'], since: 444}],
|
||||
good: [
|
||||
{
|
||||
tags: [
|
||||
['e', 'uuu'],
|
||||
['e', 'yyy']
|
||||
],
|
||||
created_at: 555
|
||||
}
|
||||
],
|
||||
bad: [{tags: [['e', 'uuu']], created_at: 111}]
|
||||
}
|
||||
].forEach(({filters, good, bad}) => {
|
||||
good.forEach(ev => {
|
||||
expect(matchFilters(filters, ev)).toBeTruthy()
|
||||
})
|
||||
bad.forEach(ev => {
|
||||
expect(matchFilters(filters, ev)).toBeFalsy()
|
||||
})
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user