Skip to content

Commit 650f7b9

Browse files
committed
test: add insta
Signed-off-by: Gustavo Inacio <[email protected]>
1 parent a1eb906 commit 650f7b9

File tree

5 files changed

+62
-5
lines changed

5 files changed

+62
-5
lines changed

Cargo.lock

Lines changed: 43 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/service/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ tower-test = "0.4.0"
6767
tower-service = "0.3.3"
6868
tokio-test = "0.4.4"
6969
wiremock.workspace = true
70+
insta = "1.41.1"
7071

7172
[build-dependencies]
7273
build-info-build = { version = "0.0.39", default-features = false }

crates/service/src/service/router.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -305,10 +305,10 @@ impl ServiceRouter {
305305
let free_query = Bearer::new(free_auth_token);
306306
let result = free_query.or(tap_auth);
307307
let auth_layer = AsyncRequireAuthorizationLayer::new(result);
308-
handler = handler.layer(auth_layer);
308+
handler = handler.route_layer(auth_layer);
309309
} else {
310310
let auth_layer = AsyncRequireAuthorizationLayer::new(tap_auth);
311-
handler = handler.layer(auth_layer);
311+
handler = handler.route_layer(auth_layer);
312312
}
313313

314314
let deployment_to_allocation = deployment_to_allocation(allocations);
@@ -346,7 +346,7 @@ impl ServiceRouter {
346346
// create attestation
347347
.layer(from_fn(attestation_middleware));
348348

349-
handler.layer(service_builder)
349+
handler.route_layer(service_builder)
350350
};
351351

352352
// setup cors

crates/service/tests/router_test.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@
44
use std::time::{Duration, SystemTime};
55

66
use alloy::primitives::Address;
7-
use axum::http::Request;
7+
use axum::{body::to_bytes, http::Request};
88
use axum_extra::headers::Header;
99
use indexer_config::{BlockchainConfig, GraphNodeConfig, IndexerConfig, NonZeroGRT};
1010
use indexer_monitor::EscrowAccounts;
1111
use indexer_service_rs::{
1212
service::{ServiceRouter, TapReceipt},
1313
QueryBody,
1414
};
15-
use reqwest::{StatusCode, Url};
15+
use reqwest::{Method, StatusCode, Url};
1616
use sqlx::PgPool;
1717
use test_assets::{create_signed_receipt, INDEXER_ALLOCATIONS, TAP_EIP712_DOMAIN};
1818
use tokio::sync::watch;
@@ -113,6 +113,7 @@ async fn full_integration_test(database: PgPool) {
113113
};
114114

115115
let request = Request::builder()
116+
.method(Method::POST)
116117
.uri(format!("/subgraphs/id/{deployment}"))
117118
.header(TapReceipt::name(), serde_json::to_string(&receipt).unwrap())
118119
.body(serde_json::to_string(&query).unwrap())
@@ -121,6 +122,12 @@ async fn full_integration_test(database: PgPool) {
121122
// with deployment
122123
let res = app.oneshot(request).await.unwrap();
123124
assert_eq!(res.status(), StatusCode::OK);
125+
126+
let graphql_response = res.into_body();
127+
let bytes = to_bytes(graphql_response, usize::MAX).await.unwrap();
128+
let res = String::from_utf8(bytes.into()).unwrap();
129+
130+
insta::assert_snapshot!(res);
124131
}
125132

126133
fn leak<T>(thing: T) -> &'static T {
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
source: crates/service/tests/router_test.rs
3+
expression: res
4+
snapshot_kind: text
5+
---
6+
{"graphQLResponse":"\n {\n \"data\": {\n \"graphNetwork\": {\n \"currentEpoch\": 960\n }\n }\n }\n ","attestation":null}

0 commit comments

Comments
 (0)