Files
nostr-tools/nip25.test.js
2023-04-23 20:19:52 -03:00

105 lines
2.7 KiB
JavaScript

/* eslint-env jest */
const {nip25, finishEvent, getPublicKey, Kind} = require('./lib/nostr.cjs')
describe('finishReactionEvent + getReactedEventPointer', () => {
const privateKey =
'd217c1ff2f8a65c3e3a1740db3b9f58b8c848bb45e26d00ed4714e4a0f4ceecf'
const publicKey = getPublicKey(privateKey)
const reactedEvent = finishEvent({
kind: Kind.Text,
tags: [
['e', 'replied event id'],
['p', 'replied event pubkey'],
],
content: 'Replied to a post',
created_at: 1617932115
}, privateKey)
it('should create a signed event from a minimal template', () => {
const template = {
created_at: 1617932115
}
const event = nip25.finishReactionEvent(template, reactedEvent, privateKey)
expect(event.kind).toEqual(Kind.Reaction)
expect(event.tags).toEqual([
[
'e',
'replied event id',
],
[
'p',
'replied event pubkey',
],
[
'e',
'0ecdbd4dba0652afb19e5f638257a41552a37995a4438ef63de658443f8d16b1',
],
[
'p',
'6af0f9de588f2c53cedcba26c5e2402e0d0aa64ec7b47c9f8d97b5bc562bab5f',
],
])
expect(event.content).toEqual('+')
expect(event.created_at).toEqual(template.created_at)
expect(event.pubkey).toEqual(publicKey)
expect(typeof event.id).toEqual('string')
expect(typeof event.sig).toEqual('string')
const reactedEventPointer = nip25.getReactedEventPointer(event)
expect(reactedEventPointer.id).toEqual(reactedEvent.id)
expect(reactedEventPointer.author).toEqual(reactedEvent.pubkey)
})
it('should create a signed event from a filled template', () => {
const template = {
tags: [
['nonstandard', 'tag'],
],
content: '👍',
created_at: 1617932115
}
const event = nip25.finishReactionEvent(template, reactedEvent, privateKey)
expect(event.kind).toEqual(Kind.Reaction)
expect(event.tags).toEqual([
[
'nonstandard',
'tag',
],
[
'e',
'replied event id',
],
[
'p',
'replied event pubkey',
],
[
'e',
'0ecdbd4dba0652afb19e5f638257a41552a37995a4438ef63de658443f8d16b1',
],
[
'p',
'6af0f9de588f2c53cedcba26c5e2402e0d0aa64ec7b47c9f8d97b5bc562bab5f',
],
])
expect(event.content).toEqual('👍')
expect(event.created_at).toEqual(template.created_at)
expect(event.pubkey).toEqual(publicKey)
expect(typeof event.id).toEqual('string')
expect(typeof event.sig).toEqual('string')
const reactedEventPointer = nip25.getReactedEventPointer(event)
expect(reactedEventPointer.id).toEqual(reactedEvent.id)
expect(reactedEventPointer.author).toEqual(reactedEvent.pubkey)
})
})