Skip to content

Commit 57b1364

Browse files
committed
test(integration): verify response content-types across HTTP routes
Signed-off-by: ABHAY PANDEY <pandeyabhay967@gmail.com>
1 parent aee8940 commit 57b1364

3 files changed

Lines changed: 102 additions & 0 deletions

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+
test(integration): verify response content-type across core HTTP paths
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
Feature: HTTP response types
2+
Scenario Outline: GET path returns expected response Content-Type
3+
When a client requests path "<path>" with Accept header "<acceptHeader>"
4+
Then the HTTP response status is <statusCode>
5+
And the HTTP response Content-Type includes "<contentType>"
6+
7+
Examples:
8+
| path | acceptHeader | statusCode | contentType |
9+
| / | application/nostr+json | 200 | application/nostr+json |
10+
| / | text/html | 200 | text/html |
11+
| /healthz | */* | 200 | text/plain |
12+
| /terms | */* | 200 | text/html |
13+
| /privacy | */* | 200 | text/html |
14+
| /.well-known/nodeinfo | */* | 200 | application/json |
15+
| /nodeinfo/2.1 | */* | 200 | application/json |
16+
| /nodeinfo/2.0 | */* | 200 | application/json |
17+
18+
Scenario Outline: dynamic GET path returns expected response Content-Type
19+
When a client requests dynamic path "<path>"
20+
Then the HTTP response status is <statusCode>
21+
And the HTTP response Content-Type includes "<contentType>"
22+
23+
Examples:
24+
| path | statusCode | contentType |
25+
| /admissions/check/0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef | 200 | application/json |
26+
| /invoices/non-existent-invoice/status | 404 | application/json |
27+
28+
Scenario Outline: POST path returns expected response Content-Type
29+
When a client posts "<body>" to path "<path>" with Content-Type "<contentTypeHeader>"
30+
Then the HTTP response status is <statusCode>
31+
And the HTTP response Content-Type includes "<contentType>"
32+
33+
Examples:
34+
| path | contentTypeHeader | body | statusCode | contentType |
35+
| /invoices | application/x-www-form-urlencoded | | 400 | text/plain |
36+
| /callbacks/zebedee | application/json | {} | 403 | text/html |
37+
| /callbacks/lnbits | application/json | {} | 403 | text/html |
38+
| /callbacks/opennode | application/x-www-form-urlencoded | id=test&status=paid | 403 | text/html |
39+
| /callbacks/nodeless | application/json | {} | 403 | text/html |
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import { Then, When, World } from '@cucumber/cucumber'
2+
import { expect } from 'chai'
3+
import axios, { AxiosResponse } from 'axios'
4+
5+
const BASE_URL = 'http://localhost:18808'
6+
7+
When(
8+
'a client requests path {string} with Accept header {string}',
9+
async function (this: World<Record<string, any>>, requestPath: string, acceptHeader: string) {
10+
const response: AxiosResponse = await axios.get(`${BASE_URL}${requestPath}`, {
11+
headers: { Accept: acceptHeader },
12+
validateStatus: () => true,
13+
})
14+
15+
this.parameters.httpResponse = response
16+
},
17+
)
18+
19+
When('a client requests dynamic path {string}', async function (this: World<Record<string, any>>, requestPath: string) {
20+
const response: AxiosResponse = await axios.get(`${BASE_URL}${requestPath}`, {
21+
validateStatus: () => true,
22+
})
23+
24+
this.parameters.httpResponse = response
25+
})
26+
27+
When(
28+
'a client posts {string} to path {string} with Content-Type {string}',
29+
async function (
30+
this: World<Record<string, any>>,
31+
body: string,
32+
requestPath: string,
33+
contentTypeHeader: string,
34+
) {
35+
const response: AxiosResponse = await axios.post(`${BASE_URL}${requestPath}`, body, {
36+
headers: { 'content-type': contentTypeHeader },
37+
validateStatus: () => true,
38+
})
39+
40+
this.parameters.httpResponse = response
41+
},
42+
)
43+
44+
Then('the HTTP response status is {int}', function (this: World<Record<string, any>>, statusCode: number) {
45+
expect(this.parameters.httpResponse.status).to.equal(statusCode)
46+
})
47+
48+
Then(
49+
'the HTTP response Content-Type includes {string}',
50+
function (this: World<Record<string, any>>, contentType: string) {
51+
// Normalize header value to plain string and compare case-insensitively
52+
// so assertions are robust to header casing/charset formatting variations.
53+
const contentTypeHeader = this.parameters.httpResponse.headers['content-type']
54+
const headerValue = Array.isArray(contentTypeHeader) ? contentTypeHeader.join(';') : contentTypeHeader
55+
const normalizedHeader = typeof headerValue === 'string' ? headerValue.toLowerCase() : ''
56+
expect(normalizedHeader).to.include(contentType.toLowerCase())
57+
},
58+
)

0 commit comments

Comments
 (0)