|
5 | 5 | from prepare_commit_msg import extract_commit_msg_title_data |
6 | 6 | from prepare_commit_msg import get_branch_name |
7 | 7 | from prepare_commit_msg import retrieve_linear_issue |
| 8 | +from prepare_commit_msg import prepare_commit_msg |
| 9 | +from prepare_commit_msg import prefix_to_commit_type |
8 | 10 | from prepare_commit_msg import main |
9 | 11 |
|
10 | 12 | from prepare_commit_msg import EDITOR_TEXT |
@@ -98,6 +100,38 @@ def test_retrieve_linear_issue(mock_linear_client): |
98 | 100 | "commit_msg_title": "Branch title", |
99 | 101 | }, |
100 | 102 | ), |
| 103 | + ( |
| 104 | + "dae-75-design-spec-for-configurable-oidc-provider-for-merchants", |
| 105 | + { |
| 106 | + "issue": "DAE-75", |
| 107 | + "commit_type": "", |
| 108 | + "commit_msg_title": "Design spec for configurable oidc provider for merchants", |
| 109 | + }, |
| 110 | + ), |
| 111 | + ( |
| 112 | + "feat/dae-75-design-spec-for-configurable-oidc-provider-for-merchants", |
| 113 | + { |
| 114 | + "issue": "DAE-75", |
| 115 | + "commit_type": "feat", |
| 116 | + "commit_msg_title": "Design spec for configurable oidc provider for merchants", |
| 117 | + }, |
| 118 | + ), |
| 119 | + ( |
| 120 | + "fix/abc-123-very-long-branch-name-with-many-hyphens-and-words", |
| 121 | + { |
| 122 | + "issue": "ABC-123", |
| 123 | + "commit_type": "fix", |
| 124 | + "commit_msg_title": "Very long branch name with many hyphens and words", |
| 125 | + }, |
| 126 | + ), |
| 127 | + ( |
| 128 | + "hotfix/xyz-456-update-critical-security-vulnerability-in-auth-module", |
| 129 | + { |
| 130 | + "issue": "XYZ-456", |
| 131 | + "commit_type": "hotfix", |
| 132 | + "commit_msg_title": "Update critical security vulnerability in auth module", |
| 133 | + }, |
| 134 | + ), |
101 | 135 | ], |
102 | 136 | ) |
103 | 137 | def test_extract_branch_data(branch, expected): |
@@ -143,3 +177,93 @@ def test_extract_branch_data(branch, expected): |
143 | 177 | ) |
144 | 178 | def test_extract_commit_msg_title_data(commit_msg_title, expected): |
145 | 179 | assert extract_commit_msg_title_data(commit_msg_title) == expected |
| 180 | + |
| 181 | + |
| 182 | +@mock.patch("prepare_commit_msg.LINEAR_API_KEY", None) |
| 183 | +@pytest.mark.parametrize( |
| 184 | + "raw_commit_msg, branch, expected_commit_msg", |
| 185 | + [ |
| 186 | + ( |
| 187 | + "", |
| 188 | + "dae-75-design-spec-for-configurable-oidc-provider-for-merchants", |
| 189 | + "DAE-75/feat: Design spec for configurable oidc provider for merchants", |
| 190 | + ), |
| 191 | + ( |
| 192 | + "", |
| 193 | + "feat/dae-75-design-spec-for-configurable-oidc-provider-for-merchants", |
| 194 | + "DAE-75/feat: Design spec for configurable oidc provider for merchants", |
| 195 | + ), |
| 196 | + ( |
| 197 | + "", |
| 198 | + "fix/abc-123-very-long-branch-name-with-many-hyphens-and-words", |
| 199 | + "ABC-123/fix: Very long branch name with many hyphens and words", |
| 200 | + ), |
| 201 | + ( |
| 202 | + "", |
| 203 | + "branch-without-issue", |
| 204 | + "feat: Branch without issue", |
| 205 | + ), |
| 206 | + ], |
| 207 | +) |
| 208 | +def test_prepare_commit_msg_with_default_commit_type(raw_commit_msg, branch, expected_commit_msg): |
| 209 | + result = prepare_commit_msg(raw_commit_msg, branch) |
| 210 | + assert result == expected_commit_msg |
| 211 | + |
| 212 | + |
| 213 | +@mock.patch("prepare_commit_msg.LINEAR_API_KEY", None) |
| 214 | +@mock.patch("prepare_commit_msg.DEFAULT_COMMIT_TYPE", "fix") |
| 215 | +@pytest.mark.parametrize( |
| 216 | + "raw_commit_msg, branch, expected_commit_msg", |
| 217 | + [ |
| 218 | + ( |
| 219 | + "", |
| 220 | + "dae-75-design-spec-for-configurable-oidc-provider-for-merchants", |
| 221 | + "DAE-75/fix: Design spec for configurable oidc provider for merchants", |
| 222 | + ), |
| 223 | + ( |
| 224 | + "", |
| 225 | + "abc-123-branch-without-prefix", |
| 226 | + "ABC-123/fix: Branch without prefix", |
| 227 | + ), |
| 228 | + ( |
| 229 | + "", |
| 230 | + "branch-without-issue", |
| 231 | + "fix: Branch without issue", |
| 232 | + ), |
| 233 | + ], |
| 234 | +) |
| 235 | +def test_prepare_commit_msg_with_custom_default_commit_type(raw_commit_msg, branch, expected_commit_msg): |
| 236 | + result = prepare_commit_msg(raw_commit_msg, branch) |
| 237 | + assert result == expected_commit_msg |
| 238 | + |
| 239 | + |
| 240 | +@mock.patch("prepare_commit_msg.DEFAULT_COMMIT_TYPE", "feat") |
| 241 | +@pytest.mark.parametrize( |
| 242 | + "prefix, expected", |
| 243 | + [ |
| 244 | + ("feat", "feat"), |
| 245 | + ("fix", "fix"), |
| 246 | + ("chore", "chore"), |
| 247 | + ("unknown", "feat"), # Should fall back to DEFAULT_COMMIT_TYPE |
| 248 | + ("invalid", "feat"), # Should fall back to DEFAULT_COMMIT_TYPE |
| 249 | + ], |
| 250 | +) |
| 251 | +def test_prefix_to_commit_type_with_default_feat(prefix, expected): |
| 252 | + result = prefix_to_commit_type(prefix) |
| 253 | + assert result == expected |
| 254 | + |
| 255 | + |
| 256 | +@mock.patch("prepare_commit_msg.DEFAULT_COMMIT_TYPE", "chore") |
| 257 | +@pytest.mark.parametrize( |
| 258 | + "prefix, expected", |
| 259 | + [ |
| 260 | + ("feat", "feat"), |
| 261 | + ("fix", "fix"), |
| 262 | + ("chore", "chore"), |
| 263 | + ("unknown", "chore"), # Should fall back to DEFAULT_COMMIT_TYPE |
| 264 | + ("invalid", "chore"), # Should fall back to DEFAULT_COMMIT_TYPE |
| 265 | + ], |
| 266 | +) |
| 267 | +def test_prefix_to_commit_type_with_default_chore(prefix, expected): |
| 268 | + result = prefix_to_commit_type(prefix) |
| 269 | + assert result == expected |
0 commit comments