|
| 1 | +defmodule AdoCli.CLI.BranchPoliciesTest do |
| 2 | + use AdoCli.CLI.TestHelper |
| 3 | + alias AdoCli.CLI.BranchPolicies |
| 4 | + |
| 5 | + describe "list_policies" do |
| 6 | + test "halts 0 on successful get", %{server: server} do |
| 7 | + expect_success_json(server, "/test/_apis/policy/configurations", ~s({"value":[]}), fn -> |
| 8 | + apply(AdoCli.CLI.BranchPolicies, :list_policies, [ |
| 9 | + %{options: %{json: true, ref_name: nil}, arguments: %{project: "test", repo_id: "repo"}} |
| 10 | + ]) |
| 11 | + end) |
| 12 | + end |
| 13 | + |
| 14 | + test "halts 1 on API error", %{server: server} do |
| 15 | + expect_api_error(server, "/test/_apis/policy/configurations", 500, "{}", fn -> |
| 16 | + apply(AdoCli.CLI.BranchPolicies, :list_policies, [ |
| 17 | + %{options: %{json: true, ref_name: nil}, arguments: %{project: "test", repo_id: "repo"}} |
| 18 | + ]) |
| 19 | + end) |
| 20 | + end |
| 21 | + end |
| 22 | + |
| 23 | + describe "show_policy" do |
| 24 | + test "halts 0 on successful get", %{server: server} do |
| 25 | + expect_success_json(server, "/test/_apis/policy/configurations/1", ~s({"value":[]}), fn -> |
| 26 | + apply(AdoCli.CLI.BranchPolicies, :show_policy, [ |
| 27 | + %{options: %{json: true}, arguments: %{project: "test", repo_id: "repo", policy_id: 1}} |
| 28 | + ]) |
| 29 | + end) |
| 30 | + end |
| 31 | + |
| 32 | + test "halts 1 on API error", %{server: server} do |
| 33 | + expect_api_error(server, "/test/_apis/policy/configurations/1", 500, "{}", fn -> |
| 34 | + apply(AdoCli.CLI.BranchPolicies, :show_policy, [ |
| 35 | + %{options: %{json: true}, arguments: %{project: "test", repo_id: "repo", policy_id: 1}} |
| 36 | + ]) |
| 37 | + end) |
| 38 | + end |
| 39 | + end |
| 40 | + |
| 41 | + describe "create_policy" do |
| 42 | + test "halts 0 on successful post", %{server: server} do |
| 43 | + expect_post_success(server, "/test/_apis/policy/configurations", "", "{\"id\":1}", fn -> |
| 44 | + apply(AdoCli.CLI.BranchPolicies, :create_policy, [ |
| 45 | + %{ |
| 46 | + options: %{json: true, type: "required reviewers", settings: %{}, ref_name: "main"}, |
| 47 | + arguments: %{project: "test", repo_id: "repo"} |
| 48 | + } |
| 49 | + ]) |
| 50 | + end) |
| 51 | + end |
| 52 | + |
| 53 | + test "halts 1 on API error", %{server: server} do |
| 54 | + expect_api_error(server, "/test/_apis/policy/configurations", 500, "{}", fn -> |
| 55 | + apply(AdoCli.CLI.BranchPolicies, :create_policy, [ |
| 56 | + %{ |
| 57 | + options: %{json: true, type: "required reviewers", settings: %{}, ref_name: "main"}, |
| 58 | + arguments: %{project: "test", repo_id: "repo"} |
| 59 | + } |
| 60 | + ]) |
| 61 | + end) |
| 62 | + end |
| 63 | + end |
| 64 | + |
| 65 | + describe "update_policy" do |
| 66 | + test "halts 0 on successful put", %{server: server} do |
| 67 | + expect_put_success(server, "/test/_apis/policy/configurations/1", "", "{\"id\":1}", fn -> |
| 68 | + apply(AdoCli.CLI.BranchPolicies, :update_policy, [ |
| 69 | + %{ |
| 70 | + options: %{json: true, is_enabled: true, is_blocking: false, settings: %{}}, |
| 71 | + arguments: %{project: "test", repo_id: "repo", policy_id: 1} |
| 72 | + } |
| 73 | + ]) |
| 74 | + end) |
| 75 | + end |
| 76 | + |
| 77 | + test "halts 1 on API error", %{server: server} do |
| 78 | + expect_api_error(server, "/test/_apis/policy/configurations/1", 500, "{}", fn -> |
| 79 | + apply(AdoCli.CLI.BranchPolicies, :update_policy, [ |
| 80 | + %{ |
| 81 | + options: %{json: true, is_enabled: true, is_blocking: false, settings: %{}}, |
| 82 | + arguments: %{project: "test", repo_id: "repo", policy_id: 1} |
| 83 | + } |
| 84 | + ]) |
| 85 | + end) |
| 86 | + end |
| 87 | + end |
| 88 | + |
| 89 | + describe "delete_policy" do |
| 90 | + test "halts 0 on successful delete", %{server: server} do |
| 91 | + expect_delete_success(server, "/test/_apis/policy/configurations/1", fn -> |
| 92 | + apply(AdoCli.CLI.BranchPolicies, :delete_policy, [ |
| 93 | + %{ |
| 94 | + options: %{json: true, force: false}, |
| 95 | + arguments: %{project: "test", repo_id: "repo", policy_id: 1} |
| 96 | + } |
| 97 | + ]) |
| 98 | + end) |
| 99 | + end |
| 100 | + |
| 101 | + test "halts 1 on API error", %{server: server} do |
| 102 | + expect_api_error(server, "/test/_apis/policy/configurations/1", 500, "{}", fn -> |
| 103 | + apply(AdoCli.CLI.BranchPolicies, :delete_policy, [ |
| 104 | + %{ |
| 105 | + options: %{json: true, force: false}, |
| 106 | + arguments: %{project: "test", repo_id: "repo", policy_id: 1} |
| 107 | + } |
| 108 | + ]) |
| 109 | + end) |
| 110 | + end |
| 111 | + end |
| 112 | +end |
0 commit comments