Skip to content

Commit

Permalink
refactor: add module prefix to external functions
Browse files Browse the repository at this point in the history
In adherence to Rust community conventions, it is recommended to prefix external functions
with the crate/module name. This practice helps prevent confusion with locally defined functions.
  • Loading branch information
azzamsa committed Jan 22, 2024
1 parent 9e35d9a commit 2996321
Showing 10 changed files with 56 additions and 56 deletions.
10 changes: 5 additions & 5 deletions tests/health/tests.rs
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@ use axum::{
};
use cynic::QueryBuilder;
use http_body_util::BodyExt; // for `collect`
use serde_json::{from_slice, json, to_string, Value};
use serde_json as json;
use tin::route::app;
use tower::util::ServiceExt;

@@ -21,13 +21,13 @@ async fn health() -> Result<()> {
.method(http::Method::POST)
.header(http::header::CONTENT_TYPE, mime::APPLICATION_JSON.as_ref())
.uri("/graphql")
.body(Body::from(to_string(&query)?))?;
.body(Body::from(json::to_string(&query)?))?;

let response = app.oneshot(request).await?;
assert_eq!(response.status(), StatusCode::OK);

let body = response.into_body().collect().await?.to_bytes();
let health_response: HealthResponse = from_slice(&body)?;
let health_response: HealthResponse = json::from_slice(&body)?;
assert_eq!(health_response.data.health.status, "running");

Ok(())
@@ -43,7 +43,7 @@ async fn health_restapi() -> Result<()> {
assert_eq!(response.status(), StatusCode::OK);

let body = response.into_body().collect().await?.to_bytes();
let body: Value = serde_json::from_slice(&body)?;
assert_eq!(body, json!({ "data": { "status": "running" } }));
let body: json::Value = json::from_slice(&body)?;
assert_eq!(body, json::json!({ "data": { "status": "running" } }));
Ok(())
}
6 changes: 3 additions & 3 deletions tests/meta/tests.rs
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@ use axum::{
};
use cynic::QueryBuilder;
use http_body_util::BodyExt; // for `collect`
use serde_json::{from_slice, to_string};
use serde_json as json;
use tin::route::app;
use tower::util::ServiceExt;

@@ -20,13 +20,13 @@ async fn meta() -> Result<()> {
.method(http::Method::POST)
.header(http::header::CONTENT_TYPE, mime::APPLICATION_JSON.as_ref())
.uri("/graphql")
.body(Body::from(to_string(&query)?))?;
.body(Body::from(json::to_string(&query)?))?;

let response = app.oneshot(request).await?;
assert_eq!(response.status(), StatusCode::OK);

let body = response.into_body().collect().await?.to_bytes();
let meta_response: MetaResponse = from_slice(&body)?;
let meta_response: MetaResponse = json::from_slice(&body)?;

let cargo_package_version = env!("CARGO_PKG_VERSION").to_string();
assert_eq!(meta_response.data.meta.version, cargo_package_version);
6 changes: 3 additions & 3 deletions tests/user/create_user.rs
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@ use axum::{
};
use cynic::MutationBuilder;
use http_body_util::BodyExt; // for `collect`
use serde_json::{from_slice, to_string};
use serde_json as json;
use tin::route::app;
use tower::util::ServiceExt;

@@ -22,13 +22,13 @@ async fn create_user() -> Result<()> {
.method(http::Method::POST)
.header(http::header::CONTENT_TYPE, mime::APPLICATION_JSON.as_ref())
.uri("/graphql")
.body(Body::from(to_string(&query)?))?;
.body(Body::from(json::to_string(&query)?))?;

let response = app.oneshot(request).await?;
assert_eq!(response.status(), StatusCode::OK);

let body = response.into_body().collect().await?.to_bytes();
let user_response: CreateUserResponse = from_slice(&body)?;
let user_response: CreateUserResponse = json::from_slice(&body)?;
assert_eq!(user_response.data.create_user.name, "khawa");

teardown().await?;
6 changes: 3 additions & 3 deletions tests/user/create_user_without_full_name.rs
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@ use axum::{
};
use cynic::MutationBuilder;
use http_body_util::BodyExt;
use serde_json::{from_slice, to_string};
use serde_json as json;
use tin::route::app;
use tower::util::ServiceExt;

@@ -27,13 +27,13 @@ async fn create_user_without_full_name() -> Result<()> {
.method(http::Method::POST)
.header(http::header::CONTENT_TYPE, mime::APPLICATION_JSON.as_ref())
.uri("/graphql")
.body(Body::from(to_string(&query)?))?;
.body(Body::from(json::to_string(&query)?))?;

let response = app.oneshot(request).await?;
assert_eq!(response.status(), StatusCode::OK);

let body = response.into_body().collect().await?.to_bytes();
let user_response: CreateUserResponse = from_slice(&body)?;
let user_response: CreateUserResponse = json::from_slice(&body)?;
assert_eq!(user_response.data.create_user.name, "khawa");
assert_eq!(user_response.data.create_user.full_name, None);

12 changes: 6 additions & 6 deletions tests/user/delete_user.rs
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@ use axum::{
};
use cynic::{MutationBuilder, QueryBuilder};
use http_body_util::BodyExt;
use serde_json::{from_slice, to_string, Value};
use serde_json as json;
use tin::route::app;
use tower::{util::ServiceExt, Service};

@@ -31,7 +31,7 @@ async fn delete_user() -> Result<()> {
.method(http::Method::POST)
.header(http::header::CONTENT_TYPE, mime::APPLICATION_JSON.as_ref())
.uri("/graphql")
.body(Body::from(to_string(&query)?))?;
.body(Body::from(json::to_string(&query)?))?;

let response = ServiceExt::<Request<Body>>::ready(&mut app)
.await?
@@ -40,7 +40,7 @@ async fn delete_user() -> Result<()> {
assert_eq!(response.status(), StatusCode::OK);

let body = response.into_body().collect().await?.to_bytes();
let user_response: CreateUserResponse = from_slice(&body)?;
let user_response: CreateUserResponse = json::from_slice(&body)?;
assert_eq!(user_response.data.create_user.name, "khawa");

let user_id = user_response.data.create_user.id;
@@ -57,7 +57,7 @@ async fn delete_user() -> Result<()> {
.method(http::Method::POST)
.header(http::header::CONTENT_TYPE, mime::APPLICATION_JSON.as_ref())
.uri("/graphql")
.body(Body::from(to_string(&query)?))?;
.body(Body::from(json::to_string(&query)?))?;

let _ = ServiceExt::<Request<Body>>::ready(&mut app)
.await?
@@ -75,14 +75,14 @@ async fn delete_user() -> Result<()> {
.method(http::Method::POST)
.header(http::header::CONTENT_TYPE, mime::APPLICATION_JSON.as_ref())
.uri("/graphql")
.body(Body::from(to_string(&query)?))?;
.body(Body::from(json::to_string(&query)?))?;

let response = ServiceExt::<Request<Body>>::ready(&mut app)
.await?
.call(request)
.await?;
let body = response.into_body().collect().await?.to_bytes();
let body: Value = from_slice(&body)?;
let body: json::Value = json::from_slice(&body)?;
let error_message = &body["errors"][0]["message"];
assert_eq!(error_message, "user not found");

18 changes: 9 additions & 9 deletions tests/user/duplicate_username.rs
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@ use axum::{
};
use cynic::MutationBuilder;
use http_body_util::BodyExt;
use serde_json::{from_slice, to_string, Value};
use serde_json as json;
use tin::route::app;
use tower::{util::ServiceExt, Service};

@@ -24,7 +24,7 @@ async fn duplicate_username_create() -> Result<()> {
.method(http::Method::POST)
.header(http::header::CONTENT_TYPE, mime::APPLICATION_JSON.as_ref())
.uri("/graphql")
.body(Body::from(to_string(&query)?))?;
.body(Body::from(json::to_string(&query)?))?;

let _ = ServiceExt::<Request<Body>>::ready(&mut app)
.await?
@@ -40,14 +40,14 @@ async fn duplicate_username_create() -> Result<()> {
.method(http::Method::POST)
.header(http::header::CONTENT_TYPE, mime::APPLICATION_JSON.as_ref())
.uri("/graphql")
.body(Body::from(to_string(&query)?))?;
.body(Body::from(json::to_string(&query)?))?;

let response = ServiceExt::<Request<Body>>::ready(&mut app)
.await?
.call(request)
.await?;
let body = response.into_body().collect().await?.to_bytes();
let body: Value = from_slice(&body)?;
let body: json::Value = json::from_slice(&body)?;
let error_message = &body["errors"][0]["message"];
assert_eq!(error_message, "username is already in use");

@@ -68,7 +68,7 @@ async fn duplicate_username_update() -> Result<()> {
.method(http::Method::POST)
.header(http::header::CONTENT_TYPE, mime::APPLICATION_JSON.as_ref())
.uri("/graphql")
.body(Body::from(to_string(&query)?))?;
.body(Body::from(json::to_string(&query)?))?;

let response = ServiceExt::<Request<Body>>::ready(&mut app)
.await?
@@ -91,7 +91,7 @@ async fn duplicate_username_update() -> Result<()> {
.method(http::Method::POST)
.header(http::header::CONTENT_TYPE, mime::APPLICATION_JSON.as_ref())
.uri("/graphql")
.body(Body::from(to_string(&query)?))?;
.body(Body::from(json::to_string(&query)?))?;

let response = ServiceExt::<Request<Body>>::ready(&mut app)
.await?
@@ -100,7 +100,7 @@ async fn duplicate_username_update() -> Result<()> {
assert_eq!(response.status(), StatusCode::OK);

let body = response.into_body().collect().await?.to_bytes();
let user_response: CreateUserResponse = from_slice(&body)?;
let user_response: CreateUserResponse = json::from_slice(&body)?;
let user_id = user_response.data.create_user.id;

//
@@ -120,14 +120,14 @@ async fn duplicate_username_update() -> Result<()> {
.method(http::Method::POST)
.header(http::header::CONTENT_TYPE, mime::APPLICATION_JSON.as_ref())
.uri("/graphql")
.body(Body::from(to_string(&query)?))?;
.body(Body::from(json::to_string(&query)?))?;

let response = ServiceExt::<Request<Body>>::ready(&mut app)
.await?
.call(request)
.await?;
let body = response.into_body().collect().await?.to_bytes();
let body: Value = from_slice(&body)?;
let body: json::Value = json::from_slice(&body)?;
let error_message = &body["errors"][0]["message"];
assert_eq!(error_message, "username is already in use");

6 changes: 3 additions & 3 deletions tests/user/find_user.rs
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@ use axum::{
};
use cynic::QueryBuilder;
use http_body_util::BodyExt;
use serde_json::{from_slice, to_string, Value};
use serde_json as json;
use tin::route::app;
use tower::util::ServiceExt;

@@ -23,13 +23,13 @@ async fn find_user() -> Result<()> {
.method(http::Method::POST)
.header(http::header::CONTENT_TYPE, mime::APPLICATION_JSON.as_ref())
.uri("/graphql")
.body(Body::from(to_string(&query)?))?;
.body(Body::from(json::to_string(&query)?))?;

let response = app.oneshot(request).await?;
assert_eq!(response.status(), StatusCode::OK);

let body = response.into_body().collect().await?.to_bytes();
let body: Value = from_slice(&body)?;
let body: json::Value = json::from_slice(&body)?;
let error_message = &body["errors"][0]["message"];
assert_eq!(error_message, "user not found");

10 changes: 5 additions & 5 deletions tests/user/keep_existing_full_name.rs
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@ use axum::{
};
use cynic::MutationBuilder;
use http_body_util::BodyExt;
use serde_json::{from_slice, to_string};
use serde_json as json;
use tin::route::app;
use tower::{util::ServiceExt, Service};

@@ -30,14 +30,14 @@ async fn keep_existing_full_name() -> Result<()> {
.method(http::Method::POST)
.header(http::header::CONTENT_TYPE, mime::APPLICATION_JSON.as_ref())
.uri("/graphql")
.body(Body::from(to_string(&query)?))?;
.body(Body::from(json::to_string(&query)?))?;

let response = ServiceExt::<Request<Body>>::ready(&mut app)
.await?
.call(request)
.await?;
let body = response.into_body().collect().await?.to_bytes();
let user_response: CreateUserResponse = from_slice(&body)?;
let user_response: CreateUserResponse = json::from_slice(&body)?;
let user_id = user_response.data.create_user.id;
//
// Update Only the user name
@@ -54,7 +54,7 @@ async fn keep_existing_full_name() -> Result<()> {
.method(http::Method::POST)
.header(http::header::CONTENT_TYPE, mime::APPLICATION_JSON.as_ref())
.uri("/graphql")
.body(Body::from(to_string(&query)?))?;
.body(Body::from(json::to_string(&query)?))?;

let response = ServiceExt::<Request<Body>>::ready(&mut app)
.await?
@@ -64,7 +64,7 @@ async fn keep_existing_full_name() -> Result<()> {
// Make sure the full name preserved
//
let body = response.into_body().collect().await?.to_bytes();
let user_response: UpdateUserResponse = from_slice(&body)?;
let user_response: UpdateUserResponse = json::from_slice(&body)?;
assert_eq!(user_response.data.update_user.name, "khawa1");
assert_eq!(
user_response.data.update_user.full_name,
Loading

0 comments on commit 2996321

Please sign in to comment.