more test

This commit is contained in:
blankie 2022-10-09 14:45:36 +07:00
parent 96af163773
commit c3179e71dc
Signed by: blankie
GPG key ID: CC15FC822C7F61F5

View file

@ -22,10 +22,10 @@
(provide page-file)
;(module+ test
; (require rackunit)
; (define category-json-data
; '#hasheq((batchcomplete . #t) (continue . #hasheq((cmcontinue . "page|4150504c45|41473") (continue . "-||"))) (query . #hasheq((categorymembers . (#hasheq((ns . 0) (pageid . 25049) (title . "Item (entity)")) #hasheq((ns . 0) (pageid . 128911) (title . "3D")) #hasheq((ns . 0) (pageid . 124018) (title . "A Very Fine Item")) #hasheq((ns . 0) (pageid . 142208) (title . "Amethyst Shard")) #hasheq((ns . 0) (pageid . 121612) (title . "Ankle Monitor")))))))))
(module+ test
(require rackunit)
(define test-media-detail
'#hasheq((fileTitle . "Example file") (videoEmbedCode . "") (imageUrl . "https://static.wikia.nocookie.net/examplefile") (rawImageUrl . "https://static.wikia.nocookie.net/examplefile") (userName . "blankie") (isPostedIn . #t) (smallerArticleList . (list #hasheq((title . "Example_article") (titleText . "Example article")))) (articleListIsSmaller . 0) (exists . #t) (imageDescription . #f))))
(define (url-content-type url)
(log-outgoing url)
@ -41,23 +41,6 @@
`(audio (@ (src ,maybe-proxied-url) (controls)))]
[(regexp-match? #rx"(?i:^video/)" content-type) `(video (@ (src ,maybe-proxied-url) (controls)))]
[else `""]))
(module+ test
(require rackunit)
(parameterize ([(config-parameter 'strict_proxy) "true"])
(check-equal? (get-media-html "https://static.wikia.nocookie.net/a" "image/jpeg")
`(img (@ (src "/proxy?dest=https%3A%2F%2Fstatic.wikia.nocookie.net%2Fa"))))
(check-equal? (get-media-html "https://static.wikia.nocookie.net/b" "audio/mp3")
`(audio (@ (src "/proxy?dest=https%3A%2F%2Fstatic.wikia.nocookie.net%2Fb")
(controls)))))
(parameterize ([(config-parameter 'strict_proxy) "no"])
(check-equal? (get-media-html "https://static.wikia.nocookie.net/c" "application/ogg")
`(audio (@ (src "/proxy?dest=https%3A%2F%2Fstatic.wikia.nocookie.net%2Fc")
(controls))))
(check-equal? (get-media-html "https://static.wikia.nocookie.net/d" "video/mp4")
`(video (@ (src "/proxy?dest=https%3A%2F%2Fstatic.wikia.nocookie.net%2Fd")
(controls)))))
(check-equal? (get-media-html "https://example.com" "who knows") `"")
(check-equal? (get-media-html "https://example.com" #f) `""))
(define (generate-results-page #:source-url source-url
#:wikiname wikiname
@ -145,11 +128,28 @@
(response/output #:code 200
#:headers (list referrer-policy)
(λ (out) (write-html body out)))))))
;(module+ test
; (check-not-false ((query-selector (attribute-selector 'href "/test/wiki/Ankle_Monitor")
; (generate-results-page
; #:source-url ""
; #:wikiname "test"
; #:title "Category:Items"
; #:members-data category-json-data
; #:page '(div "page text"))))))
(module+ test
(parameterize ([(config-parameter 'strict_proxy) "true"])
(check-equal? (get-media-html "https://static.wikia.nocookie.net/a" "image/jpeg")
`(img (@ (src "/proxy?dest=https%3A%2F%2Fstatic.wikia.nocookie.net%2Fa"))))
(check-equal? (get-media-html "https://static.wikia.nocookie.net/b" "audio/mp3")
`(audio (@ (src "/proxy?dest=https%3A%2F%2Fstatic.wikia.nocookie.net%2Fb")
(controls)))))
(parameterize ([(config-parameter 'strict_proxy) "no"])
(check-equal? (get-media-html "https://static.wikia.nocookie.net/c" "application/ogg")
`(audio (@ (src "/proxy?dest=https%3A%2F%2Fstatic.wikia.nocookie.net%2Fc")
(controls))))
(check-equal? (get-media-html "https://static.wikia.nocookie.net/d" "video/mp4")
`(video (@ (src "/proxy?dest=https%3A%2F%2Fstatic.wikia.nocookie.net%2Fd")
(controls)))))
(check-equal? (get-media-html "https://example.com" "who knows") `"")
(check-equal? (get-media-html "https://example.com" #f) `""))
(module+ test
(parameterize ([(config-parameter 'strict_proxy) "true"])
(check-not-false ((query-selector (attribute-selector 'src "/proxy?dest=https%3A%2F%2Fstatic.wikia.nocookie.net%2Fexamplefile")
(generate-results-page
#:source-url ""
#:wikiname "test"
#:title "File:Example file"
#:media-detail test-media-detail
#:image-content-type "image/jpeg"))))))