-
Notifications
You must be signed in to change notification settings - Fork 235
test(integration): verify response content-types across HTTP routes #627
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Ferryx349
wants to merge
1
commit into
cameri:main
Choose a base branch
from
Ferryx349:m3
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+102
−0
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,5 @@ | ||
| --- | ||
| "nostream": patch | ||
| --- | ||
|
|
||
| test(integration): verify response content-type across core HTTP paths | ||
39 changes: 39 additions & 0 deletions
39
test/integration/features/response-types/response-types.feature
This file contains hidden or 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,39 @@ | ||
| Feature: HTTP response types | ||
| Scenario Outline: GET path returns expected response Content-Type | ||
| When a client requests path "<path>" with Accept header "<acceptHeader>" | ||
| Then the HTTP response status is <statusCode> | ||
| And the HTTP response Content-Type includes "<contentType>" | ||
|
|
||
| Examples: | ||
| | path | acceptHeader | statusCode | contentType | | ||
| | / | application/nostr+json | 200 | application/nostr+json | | ||
| | / | text/html | 200 | text/html | | ||
| | /healthz | */* | 200 | text/plain | | ||
| | /terms | */* | 200 | text/html | | ||
| | /privacy | */* | 200 | text/html | | ||
| | /.well-known/nodeinfo | */* | 200 | application/json | | ||
| | /nodeinfo/2.1 | */* | 200 | application/json | | ||
| | /nodeinfo/2.0 | */* | 200 | application/json | | ||
|
|
||
| Scenario Outline: dynamic GET path returns expected response Content-Type | ||
| When a client requests dynamic path "<path>" | ||
| Then the HTTP response status is <statusCode> | ||
| And the HTTP response Content-Type includes "<contentType>" | ||
|
|
||
| Examples: | ||
| | path | statusCode | contentType | | ||
| | /admissions/check/0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef | 200 | application/json | | ||
| | /invoices/non-existent-invoice/status | 404 | application/json | | ||
|
|
||
| Scenario Outline: POST path returns expected response Content-Type | ||
| When a client posts "<body>" to path "<path>" with Content-Type "<contentTypeHeader>" | ||
| Then the HTTP response status is <statusCode> | ||
| And the HTTP response Content-Type includes "<contentType>" | ||
|
|
||
| Examples: | ||
| | path | contentTypeHeader | body | statusCode | contentType | | ||
| | /invoices | application/x-www-form-urlencoded | | 400 | text/plain | | ||
| | /callbacks/zebedee | application/json | {} | 403 | text/html | | ||
| | /callbacks/lnbits | application/json | {} | 403 | text/html | | ||
| | /callbacks/opennode | application/x-www-form-urlencoded | id=test&status=paid | 403 | text/html | | ||
| | /callbacks/nodeless | application/json | {} | 403 | text/html | |
58 changes: 58 additions & 0 deletions
58
test/integration/features/response-types/response-types.feature.ts
This file contains hidden or 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,58 @@ | ||
| import { Then, When, World } from '@cucumber/cucumber' | ||
| import { expect } from 'chai' | ||
| import axios, { AxiosResponse } from 'axios' | ||
|
|
||
| const BASE_URL = 'http://localhost:18808' | ||
|
|
||
| When( | ||
| 'a client requests path {string} with Accept header {string}', | ||
| async function (this: World<Record<string, any>>, requestPath: string, acceptHeader: string) { | ||
| const response: AxiosResponse = await axios.get(`${BASE_URL}${requestPath}`, { | ||
| headers: { Accept: acceptHeader }, | ||
| validateStatus: () => true, | ||
| }) | ||
|
|
||
| this.parameters.httpResponse = response | ||
| }, | ||
| ) | ||
|
|
||
| When('a client requests dynamic path {string}', async function (this: World<Record<string, any>>, requestPath: string) { | ||
| const response: AxiosResponse = await axios.get(`${BASE_URL}${requestPath}`, { | ||
| validateStatus: () => true, | ||
| }) | ||
|
|
||
| this.parameters.httpResponse = response | ||
| }) | ||
|
|
||
| When( | ||
| 'a client posts {string} to path {string} with Content-Type {string}', | ||
| async function ( | ||
| this: World<Record<string, any>>, | ||
| body: string, | ||
| requestPath: string, | ||
| contentTypeHeader: string, | ||
| ) { | ||
| const response: AxiosResponse = await axios.post(`${BASE_URL}${requestPath}`, body, { | ||
| headers: { 'content-type': contentTypeHeader }, | ||
| validateStatus: () => true, | ||
| }) | ||
|
|
||
| this.parameters.httpResponse = response | ||
| }, | ||
| ) | ||
|
Ferryx349 marked this conversation as resolved.
|
||
|
|
||
| Then('the HTTP response status is {int}', function (this: World<Record<string, any>>, statusCode: number) { | ||
| expect(this.parameters.httpResponse.status).to.equal(statusCode) | ||
| }) | ||
|
|
||
| Then( | ||
| 'the HTTP response Content-Type includes {string}', | ||
| function (this: World<Record<string, any>>, contentType: string) { | ||
| // Normalize header value to plain string and compare case-insensitively | ||
| // so assertions are robust to header casing/charset formatting variations. | ||
| const contentTypeHeader = this.parameters.httpResponse.headers['content-type'] | ||
| const headerValue = Array.isArray(contentTypeHeader) ? contentTypeHeader.join(';') : contentTypeHeader | ||
| const normalizedHeader = typeof headerValue === 'string' ? headerValue.toLowerCase() : '' | ||
| expect(normalizedHeader).to.include(contentType.toLowerCase()) | ||
| }, | ||
| ) | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.