mirror of
https://github.com/nbd-wtf/nostr-tools.git
synced 2025-12-09 00:28:51 +00:00
run prettier on tests.
This commit is contained in:
@@ -6,38 +6,39 @@ const relayUrl = 'https://relay.example.com'
|
|||||||
|
|
||||||
describe('finishRepostEvent + getRepostedEventPointer + getRepostedEvent', () => {
|
describe('finishRepostEvent + getRepostedEventPointer + getRepostedEvent', () => {
|
||||||
const privateKey =
|
const privateKey =
|
||||||
'd217c1ff2f8a65c3e3a1740db3b9f58b8c848bb45e26d00ed4714e4a0f4ceecf'
|
'd217c1ff2f8a65c3e3a1740db3b9f58b8c848bb45e26d00ed4714e4a0f4ceecf'
|
||||||
|
|
||||||
const publicKey = getPublicKey(privateKey)
|
const publicKey = getPublicKey(privateKey)
|
||||||
|
|
||||||
const repostedEvent = finishEvent({
|
const repostedEvent = finishEvent(
|
||||||
kind: Kind.Text,
|
{
|
||||||
tags: [
|
kind: Kind.Text,
|
||||||
['e', 'replied event id'],
|
tags: [
|
||||||
['p', 'replied event pubkey'],
|
['e', 'replied event id'],
|
||||||
],
|
['p', 'replied event pubkey']
|
||||||
content: 'Replied to a post',
|
],
|
||||||
created_at: 1617932115
|
content: 'Replied to a post',
|
||||||
}, privateKey)
|
created_at: 1617932115
|
||||||
|
},
|
||||||
|
privateKey
|
||||||
|
)
|
||||||
|
|
||||||
it('should create a signed event from a minimal template', () => {
|
it('should create a signed event from a minimal template', () => {
|
||||||
const template = {
|
const template = {
|
||||||
created_at: 1617932115
|
created_at: 1617932115
|
||||||
}
|
}
|
||||||
|
|
||||||
const event = nip18.finishRepostEvent(template, repostedEvent, relayUrl, privateKey)
|
const event = nip18.finishRepostEvent(
|
||||||
|
template,
|
||||||
|
repostedEvent,
|
||||||
|
relayUrl,
|
||||||
|
privateKey
|
||||||
|
)
|
||||||
|
|
||||||
expect(event.kind).toEqual(Kind.Repost)
|
expect(event.kind).toEqual(Kind.Repost)
|
||||||
expect(event.tags).toEqual([
|
expect(event.tags).toEqual([
|
||||||
[
|
['e', repostedEvent.id, relayUrl],
|
||||||
'e',
|
['p', repostedEvent.pubkey]
|
||||||
repostedEvent.id,
|
|
||||||
relayUrl,
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'p',
|
|
||||||
repostedEvent.pubkey,
|
|
||||||
],
|
|
||||||
])
|
])
|
||||||
expect(event.content).toEqual(JSON.stringify(repostedEvent))
|
expect(event.content).toEqual(JSON.stringify(repostedEvent))
|
||||||
expect(event.created_at).toEqual(template.created_at)
|
expect(event.created_at).toEqual(template.created_at)
|
||||||
@@ -49,7 +50,7 @@ describe('finishRepostEvent + getRepostedEventPointer + getRepostedEvent', () =>
|
|||||||
|
|
||||||
expect(repostedEventPointer.id).toEqual(repostedEvent.id)
|
expect(repostedEventPointer.id).toEqual(repostedEvent.id)
|
||||||
expect(repostedEventPointer.author).toEqual(repostedEvent.pubkey)
|
expect(repostedEventPointer.author).toEqual(repostedEvent.pubkey)
|
||||||
expect(repostedEventPointer.relays).toEqual([ relayUrl ])
|
expect(repostedEventPointer.relays).toEqual([relayUrl])
|
||||||
|
|
||||||
const repostedEventFromContent = nip18.getRepostedEvent(event)
|
const repostedEventFromContent = nip18.getRepostedEvent(event)
|
||||||
|
|
||||||
@@ -58,30 +59,23 @@ describe('finishRepostEvent + getRepostedEventPointer + getRepostedEvent', () =>
|
|||||||
|
|
||||||
it('should create a signed event from a filled template', () => {
|
it('should create a signed event from a filled template', () => {
|
||||||
const template = {
|
const template = {
|
||||||
tags: [
|
tags: [['nonstandard', 'tag']],
|
||||||
['nonstandard', 'tag'],
|
|
||||||
],
|
|
||||||
content: '',
|
content: '',
|
||||||
created_at: 1617932115
|
created_at: 1617932115
|
||||||
}
|
}
|
||||||
|
|
||||||
const event = nip18.finishRepostEvent(template, repostedEvent, relayUrl, privateKey)
|
const event = nip18.finishRepostEvent(
|
||||||
|
template,
|
||||||
|
repostedEvent,
|
||||||
|
relayUrl,
|
||||||
|
privateKey
|
||||||
|
)
|
||||||
|
|
||||||
expect(event.kind).toEqual(Kind.Repost)
|
expect(event.kind).toEqual(Kind.Repost)
|
||||||
expect(event.tags).toEqual([
|
expect(event.tags).toEqual([
|
||||||
[
|
['nonstandard', 'tag'],
|
||||||
'nonstandard',
|
['e', repostedEvent.id, relayUrl],
|
||||||
'tag',
|
['p', repostedEvent.pubkey]
|
||||||
],
|
|
||||||
[
|
|
||||||
'e',
|
|
||||||
repostedEvent.id,
|
|
||||||
relayUrl,
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'p',
|
|
||||||
repostedEvent.pubkey,
|
|
||||||
],
|
|
||||||
])
|
])
|
||||||
expect(event.content).toEqual('')
|
expect(event.content).toEqual('')
|
||||||
expect(event.created_at).toEqual(template.created_at)
|
expect(event.created_at).toEqual(template.created_at)
|
||||||
@@ -93,7 +87,7 @@ describe('finishRepostEvent + getRepostedEventPointer + getRepostedEvent', () =>
|
|||||||
|
|
||||||
expect(repostedEventPointer.id).toEqual(repostedEvent.id)
|
expect(repostedEventPointer.id).toEqual(repostedEvent.id)
|
||||||
expect(repostedEventPointer.author).toEqual(repostedEvent.pubkey)
|
expect(repostedEventPointer.author).toEqual(repostedEvent.pubkey)
|
||||||
expect(repostedEventPointer.relays).toEqual([ relayUrl ])
|
expect(repostedEventPointer.relays).toEqual([relayUrl])
|
||||||
|
|
||||||
const repostedEventFromContent = nip18.getRepostedEvent(event)
|
const repostedEventFromContent = nip18.getRepostedEvent(event)
|
||||||
|
|
||||||
@@ -105,15 +99,13 @@ describe('getRepostedEventPointer', () => {
|
|||||||
it('should parse an event with only an `e` tag', () => {
|
it('should parse an event with only an `e` tag', () => {
|
||||||
const event = {
|
const event = {
|
||||||
kind: Kind.Repost,
|
kind: Kind.Repost,
|
||||||
tags: [
|
tags: [['e', 'reposted event id', relayUrl]]
|
||||||
['e', 'reposted event id', relayUrl],
|
|
||||||
],
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const repostedEventPointer = nip18.getRepostedEventPointer(event)
|
const repostedEventPointer = nip18.getRepostedEventPointer(event)
|
||||||
|
|
||||||
expect(repostedEventPointer.id).toEqual('reposted event id')
|
expect(repostedEventPointer.id).toEqual('reposted event id')
|
||||||
expect(repostedEventPointer.author).toEqual(undefined)
|
expect(repostedEventPointer.author).toEqual(undefined)
|
||||||
expect(repostedEventPointer.relays).toEqual([ relayUrl ])
|
expect(repostedEventPointer.relays).toEqual([relayUrl])
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -102,7 +102,7 @@ test('decode naddr from go-nostr with different TLV ordering', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
test('encode and decode nrelay', () => {
|
test('encode and decode nrelay', () => {
|
||||||
let url = "wss://relay.nostr.example"
|
let url = 'wss://relay.nostr.example'
|
||||||
let nrelay = nip19.nrelayEncode(url)
|
let nrelay = nip19.nrelayEncode(url)
|
||||||
expect(nrelay).toMatch(/nrelay1\w+/)
|
expect(nrelay).toMatch(/nrelay1\w+/)
|
||||||
let {type, data} = nip19.decode(nrelay)
|
let {type, data} = nip19.decode(nrelay)
|
||||||
|
|||||||
@@ -4,19 +4,22 @@ const {nip25, finishEvent, getPublicKey, Kind} = require('./lib/nostr.cjs')
|
|||||||
|
|
||||||
describe('finishReactionEvent + getReactedEventPointer', () => {
|
describe('finishReactionEvent + getReactedEventPointer', () => {
|
||||||
const privateKey =
|
const privateKey =
|
||||||
'd217c1ff2f8a65c3e3a1740db3b9f58b8c848bb45e26d00ed4714e4a0f4ceecf'
|
'd217c1ff2f8a65c3e3a1740db3b9f58b8c848bb45e26d00ed4714e4a0f4ceecf'
|
||||||
|
|
||||||
const publicKey = getPublicKey(privateKey)
|
const publicKey = getPublicKey(privateKey)
|
||||||
|
|
||||||
const reactedEvent = finishEvent({
|
const reactedEvent = finishEvent(
|
||||||
kind: Kind.Text,
|
{
|
||||||
tags: [
|
kind: Kind.Text,
|
||||||
['e', 'replied event id'],
|
tags: [
|
||||||
['p', 'replied event pubkey'],
|
['e', 'replied event id'],
|
||||||
],
|
['p', 'replied event pubkey']
|
||||||
content: 'Replied to a post',
|
],
|
||||||
created_at: 1617932115
|
content: 'Replied to a post',
|
||||||
}, privateKey)
|
created_at: 1617932115
|
||||||
|
},
|
||||||
|
privateKey
|
||||||
|
)
|
||||||
|
|
||||||
it('should create a signed event from a minimal template', () => {
|
it('should create a signed event from a minimal template', () => {
|
||||||
const template = {
|
const template = {
|
||||||
@@ -27,22 +30,10 @@ describe('finishReactionEvent + getReactedEventPointer', () => {
|
|||||||
|
|
||||||
expect(event.kind).toEqual(Kind.Reaction)
|
expect(event.kind).toEqual(Kind.Reaction)
|
||||||
expect(event.tags).toEqual([
|
expect(event.tags).toEqual([
|
||||||
[
|
['e', 'replied event id'],
|
||||||
'e',
|
['p', 'replied event pubkey'],
|
||||||
'replied event id',
|
['e', '0ecdbd4dba0652afb19e5f638257a41552a37995a4438ef63de658443f8d16b1'],
|
||||||
],
|
['p', '6af0f9de588f2c53cedcba26c5e2402e0d0aa64ec7b47c9f8d97b5bc562bab5f']
|
||||||
[
|
|
||||||
'p',
|
|
||||||
'replied event pubkey',
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'e',
|
|
||||||
'0ecdbd4dba0652afb19e5f638257a41552a37995a4438ef63de658443f8d16b1',
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'p',
|
|
||||||
'6af0f9de588f2c53cedcba26c5e2402e0d0aa64ec7b47c9f8d97b5bc562bab5f',
|
|
||||||
],
|
|
||||||
])
|
])
|
||||||
expect(event.content).toEqual('+')
|
expect(event.content).toEqual('+')
|
||||||
expect(event.created_at).toEqual(template.created_at)
|
expect(event.created_at).toEqual(template.created_at)
|
||||||
@@ -58,9 +49,7 @@ describe('finishReactionEvent + getReactedEventPointer', () => {
|
|||||||
|
|
||||||
it('should create a signed event from a filled template', () => {
|
it('should create a signed event from a filled template', () => {
|
||||||
const template = {
|
const template = {
|
||||||
tags: [
|
tags: [['nonstandard', 'tag']],
|
||||||
['nonstandard', 'tag'],
|
|
||||||
],
|
|
||||||
content: '👍',
|
content: '👍',
|
||||||
created_at: 1617932115
|
created_at: 1617932115
|
||||||
}
|
}
|
||||||
@@ -69,26 +58,11 @@ describe('finishReactionEvent + getReactedEventPointer', () => {
|
|||||||
|
|
||||||
expect(event.kind).toEqual(Kind.Reaction)
|
expect(event.kind).toEqual(Kind.Reaction)
|
||||||
expect(event.tags).toEqual([
|
expect(event.tags).toEqual([
|
||||||
[
|
['nonstandard', 'tag'],
|
||||||
'nonstandard',
|
['e', 'replied event id'],
|
||||||
'tag',
|
['p', 'replied event pubkey'],
|
||||||
],
|
['e', '0ecdbd4dba0652afb19e5f638257a41552a37995a4438ef63de658443f8d16b1'],
|
||||||
[
|
['p', '6af0f9de588f2c53cedcba26c5e2402e0d0aa64ec7b47c9f8d97b5bc562bab5f']
|
||||||
'e',
|
|
||||||
'replied event id',
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'p',
|
|
||||||
'replied event pubkey',
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'e',
|
|
||||||
'0ecdbd4dba0652afb19e5f638257a41552a37995a4438ef63de658443f8d16b1',
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'p',
|
|
||||||
'6af0f9de588f2c53cedcba26c5e2402e0d0aa64ec7b47c9f8d97b5bc562bab5f',
|
|
||||||
],
|
|
||||||
])
|
])
|
||||||
expect(event.content).toEqual('👍')
|
expect(event.content).toEqual('👍')
|
||||||
expect(event.created_at).toEqual(template.created_at)
|
expect(event.created_at).toEqual(template.created_at)
|
||||||
|
|||||||
Reference in New Issue
Block a user