Skip to content

Commit 741c550

Browse files
committed
Add tests for login feature
1 parent 20d90c5 commit 741c550

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed

test/eca/features/login_test.clj

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
(ns eca.features.login-test
2+
(:require [clojure.test :refer [deftest is testing]]
3+
[eca.features.login :as login]
4+
[matcher-combinators.test :refer [match?]]))
5+
6+
(deftest test-login-step
7+
(let [msg-log (atom [])
8+
send-msg! (fn [msg] (swap! msg-log conj msg))
9+
10+
db* (atom {:auth {"google" {}
11+
"github-copilot" {}}
12+
:chats {1 {}}})]
13+
14+
(testing "user just typed /login for the first time"
15+
(login/login-step {:provider nil
16+
:step :login/start
17+
:chat-id 0
18+
:input ""
19+
:db* db*
20+
:send-msg! send-msg!})
21+
22+
(testing "should ask to choose a provider"
23+
(is (= "Please type the name of your chosen provider and press Enter:\n- github-copilot\n- google\n"
24+
(last @msg-log)))))
25+
26+
(testing "user is confused"
27+
(login/login-step {:provider nil
28+
:step :login/start
29+
:chat-id 0
30+
:input "/login github"
31+
:db* db*
32+
:send-msg! send-msg!})
33+
34+
(testing "should ask to choose a provider and provide instructions"
35+
(is (= "Sorry, \"/login github\" is not a valid provider.\nPlease type the name of your chosen provider and press Enter:\n- github-copilot\n- google\n"
36+
(last @msg-log)))
37+
38+
(testing "state didn't change"
39+
(is (= {:auth {"github-copilot" {}
40+
"google" {}}
41+
:chats {1 {}}}
42+
@db*)))))
43+
44+
(testing "valid input is provided"
45+
46+
(login/login-step {:provider nil
47+
:step :login/start
48+
:chat-id 0
49+
:input "github-copilot"
50+
:db* db*
51+
:send-msg! send-msg!})
52+
53+
(testing "should proceed to the next step"
54+
(is (re-find #"(?m)Open your browser at `https://github.com/login/device` and authenticate using the code: `.+`\nThen type anything in the chat and send it to continue the authentication."
55+
(last @msg-log)))
56+
57+
(testing "state is update to reflect in-progress login"
58+
(is (match? {:auth {"github-copilot" {;; skipping :device-code attr
59+
:step :login/waiting-user-confirmation}
60+
"google" {}}
61+
:chats {0 {:login-provider "github-copilot"}
62+
1 {}}}
63+
64+
@db*)))))))

0 commit comments

Comments
 (0)