Skip to content

Commit

Permalink
test: ☑️ update model tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rodneylab committed Dec 3, 2024
1 parent f228d7f commit 80fa5c6
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 4 deletions.
3 changes: 1 addition & 2 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ Please describe the tests that you ran to verify your changes. Provide
instructions so we can reproduce. Please also list any relevant details for your
test configuration

- [ ] Test A
- [ ] Test B
- [ ] cargo test run with all tests passing

**Test Configuration**:

Expand Down
72 changes: 70 additions & 2 deletions tests/api/model/post.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ async fn create_draft_mutation_fails_if_db_is_not_initialised() {
}

#[tokio::test]
async fn create_draft_mutation_returns_error_message_if_draft_does_not_exist() {
async fn delete_draft_mutation_returns_error_message_if_draft_does_not_exist() {
// arrange
let db_pool = TestApp::get_db_pool().await;
let title = String::from("New Post Title");
Expand All @@ -109,7 +109,7 @@ async fn create_draft_mutation_returns_error_message_if_draft_does_not_exist() {
}

#[tokio::test]
async fn create_draft_mutation_returns_draft_on_valid_input() {
async fn delete_draft_mutation_returns_draft_on_valid_input() {
// arrange
let db_pool = TestApp::get_db_pool().await;
let title = String::from("New Post Title");
Expand All @@ -134,3 +134,71 @@ async fn create_draft_mutation_returns_draft_on_valid_input() {
})
);
}

#[tokio::test]
async fn delete_draft_mutation_fails_if_db_is_not_initialised() {
// arrange
let database_url = "sqlite://:memory:";

// create database pool manually and omit migrations
let db_pool = SqlitePoolOptions::new()
.max_connections(1)
.connect(database_url)
.await
.unwrap();

// act
let outcome = delete_draft_mutation(&db_pool, 9_999).await.unwrap_err();

// assert
assert_eq!(
format!("{outcome}"),
"error returned from database: (code: 1) no such table: Post"
);
let mut chain = outcome.chain();
assert_eq!(
chain.next().map(|val| format!("{val}")),
Some(String::from(
"error returned from database: (code: 1) no such table: Post"
))
);
assert_eq!(
chain.next().map(|val| format!("{val}")),
Some(String::from("(code: 1) no such table: Post"))
);
assert_eq!(chain.next().map(|val| format!("{val}")), None);
}

#[tokio::test]
async fn publish_mutation_fails_if_db_is_not_initialised() {
// arrange
let database_url = "sqlite://:memory:";

// create database pool manually and omit migrations
let db_pool = SqlitePoolOptions::new()
.max_connections(1)
.connect(database_url)
.await
.unwrap();

// act
let outcome = publish_mutation(&db_pool, 99_999).await.unwrap_err();

// assert
assert_eq!(
format!("{outcome}"),
"error returned from database: (code: 1) no such table: Post"
);
let mut chain = outcome.chain();
assert_eq!(
chain.next().map(|val| format!("{val}")),
Some(String::from(
"error returned from database: (code: 1) no such table: Post"
))
);
assert_eq!(
chain.next().map(|val| format!("{val}")),
Some(String::from("(code: 1) no such table: Post"))
);
assert_eq!(chain.next().map(|val| format!("{val}")), None);
}

0 comments on commit 80fa5c6

Please sign in to comment.