-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
25 changed files
with
160 additions
and
38 deletions.
There are no files selected for viewing
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 |
---|---|---|
|
@@ -4,4 +4,5 @@ | |
.env | ||
/.vscode | ||
tarpaulin-report.* | ||
codecov | ||
codecov | ||
trampolin.sh |
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
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
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
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 |
---|---|---|
|
@@ -99,4 +99,4 @@ impl Github { | |
Err(_) => Err(Error::InternalServer(response)), | ||
} | ||
} | ||
} | ||
} |
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 |
---|---|---|
|
@@ -2,4 +2,4 @@ | |
extern crate serde; | ||
|
||
pub mod order; | ||
pub mod pagination; | ||
pub mod pagination; |
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 |
---|---|---|
@@ -1,9 +1,9 @@ | ||
#[derive(Serialize)] | ||
pub struct Pagination<T>{ | ||
#[derive(Serialize, Deserialize)] | ||
pub struct Pagination<T> { | ||
pub page: u64, | ||
pub per_page: u64, | ||
pub order_by: Vec<String>, | ||
pub data: Vec<T>, | ||
pub total_items: u64, | ||
pub last_page: u64 | ||
} | ||
pub last_page: u64, | ||
} |
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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
create table github_repositories( | ||
id uuid primary key default uuid_generate_v4() not null, | ||
project uuid references github_projects(id) not null, | ||
project uuid not null references github_projects(id) on delete cascade, | ||
repository_name varchar(255) not null, | ||
unique(project, repository_name) | ||
) |
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,74 @@ | ||
use crate::request::request; | ||
use error::Result; | ||
use reqwest::Method; | ||
use sea_orm::{ | ||
prelude::Uuid, sea_query::OnConflict, DatabaseConnection, EntityTrait, ModelTrait, Set, | ||
}; | ||
use store::{cryptocurrencies, github_projects, github_repositories, objects::CryptoCurrencyView}; | ||
use support::pagination::Pagination; | ||
|
||
/// | ||
/// Test function for /api/v1/crypto | ||
/// | ||
pub async fn api_v1_crypto(sea_pool: &DatabaseConnection) { | ||
let (github, crypto) = setup(sea_pool).await.unwrap(); | ||
|
||
let response: Pagination<CryptoCurrencyView> = | ||
request("/api/v1/crypto", Method::GET, ()).await.unwrap(); | ||
|
||
assert!(!response.data.is_empty()); | ||
|
||
let response: Pagination<CryptoCurrencyView> = | ||
request("/api/v1/crypto?search=oooooogggggaaaaa", Method::GET, ()) | ||
.await | ||
.unwrap(); | ||
|
||
assert!(response.data.is_empty()); | ||
|
||
github.delete(sea_pool).await.unwrap(); | ||
crypto.delete(sea_pool).await.unwrap(); | ||
} | ||
|
||
async fn setup( | ||
sea_pool: &DatabaseConnection, | ||
) -> Result<(github_projects::Model, cryptocurrencies::Model)> { | ||
let github = github_projects::ActiveModel { | ||
id: Set(Uuid::new_v4()), | ||
name: Set("TestGit".to_owned()), | ||
}; | ||
|
||
let github = github_projects::Entity::insert(github) | ||
.on_conflict( | ||
OnConflict::column(github_projects::Column::Name) | ||
.do_nothing() | ||
.to_owned(), | ||
) | ||
.exec_with_returning(sea_pool) | ||
.await?; | ||
|
||
let crypto = cryptocurrencies::ActiveModel { | ||
id: Set(Uuid::new_v4()), | ||
name: Set("Test coin 1000".to_owned()), | ||
coingecko_id: Set("test-coin-at-coingecko".to_owned()), | ||
github: Set(Some(github.id)), | ||
..Default::default() | ||
}; | ||
|
||
let crypto = cryptocurrencies::Entity::insert(crypto) | ||
.on_conflict(OnConflict::default().do_nothing().to_owned()) | ||
.exec_with_returning(sea_pool) | ||
.await?; | ||
|
||
let github_repo = github_repositories::ActiveModel { | ||
project: Set(github.id), | ||
repository_name: Set("good-repo".to_owned()), | ||
..Default::default() | ||
}; | ||
|
||
github_repositories::Entity::insert(github_repo) | ||
.on_conflict(OnConflict::default().do_nothing().to_owned()) | ||
.exec(sea_pool) | ||
.await?; | ||
|
||
Ok((github, crypto)) | ||
} |
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,7 @@ | ||
use sea_orm::DatabaseConnection; | ||
|
||
mod get; | ||
|
||
pub async fn test(sea_pool: &DatabaseConnection) { | ||
get::api_v1_crypto(sea_pool).await | ||
} |
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 |
---|---|---|
@@ -1,5 +1,9 @@ | ||
pub (crate) mod request; | ||
pub(crate) mod cryptocurrencies; | ||
#[allow(unused)] | ||
#[macro_use] | ||
extern crate adtest; | ||
|
||
pub mod cryptocurrencies; | ||
pub mod request; | ||
|
||
#[cfg(test)] | ||
mod e2e_api; | ||
mod e2e_api; |
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,16 @@ | ||
use error::{Error, Result}; | ||
use reqwest::{Client, Method}; | ||
use serde::{de::DeserializeOwned, Serialize}; | ||
|
||
pub async fn request<U, B, R>(url: U, method: Method, body: B) -> Result<R> | ||
where | ||
U: Into<String>, | ||
B: Serialize, | ||
R: DeserializeOwned + 'static, | ||
{ | ||
let client = Client::default(); | ||
let url = format!("http://localhost:1111{}", url.into()); | ||
let request = client.request(method, url).json(&body).send().await?; | ||
let response_body = request.text().await?; | ||
serde_json::from_str(&response_body).map_err(Error::from) | ||
} |