|
158 | 158 | #:body (github-review-body (not (null? comments)) file-count) |
159 | 159 | #:event (if (empty? comments) "APPROVE" "COMMENT") |
160 | 160 | #:comments comments)) |
| 161 | + |
| 162 | + |
| 163 | +(module+ test |
| 164 | + (require rackunit) |
| 165 | + |
| 166 | + (test-case "github-review-comment-jsexpr" |
| 167 | + (test-case "single-line comment" |
| 168 | + (define comment |
| 169 | + (github-review-comment |
| 170 | + #:path "file.rkt" |
| 171 | + #:body "Fix this issue" |
| 172 | + #:start-line 10 |
| 173 | + #:end-line 10 |
| 174 | + #:start-side "RIGHT" |
| 175 | + #:end-side "RIGHT")) |
| 176 | + (define result (github-review-comment-jsexpr comment)) |
| 177 | + (check-equal? (hash-ref result 'path) "file.rkt") |
| 178 | + (check-equal? (hash-ref result 'body) "Fix this issue") |
| 179 | + (check-equal? (hash-ref result 'line) 10) |
| 180 | + (check-equal? (hash-ref result 'side) "RIGHT") |
| 181 | + (check-false (hash-has-key? result 'start_line)) |
| 182 | + (check-false (hash-has-key? result 'start_side))) |
| 183 | + (test-case "multi-line comment" |
| 184 | + (define comment |
| 185 | + (github-review-comment |
| 186 | + #:path "another.rkt" |
| 187 | + #:body "Multi-line issue" |
| 188 | + #:start-line 5 |
| 189 | + #:end-line 8 |
| 190 | + #:start-side "LEFT" |
| 191 | + #:end-side "RIGHT")) |
| 192 | + (define result (github-review-comment-jsexpr comment)) |
| 193 | + (check-equal? (hash-ref result 'path) "another.rkt") |
| 194 | + (check-equal? (hash-ref result 'body) "Multi-line issue") |
| 195 | + (check-equal? (hash-ref result 'start_line) 5) |
| 196 | + (check-equal? (hash-ref result 'line) 8) |
| 197 | + (check-equal? (hash-ref result 'start_side) "LEFT") |
| 198 | + (check-equal? (hash-ref result 'side) "RIGHT"))) |
| 199 | + (test-case "github-review-request-jsexpr" |
| 200 | + (define comment1 |
| 201 | + (github-review-comment |
| 202 | + #:path "file1.rkt" |
| 203 | + #:body "Comment 1" |
| 204 | + #:start-line 1 |
| 205 | + #:end-line 1 |
| 206 | + #:start-side "RIGHT" |
| 207 | + #:end-side "RIGHT")) |
| 208 | + (define comment2 |
| 209 | + (github-review-comment |
| 210 | + #:path "file2.rkt" |
| 211 | + #:body "Comment 2" |
| 212 | + #:start-line 5 |
| 213 | + #:end-line 10 |
| 214 | + #:start-side "LEFT" |
| 215 | + #:end-side "RIGHT")) |
| 216 | + (define request |
| 217 | + (github-review-request |
| 218 | + #:owner-repo "owner/repo" |
| 219 | + #:pull-number 123 |
| 220 | + #:body "Review body" |
| 221 | + #:event "COMMENT" |
| 222 | + #:comments (list comment1 comment2))) |
| 223 | + (define result (github-review-request-jsexpr request)) |
| 224 | + (check-equal? (hash-ref result 'owner) "owner") |
| 225 | + (check-equal? (hash-ref result 'repo) "repo") |
| 226 | + (check-equal? (hash-ref result 'pull_number) 123) |
| 227 | + (check-equal? (hash-ref result 'body) "Review body") |
| 228 | + (check-equal? (hash-ref result 'event) "COMMENT") |
| 229 | + (check-equal? (length (hash-ref result 'comments)) 2)) |
| 230 | + (test-case "git-ref->pr-number" |
| 231 | + (test-case "valid PR ref" |
| 232 | + (check-equal? (git-ref->pr-number "refs/pull/42/merge") 42) |
| 233 | + (check-equal? (git-ref->pr-number "refs/pull/123/merge") 123) |
| 234 | + (check-equal? (git-ref->pr-number "refs/pull/1/merge") 1)) |
| 235 | + (test-case "invalid refs raise errors" |
| 236 | + (check-exn exn:fail? (lambda () (git-ref->pr-number "refs/heads/main"))) |
| 237 | + (check-exn exn:fail? (lambda () (git-ref->pr-number "refs/pull/42/head"))) |
| 238 | + (check-exn exn:fail? (lambda () (git-ref->pr-number "invalid"))))) |
| 239 | + (test-case "github-review-body" |
| 240 | + (test-case "with comments" |
| 241 | + (check-equal? (github-review-body #t 1) |
| 242 | + "[Resyntax](https://docs.racket-lang.org/resyntax/) analyzed 1 file in this pull request and has added suggestions.") |
| 243 | + (check-equal? (github-review-body #t 5) |
| 244 | + "[Resyntax](https://docs.racket-lang.org/resyntax/) analyzed 5 files in this pull request and has added suggestions.")) |
| 245 | + (test-case "without comments" |
| 246 | + (check-equal? (github-review-body #f 1) |
| 247 | + "[Resyntax](https://docs.racket-lang.org/resyntax/) analyzed 1 file in this pull request and found no issues.") |
| 248 | + (check-equal? (github-review-body #f 3) |
| 249 | + "[Resyntax](https://docs.racket-lang.org/resyntax/) analyzed 3 files in this pull request and found no issues.")))) |
0 commit comments