-
Notifications
You must be signed in to change notification settings - Fork 7
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
5 changed files
with
129 additions
and
1 deletion.
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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
let | ||
nixpkgs = import <nixpkgs> {}; | ||
in | ||
with nixpkgs; | ||
stdenv.mkDerivation { | ||
name = "echo-server"; | ||
buildInputs = [ | ||
cargo | ||
rustc | ||
pkgconfig | ||
openssl.dev | ||
nix | ||
protobuf | ||
]; | ||
OPENSSL_DEV=openssl.dev; | ||
} |
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,78 @@ | ||
use { | ||
crate::context::EchoServerContext, | ||
echo_server::handlers::create_tenant::TenantRegisterBody, | ||
random_string::generate, | ||
test_context::test_context, | ||
}; | ||
|
||
#[test_context(EchoServerContext)] | ||
#[tokio::test] | ||
async fn tenant_update_fcm(ctx: &mut EchoServerContext) { | ||
let charset = "1234567890"; | ||
let random_tenant_id = generate(12, charset); | ||
let payload = TenantRegisterBody { | ||
id: random_tenant_id.clone(), | ||
}; | ||
|
||
// Register tenant | ||
let client = reqwest::Client::new(); | ||
let response = client | ||
.post(format!("http://{}/tenants", ctx.server.public_addr)) | ||
.json(&payload) | ||
.send() | ||
.await | ||
.expect("Call failed"); | ||
|
||
// Send valid API Key | ||
let api_key = env!("ECHO_TEST_FCM_KEY"); | ||
let form = reqwest::multipart::Form::new().text("api_key", api_key); | ||
|
||
let response = client | ||
.post(format!( | ||
"http://{}/tenants/{}/fcm", | ||
ctx.server.public_addr, &random_tenant_id | ||
)) | ||
.multipart(&form) | ||
.send() | ||
.await | ||
.expect("Call failed"); | ||
|
||
assert!( | ||
response.status().is_success(), | ||
"Response was not successful" | ||
); | ||
} | ||
|
||
#[test_context(EchoServerContext)] | ||
#[tokio::test] | ||
async fn tenant_update_fcm_bad(ctx: &mut EchoServerContext) { | ||
let charset = "1234567890"; | ||
let random_tenant_id = generate(12, charset); | ||
let payload = TenantRegisterBody { | ||
id: random_tenant_id.clone(), | ||
}; | ||
|
||
// Register tenant | ||
let client = reqwest::Client::new(); | ||
let response = client | ||
.post(format!("http://{}/tenants", ctx.server.public_addr)) | ||
.json(&payload) | ||
.send() | ||
.await | ||
.expect("Call failed"); | ||
|
||
// Send invalid API Key | ||
let form = reqwest::multipart::Form::new().text("api_key", "invalid-key"); | ||
|
||
let response = client | ||
.post(format!( | ||
"http://{}/tenants/{}/fcm", | ||
ctx.server.public_addr, &random_tenant_id | ||
)) | ||
.multipart(&form) | ||
.send() | ||
.await | ||
.expect("Call failed"); | ||
|
||
assert!(!response.status().is_success(), "Response was successful"); | ||
} |
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