-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* test: support organization * fix: correct the request URL
- Loading branch information
Showing
2 changed files
with
101 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
use std::path::Path; | ||
|
||
use algohub_server::{ | ||
models::{ | ||
account::Register, | ||
organization::CreateOrganization, | ||
response::{Empty, Response}, | ||
OwnedCredentials, Token, | ||
}, | ||
routes::organization::{CreateOrgResponse, OrgData}, | ||
}; | ||
use anyhow::Result; | ||
use rocket::local::asynchronous::Client; | ||
|
||
#[rocket::async_test] | ||
async fn test_organization() -> Result<()> { | ||
let rocket = algohub_server::rocket().await; | ||
|
||
let client = Client::tracked(rocket).await?; | ||
|
||
println!("Testing organization..."); | ||
let response = client | ||
.post("/account/create") | ||
.json(&Register { | ||
username: "fu050409".to_string(), | ||
password: "password".to_string(), | ||
email: "[email protected]".to_string(), | ||
}) | ||
.dispatch() | ||
.await; | ||
|
||
assert_eq!(response.status().code, 200); | ||
|
||
let Response { | ||
success, | ||
message: _, | ||
data, | ||
} = response.into_json().await.unwrap(); | ||
let data: OwnedCredentials = data.unwrap(); | ||
|
||
let id = data.id.clone(); | ||
let token = data.token.clone(); | ||
|
||
assert!(success); | ||
|
||
let response = client | ||
.post("/org/create") | ||
.json(&OrgData { | ||
id: &id, | ||
token: &token, | ||
org: CreateOrganization { | ||
name: "test_organization".to_string(), | ||
display_name: None, | ||
description: None, | ||
}, | ||
}) | ||
.dispatch() | ||
.await; | ||
|
||
assert_eq!(response.status().code, 200); | ||
|
||
let Response { | ||
success, | ||
message: _, | ||
data, | ||
} = response.into_json().await.unwrap(); | ||
let data: CreateOrgResponse = data.unwrap(); | ||
|
||
assert!(success); | ||
println!("Created organization: {}", data.id); | ||
|
||
let response = client | ||
.post(format!("/org/delete/{}", id)) | ||
.json(&OrgData { | ||
id: &id, | ||
token: &token, | ||
org: CreateOrganization { | ||
name: "test_organization".to_string(), | ||
display_name: None, | ||
description: None, | ||
}, | ||
}) | ||
.dispatch() | ||
.await; | ||
|
||
response.into_json::<Response<Empty>>().await.unwrap(); | ||
|
||
assert!(!Path::new("content").join(id.clone()).exists()); | ||
|
||
client | ||
.post(format!("/account/delete/{}", id)) | ||
.json(&Token { token: &token }) | ||
.dispatch() | ||
.await | ||
.into_json::<Response<Empty>>() | ||
.await | ||
.unwrap(); | ||
|
||
Ok(()) | ||
} |