]> njoseph.me Git - nimcoon.git/blobdiff - tests/tests.nim
YouTube auto-play
[nimcoon.git] / tests / tests.nim
index a218596fd0543225f806a5afebb599b4449a7879..b412cb3151d36c49d725ba8229d551e80e80dd3c 100644 (file)
@@ -1,4 +1,6 @@
-import unittest
+import
+  tables,
+  unittest
 
 import lib
 
@@ -8,3 +10,27 @@ suite "Playing direct links":
     let expected = "https://www.youtube.com/watch?v=QOEMv0S8AcA"
     check(sanitizeURL("https://youtu.be/QOEMv0S8AcA") == expected)
     check(sanitizeURL("https://www.youtube.com/watch\\?v\\=QOEMv0S8AcA") == expected)
+
+  test "validate options":
+    let invalidOptionsList = [
+      to_table({"musicOnly": true, "feelingLucky": false, "fullScreen": true, "download": false, "autoPlay": false}),
+      to_table({"musicOnly": false, "feelingLucky": true, "fullScreen": true, "download": true, "autoPlay": false}),
+      # autoPlay download
+      to_table({"musicOnly": true, "feelingLucky": true, "fullScreen": true, "download": true, "autoPlay": true}),
+      # autoPlay video
+      to_table({"musicOnly": false, "feelingLucky": true, "fullScreen": true, "download": false, "autoPlay": true}),
+    ]
+    for invalidOptions in invalidOptionsList:
+      check(not isValidOptions(invalidOptions))
+
+    let validOptionsList = [
+      to_table({"musicOnly": false, "feelingLucky": true, "fullScreen": false, "download": true, "autoPlay": false}),
+      to_table({"musicOnly": false, "feelingLucky": true, "fullScreen": true, "download": false, "autoPlay": false}),
+      to_table({"musicOnly": true, "feelingLucky": true, "fullScreen": false, "download": false, "autoPlay": true}),
+    ]
+    for validOptions in validOptionsList:
+      check(isValidOptions(validOptions))
+
+  test "rewrite invidious urls":
+    let url = "https://invidious.snopyta.org/watch?v=sZhxCUay5ks"
+    check(rewriteInvidiousToYouTube(url) == "https://www.youtube.com/watch?v=sZhxCUay5ks")