(test-begin "set") (tick '("create" "--type" "defect" "--summary" "hello" "--body" "Set me")) (let ((last-ticket (get-last-modified-ticket))) (tick `("set" ,last-ticket "--owner" "foo" "--status" "assigned")) (test-assert "Set status to assigned" (let ((body (tick `("show" ,last-ticket)))) (string-suffix? "changed status from ''new'' to ''assigned''\n" body))) (tick `("set" ,last-ticket "--priority" "critical")) (test-assert "Set priority to critical" (let ((body (tick `("show" ,last-ticket)))) (string-suffix? "set priority to ''critical''\n" body))) (tick `("set" ,last-ticket "--priority" "")) (test-assert "Unset priority" (let ((body (tick `("show" ,last-ticket)))) (string-suffix? "set priority empty\n" body))) (tick `("set" ,last-ticket "--owner" "bar")) (test-assert "Set owner to bar" (let ((body (tick `("show" ,last-ticket)))) (string-suffix? "changed owner from ''foo'' to ''bar''\n" body))) (test-error "Trying to accept a ticket on behalf of someone else" (tick `("set" ,last-ticket "--status" "accepted"))) ;; Fake user=bar to be able to accept the ticket (with-another-username "bar" (lambda () (tick `("set" ,last-ticket "--status" "accepted")))) (test-assert "Fake user=bar and accept the ticket" (let ((body (tick `("show" ,last-ticket)))) (string-suffix? "changed status from ''assigned'' to ''accepted''\n" body))) ;; Check whether a change in the owner of an accepted ticket puts ;; the ticket in the assigned state if the owner is not the current ;; user. (tick `("set" ,last-ticket "--owner" "baz")) (test-assert "Check changing owner of accepted ticket" (let ((body (tick `("show" ,last-ticket)))) (string-suffix? "changed status from ''accepted'' to ''assigned''\n" body))) (test "Check whether baz is the new owner" "baz" (string-trim-right (tick `("get" "--bare" "--owner" ,last-ticket)))) ;; Fake user=baz to be able to accept the ticket (test-assert "Fake user=baz and accept the ticket" (begin (with-another-username "baz" (lambda () (tick `("set" ,last-ticket "--status" "accepted")))) (let ((body (tick `("show" ,last-ticket)))) (string-suffix? "changed status from ''assigned'' to ''accepted''\n" body)))) (test "Check whether baz is still the new owner" "baz" (string-trim-right (tick `("get" "--bare" "--owner" ,last-ticket)))) ;; Change the owner to the current user and check whether the status ;; of the ticket continues to be accepted. (tick `("set" ,last-ticket "--owner" ,(get-username))) (test-assert "Check changing owner of accepted ticket to current user" (let ((body (tick `("show" ,last-ticket)))) (string-suffix? "changed owner from ''baz'' to ''foo''\n" body))) (test-error "Try to unset type" (tick `("set" ,last-ticket "--type" ""))) (test-error "Try to unset reporter" (tick `("set" ,last-ticket "--reporter" ""))) ;; Test workflow (test-assert "Set status to new and unset owner" (tick `("set" ,last-ticket "--status" "new" "--owner" ""))) (test-error "Check that setting status to assigned requires an owner" (tick `("set" ,last-ticket "--status" "assigned"))) (test "Check that accepting a ticket without providing an owner works" (get-username) (begin (tick `("set" ,last-ticket "--status" "accepted")) (string-trim-right (tick `("get" ,last-ticket "--bare" "--owner"))))) (test-error "Check that moving a ticket to new while providing an owner fails" (tick `("set" ,last-ticket "--status" "new" "--owner" ,(get-username)))) (test "Check that moving a ticket back to new unsets owner" "\n" (begin (tick `("set" ,last-ticket "--status" "new")) (tick `("get" ,last-ticket "--bare" "--owner")))) (test "Check that accepting a ticket while providing the owner (= username) works" `("accepted\n" ,(string-append (get-username) "\n")) (begin (tick `("set" ,last-ticket "--status" "accepted" "--owner" ,(get-username))) (list (tick `("get" ,last-ticket "--bare" "--status")) (tick `("get" ,last-ticket "--bare" "--owner"))))) (test "Check that removing the owner of an assigned/accepted ticket changes its status to new" '("new\n" "\n") (begin (tick `("set" ,last-ticket "--owner" "")) (list (tick `("get" ,last-ticket "--bare" "--status")) (tick `("get" ,last-ticket "--bare" "--owner"))))) ;; Test whether set is actually changing properties (let ((set/get (lambda (prop-cmd-opt value) (tick `("set" ,last-ticket ,prop-cmd-opt ,value)) (tick `("get" ,last-ticket "--bare" ,prop-cmd-opt))))) (test "Check changing summary" "summary\n" (set/get "--summary" "summary")) (test "Check changing status" "new\n" (set/get "--status" "new")) (test "Check changing priority" "major\n" (set/get "--priority" "major")) (test "Check changing type" "defect\n" (set/get "--type" "defect")) (test "Check changing difficulty" "easy\n" (set/get "--difficulty" "easy")) (test "Check changing component" "compiler\n" (set/get "--component" "compiler")) (test "Check changing version" "5.4.0\n" (set/get "--version" "5.4.0")) (test "Check changing resolution" "fixed\n" (set/get "--resolution" "fixed")) (test "Check changing cc" "foo\n" (set/get "--cc" "foo")) (test "Check changing keywords" "key\n" (set/get "--keywords" "key")) (test "Check changing milestone" "5.0.0\n" (set/get "--milestone" "5.0.0")) ) ) (test-end "set") (test-exit)