From 7f45d81eb9cb5df47cf3f71c9c340b6a55fcb76e Mon Sep 17 00:00:00 2001 From: Chanhyuk Yang Date: Sun, 10 Dec 2023 23:41:13 +0900 Subject: [PATCH] fix: fix test initialization --- .../springboot/domain/emoji/dao/EmojiDaoTest.kt | 13 +++++++++++++ .../springboot/domain/post/dao/PostDaoTest.kt | 14 ++++++++++++-- .../domain/reaction/dao/ReactionDaoTest.kt | 6 ++++++ .../springboot/domain/user/dao/UserDaoTest.kt | 6 ++++++ 4 files changed, 37 insertions(+), 2 deletions(-) diff --git a/springboot/src/test/kotlin/com/goliath/emojihub/springboot/domain/emoji/dao/EmojiDaoTest.kt b/springboot/src/test/kotlin/com/goliath/emojihub/springboot/domain/emoji/dao/EmojiDaoTest.kt index f3be699a..7aad5f0e 100644 --- a/springboot/src/test/kotlin/com/goliath/emojihub/springboot/domain/emoji/dao/EmojiDaoTest.kt +++ b/springboot/src/test/kotlin/com/goliath/emojihub/springboot/domain/emoji/dao/EmojiDaoTest.kt @@ -79,6 +79,12 @@ internal class EmojiDaoTest { for (emoji in testDto.emojiList) { testDB.collection(EMOJI_COLLECTION_NAME.string).document(emoji.id).set(emoji) } + var docs = testDB.collection(EMOJI_COLLECTION_NAME.string).get().get().documents + var a = 1 + while (docs.size != testDto.emojiList.size && a <= 5) { + docs = testDB.collection(EMOJI_COLLECTION_NAME.string).get().get().documents + a++ + } } } @@ -236,6 +242,13 @@ internal class EmojiDaoTest { testDB.collection(EMOJI_COLLECTION_NAME.string) .document(emojiId) .set(emojiList[3]) + result = emojiDao.existsEmoji(emojiId) + var b = 1 + while (!result && b <= 5) { + result = emojiDao.existsEmoji(emojiId) + b++ + } + assertEquals(result, true) } @Test diff --git a/springboot/src/test/kotlin/com/goliath/emojihub/springboot/domain/post/dao/PostDaoTest.kt b/springboot/src/test/kotlin/com/goliath/emojihub/springboot/domain/post/dao/PostDaoTest.kt index 0069f279..2cc99f39 100644 --- a/springboot/src/test/kotlin/com/goliath/emojihub/springboot/domain/post/dao/PostDaoTest.kt +++ b/springboot/src/test/kotlin/com/goliath/emojihub/springboot/domain/post/dao/PostDaoTest.kt @@ -65,6 +65,12 @@ internal class PostDaoTest { for (post in testDto.postList) { testDB.collection(POST_COLLECTION_NAME.string).document(post.id).set(post) } + var docs = testDB.collection(POST_COLLECTION_NAME.string).get().get().documents + var a = 1 + while (docs.size != testDto.postList.size && a <= 5) { + docs = testDB.collection(POST_COLLECTION_NAME.string).get().get().documents + a++ + } } } @@ -124,8 +130,12 @@ internal class PostDaoTest { val index = 1 val count = testDto.postSize val postListForUser = mutableListOf() - postListForUser.add(postList[1]) - postListForUser.add(postList[0]) + for (post in testDto.postList) { + if (post.created_by == username) { + postListForUser.add(post) + } + } + postListForUser.sortByDescending { it.created_at } Mockito.`when`(db.collection(POST_COLLECTION_NAME.string)) .thenReturn(testDB.collection(POST_COLLECTION_NAME.string)) diff --git a/springboot/src/test/kotlin/com/goliath/emojihub/springboot/domain/reaction/dao/ReactionDaoTest.kt b/springboot/src/test/kotlin/com/goliath/emojihub/springboot/domain/reaction/dao/ReactionDaoTest.kt index 43796abe..72dd39d4 100644 --- a/springboot/src/test/kotlin/com/goliath/emojihub/springboot/domain/reaction/dao/ReactionDaoTest.kt +++ b/springboot/src/test/kotlin/com/goliath/emojihub/springboot/domain/reaction/dao/ReactionDaoTest.kt @@ -62,6 +62,12 @@ internal class ReactionDaoTest { for (reaction in testDto.reactionList) { testDB.collection(REACTION_COLLECTION_NAME.string).document(reaction.id).set(reaction) } + var docs = testDB.collection(REACTION_COLLECTION_NAME.string).get().get().documents + var a = 1 + while (docs.size != testDto.reactionList.size && a <= 5) { + docs = testDB.collection(REACTION_COLLECTION_NAME.string).get().get().documents + a++ + } } } diff --git a/springboot/src/test/kotlin/com/goliath/emojihub/springboot/domain/user/dao/UserDaoTest.kt b/springboot/src/test/kotlin/com/goliath/emojihub/springboot/domain/user/dao/UserDaoTest.kt index b9ad5973..a976f4e0 100644 --- a/springboot/src/test/kotlin/com/goliath/emojihub/springboot/domain/user/dao/UserDaoTest.kt +++ b/springboot/src/test/kotlin/com/goliath/emojihub/springboot/domain/user/dao/UserDaoTest.kt @@ -64,6 +64,12 @@ internal class UserDaoTest { for (user in testDto.userList) { testDB.collection(USER_COLLECTION_NAME.string).document(user.username).set(user) } + var docs = testDB.collection(USER_COLLECTION_NAME.string).get().get().documents + var a = 1 + while (docs.size != testDto.userList.size && a <= 5) { + docs = testDB.collection(USER_COLLECTION_NAME.string).get().get().documents + a++ + } } }