-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: add handler for new attachments (#1185)
- Loading branch information
Showing
5 changed files
with
87 additions
and
16 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,59 @@ | ||
//! This module contains the default router for the signers api | ||
//! | ||
use axum::{ | ||
routing::{get, post}, | ||
Router, | ||
}; | ||
|
||
use crate::context::Context; | ||
|
||
use axum::http::StatusCode; | ||
|
||
use super::{new_block, status, ApiState}; | ||
|
||
async fn new_attachment_handler() -> StatusCode { | ||
StatusCode::OK | ||
} | ||
|
||
/// Return the default router | ||
pub fn get_router<C: Context + 'static>() -> Router<ApiState<C>> { | ||
Router::new() | ||
.route("/", get(status::status_handler)) | ||
.route("/new_block", post(new_block::new_block_handler)) | ||
// TODO: remove this once https://github.com/stacks-network/stacks-core/issues/5558 | ||
// is addressed | ||
.route("/attachments/new", post(new_attachment_handler)) | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use axum::{ | ||
body::Body, | ||
http::{Method, Request, StatusCode}, | ||
Router, | ||
}; | ||
use tower::ServiceExt; | ||
|
||
use crate::{ | ||
api::{router::get_router, ApiState}, | ||
testing::context::TestContext, | ||
}; | ||
|
||
#[tokio::test] | ||
async fn test_new_attachment() { | ||
let context = TestContext::default_mocked(); | ||
|
||
let state = ApiState { ctx: context.clone() }; | ||
let app: Router = get_router().with_state(state); | ||
|
||
let request = Request::builder() | ||
.uri("/attachments/new") | ||
.method(Method::POST) | ||
.body(Body::empty()) | ||
.unwrap(); | ||
|
||
let response = app.oneshot(request).await.unwrap(); | ||
assert_eq!(response.status(), StatusCode::OK); | ||
} | ||
} |
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