From 5476bb17dc428bcef8163c26c320e5c3ef1ff5d5 Mon Sep 17 00:00:00 2001
From: Vika <vika@fireburn.ru>
Date: Mon, 19 Jul 2021 04:56:08 +0300
Subject: Added a NixOS test for onboarding workflow

---
 flake.nix | 29 ++++++++++++++++++++++++++++-
 1 file changed, 28 insertions(+), 1 deletion(-)

diff --git a/flake.nix b/flake.nix
index b05e05c..3ff32f9 100644
--- a/flake.nix
+++ b/flake.nix
@@ -166,9 +166,36 @@
         };
 
         testScript = ''
+          import json
+
           kittybox.start()
           kittybox.wait_for_unit("default.target")
-          kittybox.succeed("curl --silent http://localhost:8080/micropub")
+          with subtest("Verify that Kittybox started correctly..."):
+              kittybox.succeed("curl --silent http://localhost:8080/micropub")
+
+          with subtest("Onboarding should correctly work..."):
+              onboarding_json = {
+                  "user": {
+                      "type": ["h-card"],
+                      "properties": {
+                          "name": ["Vika"],
+                          "pronoun": ["she/her"],
+                          "url": ["https://twitter.com/VikaNezrimaya"],
+                          "note": ["Just a simple girl. Do I even exist or am I a vestige of the past long gone?"]
+                      }
+                    },
+                    "first_post": {
+                        "type": ["h-entry"],
+                        "properties": {
+                            "content": ["Hello!"]
+                        }
+                    },
+                    "blog_name": "Test Hideout",
+                    "feeds": []
+              }
+              kittybox.succeed("echo '{}' | curl --silent http://localhost:8080/ -d@- -H 'Content-Type: application/json'".format(json.dumps(onboarding_json).replace("'", "'\''$")))
+              # Testing for a known string is the easiest way to determine that the onboarding worked
+              kittybox.succeed("curl --silent http://localhost:8080/ | grep 'vestige of the past long gone'")
         '';
       });
     };
-- 
cgit 1.4.1