-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
チャンネル取得機能のテストの実装 #61
Merged
Merged
チャンネル取得機能のテストの実装 #61
Changes from 7 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
93b7ebb
チャンネル取得機能のテストの実装
92c3225
fmt
b905873
merge main
9f34ad7
仮修正
cb63544
fix
9a68c15
fixx
098b254
async test
0dd7b9e
channelのモデル変更とそれによるテストの追加編集
38ac761
mockがvectorを受け取れるようにした
2098991
fmt
58c5b42
fix
ca721cb
fix ci
37b4ea5
fix
df6d50d
fixx ci
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
|
@@ -15,4 +15,5 @@ sea-orm = { version = "0.12", features = [ | |
"sqlx-postgres", | ||
"runtime-tokio-native-tls", | ||
"macros", | ||
"mock" | ||
] } |
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 +1,2 @@ | ||
pub mod channel; | ||
pub mod test; |
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 @@ | ||
use async_graphql::SimpleObject; | ||
|
||
#[derive(SimpleObject, Debug, PartialEq, Eq)] | ||
pub struct Channel { | ||
pub id: String, | ||
pub name: String, | ||
// User型を実装したら書き換える | ||
pub owner: String, | ||
pub description: Option<String>, | ||
pub created_at: String, | ||
pub archived: bool, | ||
pub private: bool, | ||
// User型を実装したら書き換える | ||
pub users: Vec<String>, | ||
// message型を実装したら書き換える | ||
pub messages: Vec<String>, | ||
} |
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 +1,2 @@ | ||
pub mod channel; | ||
pub mod test; |
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,60 @@ | ||
use crate::context::Context; | ||
use crate::generate::entities::channel::Model; | ||
use crate::models::channel::Channel; | ||
|
||
pub async fn get_all_channel(_ctx: &Context) -> Result<Vec<Channel>, ()> { | ||
todo!("generate::entities::channel::Model to models::channel::Channel") | ||
} | ||
|
||
#[cfg(test)] | ||
mod test { | ||
use super::get_all_channel; | ||
use crate::context::Context; | ||
use crate::generate::entities::channel; | ||
use crate::models::channel::Channel; | ||
use sea_orm::prelude::*; | ||
use sea_orm::MockDatabase; | ||
|
||
#[tokio::test] | ||
async fn すべてのチャンネルを取得する() { | ||
// Arrange | ||
let db: DatabaseConnection = MockDatabase::new(sea_orm::DatabaseBackend::Postgres) | ||
.append_query_results([vec![channel::Model { | ||
id: "0".to_string(), | ||
channel_name: "hoge".to_string(), | ||
description: Some("huga".to_string()), | ||
is_private: false, | ||
created_user_id: "0".to_string(), | ||
created_at: DateTime::parse_from_str("2024-08-08 00:00:00", "%Y-%m-%d %H:%M:%S") | ||
.unwrap(), | ||
updated_at: None, | ||
archive_at: None, | ||
deleted_at: None, | ||
}]]) | ||
.into_connection(); | ||
|
||
let context = Context { | ||
noharu36 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
env: "harukun".to_string(), | ||
db, | ||
}; | ||
|
||
// Action | ||
let result = get_all_channel(&context).await.unwrap(); | ||
|
||
// Assert | ||
assert_eq!( | ||
result, | ||
vec![Channel { | ||
id: "0".to_string(), | ||
name: "hoge".to_string(), | ||
owner: "0".to_string(), | ||
description: Some("huga".to_string()), | ||
created_at: "2024-08-08 00:00:00".to_string(), | ||
archived: false, | ||
private: false, | ||
users: vec!["eraser".to_string(), "yuorei".to_string()], | ||
messages: vec!["welcome".to_string(), "zoo".to_string()] | ||
}], | ||
) | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ownerみたいな別のモデルを参照するやつは多分ComplexObject使うことになるのでいらないはず
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ComplexObject、詳しく見てないんでわからないんですけど、自分のフィールドを見て新しいフィールドを擬似的に作成してるものじゃないですか?使い方違うような気がする???
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ComplexObjectの認識は合ってると思う。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
色々考えてどっちでもいい感ありそうだなってなっている。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
俺の認識としてはComplexObjectはここのトレードオフのための仕組みだと思ってる。間違っていたらすまん。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
この程度のものに関してはComplexObjectは使わないで、本当に重い処理(例えば検索付きのフィールドとか)に関してComplexObjectで切り分けるとかになるのかな?