-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into building-name
- Loading branch information
Showing
5 changed files
with
110 additions
and
14 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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { Course } from './Course'; | ||
import { Review } from './Review'; | ||
|
||
export type GetCourseWithReviewsPayload = { | ||
course: Course; | ||
reviews: Review[]; | ||
}; |
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 |
---|---|---|
|
@@ -195,6 +195,12 @@ mod tests { | |
} | ||
} | ||
|
||
#[derive(Debug, Deserialize, Serialize)] | ||
pub(crate) struct GetCourseWithReviewsPayload { | ||
pub(crate) course: Course, | ||
pub(crate) reviews: Vec<Review>, | ||
} | ||
|
||
#[tokio::test] | ||
async fn courses_route_works() { | ||
let TestContext { db, app, .. } = TestContext::new().await; | ||
|
@@ -326,6 +332,71 @@ mod tests { | |
); | ||
} | ||
|
||
#[tokio::test] | ||
async fn can_get_course_with_reviews() { | ||
let TestContext { | ||
db, | ||
mut app, | ||
session_store, | ||
.. | ||
} = TestContext::new().await; | ||
|
||
db.initialize(InitializeOptions { | ||
source: seed(), | ||
..Default::default() | ||
}) | ||
.await | ||
.unwrap(); | ||
|
||
let cookie = mock_login(session_store, "test", "[email protected]").await; | ||
|
||
let review = json!({ | ||
"content": "test", | ||
"course_id": "MATH240", | ||
"instructors": ["Adrian Roshan Vetta"], | ||
"rating": 5, | ||
"difficulty": 5 | ||
}) | ||
.to_string(); | ||
|
||
let response = app | ||
.call( | ||
Request::builder() | ||
.method(http::Method::POST) | ||
.header("Cookie", cookie.clone()) | ||
.header("Content-Type", "application/json") | ||
.uri("/api/reviews") | ||
.body(Body::from(review)) | ||
.unwrap(), | ||
) | ||
.await | ||
.unwrap(); | ||
|
||
assert_eq!(response.status(), StatusCode::OK); | ||
assert_eq!(db.find_reviews_by_user_id("test").await.unwrap().len(), 1); | ||
|
||
let response = app | ||
.call( | ||
Request::builder() | ||
.uri("/api/courses/MATH240?with_reviews=true") | ||
.body(Body::empty()) | ||
.unwrap(), | ||
) | ||
.await | ||
.unwrap(); | ||
|
||
assert_eq!(response.status(), StatusCode::OK); | ||
|
||
let payload = response.convert::<GetCourseWithReviewsPayload>().await; | ||
|
||
assert_eq!( | ||
payload.course, | ||
db.find_course_by_id("MATH240").await.unwrap().unwrap() | ||
); | ||
|
||
assert_eq!(payload.reviews.len(), 1); | ||
} | ||
|
||
#[tokio::test] | ||
async fn course_by_id_invalid_course_code() { | ||
let TestContext { db, app, .. } = TestContext::new().await; | ||
|