Skip to content

Commit 4d030c7

Browse files
authored
test(nip-11): add integration tests and fix max_filters mapping (#527)
* test(nip-11): add integration tests and fix max_filters mapping * chore: add changeset for NIP-11 integration tests
1 parent b09e23a commit 4d030c7

4 files changed

Lines changed: 103 additions & 1 deletion

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"nostream": patch
3+
---
4+
5+
Add NIP-11 integration tests and fix max_filters mapping in relay information document.

src/handlers/request-handlers/root-request-handler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export const rootRequestHandler = (request: Request, response: Response, next: N
3636
limitation: {
3737
max_message_length: settings.network.maxPayloadSize,
3838
max_subscriptions: settings.limits?.client?.subscription?.maxSubscriptions,
39-
max_filters: settings.limits?.client?.subscription?.maxFilterValues,
39+
max_filters: settings.limits?.client?.subscription?.maxFilters,
4040
max_limit: settings.limits?.client?.subscription?.maxLimit,
4141
max_subid_length: settings.limits?.client?.subscription?.maxSubscriptionIdLength,
4242
min_prefix: settings.limits?.client?.subscription?.minPrefixLength,
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
Feature: NIP-11
2+
Scenario: Relay returns information document for NIP-11 request
3+
When a client requests the relay information document
4+
Then the response status is 200
5+
And the response Content-Type includes "application/nostr+json"
6+
And the relay information document contains the required fields
7+
8+
Scenario: Relay information document lists supported NIPs from package.json
9+
When a client requests the relay information document
10+
Then the supported_nips field matches the NIPs declared in package.json
11+
12+
Scenario: Relay does not return information document for a non-NIP-11 Accept header
13+
When a client requests the root path with Accept header "text/html"
14+
Then the response Content-Type does not include "application/nostr+json"
15+
And the response body is not a relay information document
16+
17+
Scenario: Relay information document reports max_filters from settings
18+
When a client requests the relay information document
19+
Then the limitation object contains a max_filters field
20+
21+
Scenario: WebSocket connections coexist with HTTP on the same port
22+
Given someone called Alice
23+
When Alice sends a text_note event with content "nostr is great"
24+
And Alice subscribes to author Alice
25+
Then Alice receives a text_note event from Alice with content "nostr is great"
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
import { Then, When, World } from '@cucumber/cucumber'
2+
import axios, { AxiosResponse } from 'axios'
3+
import chai from 'chai'
4+
5+
import packageJson from '../../../../package.json'
6+
import { createSettings } from '../../../../src/factories/settings-factory'
7+
8+
chai.use(require('sinon-chai'))
9+
const { expect } = chai
10+
11+
const BASE_URL = 'http://localhost:18808'
12+
13+
When('a client requests the relay information document', async function(this: World<Record<string, any>>) {
14+
const response: AxiosResponse = await axios.get(BASE_URL, {
15+
headers: { Accept: 'application/nostr+json' },
16+
validateStatus: () => true,
17+
})
18+
this.parameters.httpResponse = response
19+
})
20+
21+
When('a client requests the root path with Accept header {string}', async function(
22+
this: World<Record<string, any>>,
23+
acceptHeader: string,
24+
) {
25+
const response: AxiosResponse = await axios.get(BASE_URL, {
26+
headers: { Accept: acceptHeader },
27+
validateStatus: () => true,
28+
})
29+
this.parameters.httpResponse = response
30+
})
31+
32+
Then('the response status is {int}', function(this: World<Record<string, any>>, status: number) {
33+
expect(this.parameters.httpResponse.status).to.equal(status)
34+
})
35+
36+
Then('the response Content-Type includes {string}', function(
37+
this: World<Record<string, any>>,
38+
contentType: string,
39+
) {
40+
expect(this.parameters.httpResponse.headers['content-type']).to.include(contentType)
41+
})
42+
43+
Then('the response Content-Type does not include {string}', function(
44+
this: World<Record<string, any>>,
45+
contentType: string,
46+
) {
47+
expect(this.parameters.httpResponse.headers['content-type']).to.not.include(contentType)
48+
})
49+
50+
Then('the relay information document contains the required fields', function(this: World<Record<string, any>>) {
51+
const doc = this.parameters.httpResponse.data
52+
for (const field of ['name', 'description', 'pubkey', 'supported_nips', 'software', 'version']) {
53+
expect(doc, `expected relay info doc to have field "${field}"`).to.have.property(field)
54+
}
55+
})
56+
57+
Then('the supported_nips field matches the NIPs declared in package.json', function(this: World<Record<string, any>>) {
58+
const doc = this.parameters.httpResponse.data
59+
expect(doc.supported_nips).to.deep.equal(packageJson.supportedNips)
60+
})
61+
62+
Then('the response body is not a relay information document', function(this: World<Record<string, any>>) {
63+
const body = this.parameters.httpResponse.data
64+
const isRelayInfoDoc = typeof body === 'object' && body !== null && 'supported_nips' in body
65+
expect(isRelayInfoDoc).to.equal(false)
66+
})
67+
68+
Then('the limitation object contains a max_filters field', function(this: World<Record<string, any>>) {
69+
const doc = this.parameters.httpResponse.data
70+
const expectedMaxFilters = createSettings().limits?.client?.subscription?.maxFilters
71+
expect(doc.limitation.max_filters).to.equal(expectedMaxFilters)
72+
})

0 commit comments

Comments
 (0)