-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(newsletter): support public double opt-in (#187)
* feature(newsletter): support public double opt-in This das the route /api/v1/newsletter to allow public sign up to our newsletter, once we made it non-private basket * dynamic url * add test
- Loading branch information
Showing
4 changed files
with
117 additions
and
7 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
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,14 +1,15 @@ | ||
use crate::helpers::app::test_app_with_login; | ||
use crate::helpers::app::{init_test, test_app_with_login}; | ||
use crate::helpers::db::reset; | ||
use crate::helpers::http_client::TestHttpClient; | ||
use crate::helpers::{read_json, wait_for_stubr}; | ||
use actix_web::test; | ||
use anyhow::Error; | ||
use serde_json::json; | ||
use stubr::{Config, Stubr}; | ||
|
||
#[actix_rt::test] | ||
#[stubr::mock(port = 4321)] | ||
async fn whoami_settings_test() -> Result<(), Error> { | ||
async fn settings_newsletter_test() -> Result<(), Error> { | ||
let pool = reset()?; | ||
wait_for_stubr().await?; | ||
let app = test_app_with_login(&pool).await?; | ||
|
@@ -41,7 +42,10 @@ async fn whoami_settings_test() -> Result<(), Error> { | |
|
||
drop(stubr); | ||
let stubr = Stubr::start_blocking_with( | ||
vec!["tests/stubs", "tests/test_specific_stubs/newsletter"], | ||
vec![ | ||
"tests/stubs", | ||
"tests/test_specific_stubs/newsletter/basket_lookup_user.json", | ||
], | ||
Config { | ||
port: Some(4321), | ||
latency: None, | ||
|
@@ -67,3 +71,45 @@ async fn whoami_settings_test() -> Result<(), Error> { | |
drop(stubr); | ||
Ok(()) | ||
} | ||
|
||
#[actix_rt::test] | ||
#[stubr::mock(port = 4321)] | ||
async fn anonymous_newsletter_test() -> Result<(), Error> { | ||
let pool = reset()?; | ||
wait_for_stubr().await?; | ||
let app = test_app_with_login(&pool).await.unwrap(); | ||
let service = test::init_service(app).await; | ||
let request = test::TestRequest::post() | ||
.set_json(json!({ "email": "[email protected]"})) | ||
.uri("/api/v1/newsletter") | ||
.to_request(); | ||
let newsletter_res = test::call_service(&service, request).await; | ||
|
||
assert!(newsletter_res.status().is_success()); | ||
|
||
drop(stubr); | ||
Ok(()) | ||
} | ||
|
||
#[actix_rt::test] | ||
async fn anonymous_newsletter_error_test() -> Result<(), Error> { | ||
let (_, stubr) = init_test(vec![ | ||
"tests/stubs", | ||
"tests/test_specific_stubs/newsletter/basket_subscribe_error.json", | ||
]) | ||
.await?; | ||
|
||
let pool = reset()?; | ||
let app = test_app_with_login(&pool).await.unwrap(); | ||
let service = test::init_service(app).await; | ||
let request = test::TestRequest::post() | ||
.set_json(json!({ "email": "[email protected]"})) | ||
.uri("/api/v1/newsletter") | ||
.to_request(); | ||
let newsletter_res = test::call_service(&service, request).await; | ||
|
||
assert!(newsletter_res.status().is_server_error()); | ||
|
||
drop(stubr); | ||
Ok(()) | ||
} |
17 changes: 17 additions & 0 deletions
17
tests/test_specific_stubs/newsletter/basket_subscribe_error.json
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,17 @@ | ||
{ | ||
"uuid": "basket_subscribe", | ||
"priority": 1, | ||
"request": { | ||
"method": "POST", | ||
"url": "/news/subscribe/" | ||
}, | ||
"response": { | ||
"status": 500, | ||
"headers": { | ||
"Content-Type": "application/json" | ||
}, | ||
"jsonBody": { | ||
"status": "error" | ||
} | ||
} | ||
} |