Skip to content

Commit 96e2986

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

3 files changed

Lines changed: 84 additions & 0 deletions

File tree

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
---
3+
4+
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 response status is <statusCode>
5+
And the 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 response status is <statusCode>
21+
And the 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 response status is <statusCode>
31+
And the 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 | {"event":"payment_received"} | 403 | text/html |
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import { When, World } from '@cucumber/cucumber'
2+
import axios, { AxiosResponse } from 'axios'
3+
4+
const BASE_URL = 'http://localhost:18808'
5+
6+
When(
7+
'a client requests path {string} with Accept header {string}',
8+
async function (this: World<Record<string, any>>, requestPath: string, acceptHeader: string) {
9+
const response: AxiosResponse = await axios.get(`${BASE_URL}${requestPath}`, {
10+
headers: { Accept: acceptHeader },
11+
validateStatus: () => true,
12+
})
13+
14+
this.parameters.httpResponse = response
15+
},
16+
)
17+
18+
When('a client requests dynamic path {string}', async function (this: World<Record<string, any>>, requestPath: string) {
19+
const response: AxiosResponse = await axios.get(`${BASE_URL}${requestPath}`, {
20+
validateStatus: () => true,
21+
})
22+
23+
this.parameters.httpResponse = response
24+
})
25+
26+
When(
27+
'a client posts {string} to path {string} with Content-Type {string}',
28+
async function (
29+
this: World<Record<string, any>>,
30+
body: string,
31+
requestPath: string,
32+
contentTypeHeader: string,
33+
) {
34+
const response: AxiosResponse = await axios.post(`${BASE_URL}${requestPath}`, body, {
35+
headers: { 'content-type': contentTypeHeader },
36+
validateStatus: () => true,
37+
})
38+
39+
this.parameters.httpResponse = response
40+
},
41+
)

0 commit comments

Comments
 (0)