|
| 1 | +package com.example.solidconnection.siteuser.fixture; |
| 2 | + |
| 3 | +import com.example.solidconnection.siteuser.domain.AuthType; |
| 4 | +import com.example.solidconnection.siteuser.domain.SiteUser; |
| 5 | +import com.example.solidconnection.type.Role; |
| 6 | +import lombok.RequiredArgsConstructor; |
| 7 | +import org.springframework.boot.test.context.TestComponent; |
| 8 | +import org.springframework.security.crypto.password.PasswordEncoder; |
| 9 | + |
| 10 | +@TestComponent |
| 11 | +@RequiredArgsConstructor |
| 12 | +public class SiteUserFixture { |
| 13 | + |
| 14 | + private final SiteUserFixtureBuilder siteUserFixtureBuilder; |
| 15 | + private final PasswordEncoder passwordEncoder; |
| 16 | + |
| 17 | + /** |
| 18 | + * Creates a default test user with preset email, nickname, role, and password. |
| 19 | + * |
| 20 | + * @return a SiteUser instance representing a standard test user |
| 21 | + */ |
| 22 | + public SiteUser ν
μ€νΈ_μ μ () { |
| 23 | + return siteUserFixtureBuilder.siteUser() |
| 24 | + .email("test@example.com") |
| 25 | + .authType(AuthType.EMAIL) |
| 26 | + .nickname("ν
μ€νΈμ μ ") |
| 27 | + .profileImageUrl("profileImageUrl") |
| 28 | + .role(Role.MENTEE) |
| 29 | + .password("password123") |
| 30 | + .create(); |
| 31 | + } |
| 32 | + |
| 33 | + /** |
| 34 | + * Creates a test user with a unique email based on the given index and the specified nickname. |
| 35 | + * |
| 36 | + * @param index the numeric value to include in the user's email address for uniqueness |
| 37 | + * @param nickname the nickname to assign to the user |
| 38 | + * @return a new SiteUser instance with the specified nickname and a unique email |
| 39 | + */ |
| 40 | + public SiteUser ν
μ€νΈ_μ μ (int index, String nickname) { |
| 41 | + return siteUserFixtureBuilder.siteUser() |
| 42 | + .email("test" + index + " @example.com") |
| 43 | + .authType(AuthType.EMAIL) |
| 44 | + .nickname(nickname) |
| 45 | + .profileImageUrl("profileImageUrl") |
| 46 | + .role(Role.MENTEE) |
| 47 | + .password("password123") |
| 48 | + .create(); |
| 49 | + } |
| 50 | + |
| 51 | + /** |
| 52 | + * Creates a test user with the specified email and authentication type. |
| 53 | + * |
| 54 | + * @param email the email address for the test user |
| 55 | + * @param authType the authentication type for the test user |
| 56 | + * @return a SiteUser instance with the given email and auth type, default nickname, profile image URL, mentee role, and password |
| 57 | + */ |
| 58 | + public SiteUser ν
μ€νΈ_μ μ (String email, AuthType authType) { |
| 59 | + return siteUserFixtureBuilder.siteUser() |
| 60 | + .email(email) |
| 61 | + .authType(authType) |
| 62 | + .nickname("ν
μ€νΈμ μ ") |
| 63 | + .profileImageUrl("profileImageUrl") |
| 64 | + .role(Role.MENTEE) |
| 65 | + .password("password123") |
| 66 | + .create(); |
| 67 | + } |
| 68 | + |
| 69 | + /** |
| 70 | + * Creates a test user with the specified email and password, encoding the password. |
| 71 | + * |
| 72 | + * @param email the email address for the test user |
| 73 | + * @param password the raw password to be encoded for the test user |
| 74 | + * @return a SiteUser instance with the given email and encoded password, default nickname, profile image URL, and mentee role |
| 75 | + */ |
| 76 | + public SiteUser ν
μ€νΈ_μ μ (String email, String password) { |
| 77 | + return siteUserFixtureBuilder.siteUser() |
| 78 | + .email(email) |
| 79 | + .authType(AuthType.EMAIL) |
| 80 | + .nickname("ν
μ€νΈμ μ ") |
| 81 | + .profileImageUrl("profileImageUrl") |
| 82 | + .role(Role.MENTEE) |
| 83 | + .password(passwordEncoder.encode(password)) |
| 84 | + .create(); |
| 85 | + } |
| 86 | + |
| 87 | + /** |
| 88 | + * Creates a test user with a duplicated nickname for testing nickname collision scenarios. |
| 89 | + * |
| 90 | + * @return a SiteUser instance with a fixed email, nickname "μ€λ³΅λλ€μ", and default attributes |
| 91 | + */ |
| 92 | + public SiteUser μ€λ³΅_λλ€μ_ν
μ€νΈ_μ μ () { |
| 93 | + return siteUserFixtureBuilder.siteUser() |
| 94 | + .email("duplicated@example.com") |
| 95 | + .authType(AuthType.EMAIL) |
| 96 | + .nickname("μ€λ³΅λλ€μ") |
| 97 | + .profileImageUrl("profileImageUrl") |
| 98 | + .role(Role.MENTEE) |
| 99 | + .password("password123") |
| 100 | + .create(); |
| 101 | + } |
| 102 | + |
| 103 | + /** |
| 104 | + * Creates a test user with a custom profile image URL and password. |
| 105 | + * |
| 106 | + * @return a SiteUser instance with email "customProfile@example.com", nickname "컀μ€ν
νλ‘ν", role MENTEE, authentication type EMAIL, profile image URL "profile/profileImageUrl", and password "customPassword123" |
| 107 | + */ |
| 108 | + public SiteUser 컀μ€ν
_νλ‘ν_ν
μ€νΈ_μ μ () { |
| 109 | + return siteUserFixtureBuilder.siteUser() |
| 110 | + .email("customProfile@example.com") |
| 111 | + .authType(AuthType.EMAIL) |
| 112 | + .nickname("컀μ€ν
νλ‘ν") |
| 113 | + .profileImageUrl("profile/profileImageUrl") |
| 114 | + .role(Role.MENTEE) |
| 115 | + .password("customPassword123") |
| 116 | + .create(); |
| 117 | + } |
| 118 | + |
| 119 | + /** |
| 120 | + * Creates a test admin user with predefined email, nickname, profile image URL, and password. |
| 121 | + * |
| 122 | + * @return a SiteUser instance representing an admin user for testing purposes |
| 123 | + */ |
| 124 | + public SiteUser ν
μ€νΈ_μ΄λλ―Ό() { |
| 125 | + return siteUserFixtureBuilder.siteUser() |
| 126 | + .email("admin@example.com") |
| 127 | + .authType(AuthType.EMAIL) |
| 128 | + .nickname("ν
μ€νΈμ΄λλ―Ό") |
| 129 | + .profileImageUrl("profileImageUrl") |
| 130 | + .role(Role.ADMIN) |
| 131 | + .password("admin123") |
| 132 | + .create(); |
| 133 | + } |
| 134 | +} |
0 commit comments