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
Show file tree
Hide file tree
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
Expand Up @@ -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;

Expand All @@ -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(())
Expand All @@ -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
Expand Up @@ -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;

Expand All @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions tests/user/create_user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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?;
Expand Down
6 changes: 3 additions & 3 deletions tests/user/create_user_without_full_name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);

Expand Down
12 changes: 6 additions & 6 deletions tests/user/delete_user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand All @@ -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?
Expand All @@ -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;
Expand All @@ -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?
Expand All @@ -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");

Expand Down
18 changes: 9 additions & 9 deletions tests/user/duplicate_username.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand All @@ -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?
Expand All @@ -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");

Expand All @@ -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?
Expand All @@ -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?
Expand All @@ -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;

//
Expand All @@ -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");

Expand Down
6 changes: 3 additions & 3 deletions tests/user/find_user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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");

Expand Down
10 changes: 5 additions & 5 deletions tests/user/keep_existing_full_name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand All @@ -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
Expand All @@ -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?
Expand All @@ -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,
Expand Down
Loading

0 comments on commit 2996321

Please sign in to comment.