mirror of
https://github.com/Cameri/nostream.git
synced 2025-04-08 20:08:07 +02:00
test: add more intg tests
This commit is contained in:
parent
55df03df73
commit
ee1a1c8ba9
@ -70,10 +70,10 @@ export class SettingsStatic {
|
||||
}
|
||||
|
||||
public static createSettings(): ISettings {
|
||||
debug('creating settings')
|
||||
if (SettingsStatic._settings) {
|
||||
return SettingsStatic._settings
|
||||
}
|
||||
debug('creating settings')
|
||||
const path = SettingsStatic.getSettingsFilePath()
|
||||
const defaults = SettingsStatic.getDefaultSettings()
|
||||
try {
|
||||
|
@ -1,30 +1,37 @@
|
||||
Feature: NIP-01
|
||||
Scenario: Alice gets an event by ID
|
||||
Given someone called Alice
|
||||
And someone called Bob
|
||||
When Bob sends a text_note event with content "why is nobody talking about this?"
|
||||
And Alice subscribes to last event from Bob
|
||||
Then Alice receives a text_note event from Bob with content "why is nobody talking about this?"
|
||||
|
||||
Scenario: Alice posts a set_metadata event
|
||||
Given someone is Alice
|
||||
Given someone called Alice
|
||||
And Alice subscribes to author Alice
|
||||
When Alice sends a set_metadata event
|
||||
Then Alice receives a set_metadata event from Alice
|
||||
|
||||
Scenario: Alice posts a text_note event
|
||||
Given someone is Alice
|
||||
Given someone called Alice
|
||||
And Alice subscribes to author Alice
|
||||
When Alice sends a text_note event with content "hello world"
|
||||
Then Alice receives a text_note event from Alice with content "hello world"
|
||||
|
||||
Scenario: Alice posts a recommend_server event
|
||||
Given someone is Alice
|
||||
Given someone called Alice
|
||||
And Alice subscribes to author Alice
|
||||
When Alice sends a recommend_server event with content "https://nostr-ts-relay.wlvs.space"
|
||||
Then Alice receives a recommend_server event from Alice with content "https://nostr-ts-relay.wlvs.space"
|
||||
|
||||
Scenario: Alice can't post a text_note event with an invalid signature
|
||||
Given someone is Alice
|
||||
Given someone called Alice
|
||||
When Alice sends a text_note event with invalid signature
|
||||
Then Alice receives a notice with invalid signature
|
||||
|
||||
Scenario: Alice and Bob exchange text_note events
|
||||
Given someone is Alice
|
||||
And someone is Bob
|
||||
Given someone called Alice
|
||||
And someone called Bob
|
||||
And Alice subscribes to author Bob
|
||||
And Bob subscribes to author Alice
|
||||
When Bob sends a text_note event with content "hello alice"
|
||||
@ -33,29 +40,45 @@ Feature: NIP-01
|
||||
Then Bob receives a text_note event from Alice with content "hello bob"
|
||||
|
||||
Scenario: Alice is interested in text_note events
|
||||
Given someone is Alice
|
||||
And someone is Bob
|
||||
Given someone called Alice
|
||||
And someone called Bob
|
||||
And Alice subscribes to text_note events
|
||||
When Bob sends a text_note event with content "hello nostr"
|
||||
Then Alice receives a text_note event from Bob with content "hello nostr"
|
||||
|
||||
Scenario: Alice is interested in the #NostrNovember hashtag
|
||||
Given someone is Alice
|
||||
And someone is Bob
|
||||
Given someone called Alice
|
||||
And someone called Bob
|
||||
And Alice subscribes to tag t with "NostrNovember"
|
||||
When Bob sends a text_note event with content "Nostr FTW!" and tag t containing "NostrNovember"
|
||||
Then Alice receives a text_note event from Bob with content "Nostr FTW!"
|
||||
|
||||
@Debug
|
||||
Scenario: Alice is interested to Bob's text_note events and Charlie's set_metadata events
|
||||
Given someone called Alice
|
||||
And someone called Bob
|
||||
And someone called Charlie
|
||||
And Bob subscribes to author Bob
|
||||
And Charlie subscribes to author Charlie
|
||||
|
||||
When Bob sends a text_note event with content "I'm Bob"
|
||||
And Bob receives a text_note event from Bob with content "I'm Bob"
|
||||
And Charlie sends a set_metadata event
|
||||
And Charlie receives a set_metadata event from Charlie
|
||||
And Alice subscribes to text_note events from Bob and set_metadata events from Charlie
|
||||
|
||||
Then Alice receives 2 events from Bob and Charlie
|
||||
|
||||
Scenario: Alice is interested in Bob's events from back in November
|
||||
Given someone is Alice
|
||||
And someone is Bob
|
||||
Given someone called Alice
|
||||
And someone called Bob
|
||||
When Bob sends a text_note event with content "What's up?" on 1668074223
|
||||
And Alice subscribes to any event since 1667275200 until 1669870799
|
||||
Then Alice receives a text_note event from Bob with content "What's up?"
|
||||
|
||||
Scenario: Alice is interested Bob's in 2 past events
|
||||
Given someone is Alice
|
||||
And someone is Bob
|
||||
Given someone called Alice
|
||||
And someone called Bob
|
||||
Then Bob subscribes to author Bob
|
||||
And Bob sends a text_note event with content "One"
|
||||
And Bob receives a text_note event from Bob with content "One"
|
||||
|
@ -25,9 +25,11 @@ Before(async function () {
|
||||
this.parameters.identities = {}
|
||||
this.parameters.subscriptions = {}
|
||||
this.parameters.clients = {}
|
||||
this.parameters.events = {}
|
||||
})
|
||||
|
||||
After(async function () {
|
||||
this.parameters.events = {}
|
||||
this.parameters.subscriptions = {}
|
||||
Object.values(this.parameters.clients).forEach((ws: WebSocket) => {
|
||||
if (ws && ws.readyState === WebSocket.OPEN) {
|
||||
@ -44,11 +46,12 @@ After(async function () {
|
||||
this.parameters.identities = {}
|
||||
})
|
||||
|
||||
Given(/someone is (\w+)/, async function(name: string) {
|
||||
Given(/someone called (\w+)/, async function(name: string) {
|
||||
const connection = connect(name)
|
||||
this.parameters.identities[name] = this.parameters.identities[name] ?? createIdentity(name)
|
||||
this.parameters.clients[name] = await connection
|
||||
this.parameters.subscriptions[name] = []
|
||||
this.parameters.events[name] = []
|
||||
})
|
||||
|
||||
When(/(\w+) subscribes to author (\w+)$/, async function(this: World<Record<string, any>>, from: string, to: string) {
|
||||
@ -60,6 +63,15 @@ When(/(\w+) subscribes to author (\w+)$/, async function(this: World<Record<stri
|
||||
await createSubscription(ws, subscription.name, subscription.filters)
|
||||
})
|
||||
|
||||
When(/(\w+) subscribes to last event from (\w+)$/, async function(this: World<Record<string, any>>, from: string, to: string) {
|
||||
const ws = this.parameters.clients[from] as WebSocket
|
||||
const event = this.parameters.events[to].pop()
|
||||
const subscription = { name: `test-${Math.random()}`, filters: [{ ids: [event.id] }] }
|
||||
this.parameters.subscriptions[from].push(subscription)
|
||||
|
||||
await createSubscription(ws, subscription.name, subscription.filters)
|
||||
})
|
||||
|
||||
When(/(\w+) subscribes to author (\w+) with a limit of (\d+)/, async function(this: World<Record<string, any>>, from: string, to: string, limit: string) {
|
||||
const ws = this.parameters.clients[from] as WebSocket
|
||||
const pubkey = this.parameters.identities[to].pubkey
|
||||
@ -69,7 +81,7 @@ When(/(\w+) subscribes to author (\w+) with a limit of (\d+)/, async function(th
|
||||
await createSubscription(ws, subscription.name, subscription.filters)
|
||||
})
|
||||
|
||||
When(/(\w+) subscribes to text_note events/, async function(this: World<Record<string, any>>, name: string) {
|
||||
When(/^(\w+) subscribes to text_note events$/, async function(this: World<Record<string, any>>, name: string) {
|
||||
const ws = this.parameters.clients[name] as WebSocket
|
||||
const subscription = { name: `test-${Math.random()}`, filters: [{ kinds: [1] }] }
|
||||
this.parameters.subscriptions[name].push(subscription)
|
||||
@ -77,6 +89,22 @@ When(/(\w+) subscribes to text_note events/, async function(this: World<Record<s
|
||||
await createSubscription(ws, subscription.name, subscription.filters)
|
||||
})
|
||||
|
||||
When(/^(\w+) subscribes to text_note events from (\w+) and set_metadata events from (\w+)$/, async function(this: World<Record<string, any>>, name: string, author1: string, author2: string) {
|
||||
const ws = this.parameters.clients[name] as WebSocket
|
||||
const firstAuthor = this.parameters.identities[author1].pubkey
|
||||
const secondAuthor = this.parameters.identities[author2].pubkey
|
||||
const subscription = {
|
||||
name: `test-${Math.random()}`,
|
||||
filters: [
|
||||
{ kinds: [1], authors: [firstAuthor] },
|
||||
{ kinds: [0], authors: [secondAuthor] },
|
||||
],
|
||||
}
|
||||
this.parameters.subscriptions[name].push(subscription)
|
||||
|
||||
await createSubscription(ws, subscription.name, subscription.filters)
|
||||
})
|
||||
|
||||
When(/(\w+) subscribes to any event since (\d+) until (\d+)/, async function(this: World<Record<string, any>>, name: string, since: string, until: string) {
|
||||
const ws = this.parameters.clients[name] as WebSocket
|
||||
const subscription = { name: `test-${Math.random()}`, filters: [{ since: Number(since), until: Number(until) }] }
|
||||
@ -103,9 +131,7 @@ When(/(\w+) sends a set_metadata event/, async function(name: string) {
|
||||
const event: Event = await createEvent({ pubkey, kind: 0, content }, privkey)
|
||||
|
||||
await sendEvent(ws, event)
|
||||
|
||||
this.parameters.events = this.parameters.events ?? []
|
||||
this.parameters.events.push(event)
|
||||
this.parameters.events[name].push(event)
|
||||
})
|
||||
|
||||
When(/^(\w+) sends a text_note event with content "([^"]+)"$/, async function(name: string, content: string) {
|
||||
@ -115,6 +141,7 @@ When(/^(\w+) sends a text_note event with content "([^"]+)"$/, async function(na
|
||||
const event: Event = await createEvent({ pubkey, kind: 1, content }, privkey)
|
||||
|
||||
await sendEvent(ws, event)
|
||||
this.parameters.events[name].push(event)
|
||||
})
|
||||
|
||||
When(/^(\w+) sends a text_note event with content "([^"]+)" and tag (\w) containing "([^"]+)"$/, async function(
|
||||
@ -129,6 +156,7 @@ When(/^(\w+) sends a text_note event with content "([^"]+)" and tag (\w) contain
|
||||
const event: Event = await createEvent({ pubkey, kind: 1, content, tags: [[tag, value]] }, privkey)
|
||||
|
||||
await sendEvent(ws, event)
|
||||
this.parameters.events[name].push(event)
|
||||
})
|
||||
|
||||
When(/^(\w+) sends a text_note event with content "([^"]+)" on (\d+)$/, async function(
|
||||
@ -142,6 +170,7 @@ When(/^(\w+) sends a text_note event with content "([^"]+)" on (\d+)$/, async fu
|
||||
const event: Event = await createEvent({ pubkey, kind: 1, content, created_at: Number(createdAt) }, privkey)
|
||||
|
||||
await sendEvent(ws, event)
|
||||
this.parameters.events[name].push(event)
|
||||
})
|
||||
|
||||
When(/(\w+) sends a text_note event with invalid signature/, async function(name: string) {
|
||||
@ -153,6 +182,7 @@ When(/(\w+) sends a text_note event with invalid signature/, async function(name
|
||||
event.sig = 'f'.repeat(128)
|
||||
|
||||
await sendEvent(ws, event)
|
||||
this.parameters.events[name].push(event)
|
||||
})
|
||||
|
||||
When(/(\w+) sends a recommend_server event with content "(.+?)"/, async function(name: string, content: string) {
|
||||
@ -162,6 +192,7 @@ When(/(\w+) sends a recommend_server event with content "(.+?)"/, async function
|
||||
const event: Event = await createEvent({ pubkey, kind: 2, content }, privkey)
|
||||
|
||||
await sendEvent(ws, event)
|
||||
this.parameters.events[name].push(event)
|
||||
})
|
||||
|
||||
Then(/(\w+) receives a set_metadata event from (\w+)/, async function(name: string, author: string) {
|
||||
@ -173,7 +204,7 @@ Then(/(\w+) receives a set_metadata event from (\w+)/, async function(name: stri
|
||||
expect(receivedEvent.pubkey).to.equal(this.parameters.identities[author].pubkey)
|
||||
})
|
||||
|
||||
Then(/(\w+) receives a text_note event from (\w+) with content "(.+?)"/, async function(name: string, author: string, content: string) {
|
||||
Then(/(\w+) receives a text_note event from (\w+) with content "([^"]+?)"/, async function(name: string, author: string, content: string) {
|
||||
const ws = this.parameters.clients[name] as WebSocket
|
||||
const subscription = this.parameters.subscriptions[name][this.parameters.subscriptions[name].length - 1]
|
||||
const receivedEvent = await waitForNextEvent(ws, subscription.name)
|
||||
@ -215,6 +246,24 @@ Then(/(\w+) receives (\d+) text_note events from (\w+)/, async function(
|
||||
expect(events[1].pubkey).to.equal(this.parameters.identities[author].pubkey)
|
||||
})
|
||||
|
||||
Then(/(\w+) receives (\d+) events from (\w+) and (\w+)/, async function(
|
||||
name: string,
|
||||
count: string,
|
||||
author1: string,
|
||||
author2: string,
|
||||
) {
|
||||
const ws = this.parameters.clients[name] as WebSocket
|
||||
const subscription = this.parameters.subscriptions[name][this.parameters.subscriptions[name].length - 1]
|
||||
const events = await waitForEventCount(ws, subscription.name, Number(count), true)
|
||||
|
||||
console.log(events)
|
||||
expect(events.length).to.equal(2)
|
||||
expect(events[0].kind).to.equal(1)
|
||||
expect(events[1].kind).to.equal(0)
|
||||
expect(events[0].pubkey).to.equal(this.parameters.identities[author1].pubkey)
|
||||
expect(events[1].pubkey).to.equal(this.parameters.identities[author2].pubkey)
|
||||
})
|
||||
|
||||
Then(/(\w+) receives a recommend_server event from (\w+) with content "(.+?)"/, async function(name: string, author: string, content: string) {
|
||||
const ws = this.parameters.clients[name] as WebSocket
|
||||
const subscription = this.parameters.subscriptions[name][this.parameters.subscriptions[name].length - 1]
|
Loading…
x
Reference in New Issue
Block a user