-
Notifications
You must be signed in to change notification settings - Fork 197
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
114 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
Feature: NIP-28 | ||
Scenario: Alice creates a channel | ||
Given someone called Alice | ||
When Alice sends a channel_creation event with content '{\"name\": \"Demo Channel\", \"about\": \"A test channel.\", \"picture\": \"https://placekitten.com/200/200\"}' | ||
And Alice subscribes to last event from Alice | ||
Then Alice receives a channel_creation event from Alice with content '{\"name\": \"Demo Channel\", \"about\": \"A test channel.\", \"picture\": \"https://placekitten.com/200/200\"}' | ||
|
||
Scenario: Alice sets metadata for a channel | ||
Given someone called Alice | ||
And Alice subscribes to author Alice | ||
And Alice sends a channel_creation event with content '{\"name\": \"Original\", \"about\": \"A test channel.\", \"picture\": \"https://placekitten.com/200/200\"}' | ||
And Alice receives a channel_creation event from Alice with content '{\"name\": \"Original\", \"about\": \"A test channel.\", \"picture\": \"https://placekitten.com/200/200\"}' | ||
When Alice sends a channel_metadata event with content '{\"name\": \"New\", \"about\": \"A better test channel.\", \"picture\": \"https://placekitten.com/256/256\"}' | ||
Then Alice receives a channel_metadata event from Alice with content '{\"name\": \"New\", \"about\": \"A better test channel.\", \"picture\": \"https://placekitten.com/256/256\"}' | ||
|
||
Scenario: Alice replaces metadata for a channel | ||
Given someone called Alice | ||
And Alice subscribes to author Alice | ||
And Alice sends a channel_creation event with content '{\"name\": \"Original\", \"about\": \"A test channel.\", \"picture\": \"https://placekitten.com/200/200\"}' | ||
And Alice receives a channel_creation event from Alice with content '{\"name\": \"Original\", \"about\": \"A test channel.\", \"picture\": \"https://placekitten.com/200/200\"}' | ||
And Alice sends a channel_metadata event with content '{\"name\": \"New\", \"about\": \"A better test channel.\", \"picture\": \"https://placekitten.com/256/256\"}' | ||
And Alice receives a channel_metadata event from Alice with content '{\"name\": \"New\", \"about\": \"A better test channel.\", \"picture\": \"https://placekitten.com/256/256\"}' | ||
When Alice sends a channel_metadata event with content '{\"name\": \"Replaced\", \"about\": \"A different test channel.\", \"picture\": \"https://placekitten.com/400/400\"}' | ||
Then Alice receives a channel_metadata event from Alice with content '{\"name\": \"Replaced\", \"about\": \"A different test channel.\", \"picture\": \"https://placekitten.com/400/400\"}' | ||
|
||
Scenario: Alice replaces metadata for a channel | ||
Given someone called Alice | ||
And Alice subscribes to author Alice | ||
And Alice sends a channel_creation event with content '{\"name\": \"Original\", \"about\": \"A test channel.\", \"picture\": \"https://placekitten.com/200/200\"}' | ||
And Alice receives a channel_creation event from Alice with content '{\"name\": \"Original\", \"about\": \"A test channel.\", \"picture\": \"https://placekitten.com/200/200\"}' | ||
And Alice sends a channel_metadata event with content '{\"name\": \"New\", \"about\": \"A better test channel.\", \"picture\": \"https://placekitten.com/256/256\"}' | ||
And Alice receives a channel_metadata event from Alice with content '{\"name\": \"New\", \"about\": \"A better test channel.\", \"picture\": \"https://placekitten.com/256/256\"}' | ||
And Alice unsubscribes from author Alice | ||
When Alice sends a channel_metadata event with content '{\"name\": \"Replaced\", \"about\": \"A different test channel.\", \"picture\": \"https://placekitten.com/400/400\"}' | ||
And Alice subscribes to channel_creation events | ||
And Alice receives a channel_creation event from Alice with content '{\"name\": \"Original\", \"about\": \"A test channel.\", \"picture\": \"https://placekitten.com/200/200\"}' | ||
And Alice subscribes to channel_metadata events | ||
Then Alice receives a channel_metadata event from Alice with content '{\"name\": \"Replaced\", \"about\": \"A different test channel.\", \"picture\": \"https://placekitten.com/400/400\"}' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import { Before, Then, When, World } from '@cucumber/cucumber' | ||
import WebSocket from 'ws' | ||
|
||
import { createEvent, createSubscription, sendEvent, waitForNextEvent } from '../helpers' | ||
import { Event } from '../../../../src/@types/event' | ||
import { expect } from 'chai' | ||
|
||
Before(function () { | ||
this.parameters.channels = [] | ||
}) | ||
|
||
When(/^(\w+) sends a channel_creation event with content '([^']+)'$/, async function(name: string, content: string) { | ||
const ws = this.parameters.clients[name] as WebSocket | ||
const { pubkey, privkey } = this.parameters.identities[name] | ||
|
||
const event: Event = await createEvent({ pubkey, kind: 40, content }, privkey) | ||
this.parameters.channels.push(event.id) | ||
await sendEvent(ws, event) | ||
this.parameters.events[name].push(event) | ||
}) | ||
|
||
When(/^(\w+) sends a channel_metadata event with content '([^']+)'$/, async function(name: string, content: string) { | ||
const ws = this.parameters.clients[name] as WebSocket | ||
const { pubkey, privkey } = this.parameters.identities[name] | ||
|
||
const channel = this.parameters.channels[this.parameters.channels.length - 1] | ||
const event: Event = await createEvent({ pubkey, kind: 41, content, tags: [['e', channel]] }, privkey) | ||
|
||
await sendEvent(ws, event) | ||
this.parameters.events[name].push(event) | ||
}) | ||
|
||
Then(/(\w+) receives a channel_creation 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) | ||
|
||
expect(receivedEvent.kind).to.equal(40) | ||
expect(receivedEvent.pubkey).to.equal(this.parameters.identities[author].pubkey) | ||
expect(receivedEvent.content).to.equal(content) | ||
}) | ||
|
||
|
||
Then(/(\w+) receives a channel_metadata 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) | ||
|
||
const channel = this.parameters.channels[this.parameters.channels.length - 1] | ||
|
||
expect(receivedEvent.kind).to.equal(41) | ||
expect(receivedEvent.pubkey).to.equal(this.parameters.identities[author].pubkey) | ||
expect(receivedEvent.content).to.equal(content) | ||
expect(receivedEvent.tags).to.deep.include(['e', channel]) | ||
}) | ||
|
||
When(/^(\w+) subscribes to channel_creation 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: [40] }] } | ||
this.parameters.subscriptions[name].push(subscription) | ||
|
||
await createSubscription(ws, subscription.name, subscription.filters) | ||
}) | ||
|
||
|
||
When(/^(\w+) subscribes to channel_metadata 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: [41] }] } | ||
this.parameters.subscriptions[name].push(subscription) | ||
|
||
await createSubscription(ws, subscription.name, subscription.filters) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters