|
3 | 3 | require 'webmock/rspec' |
4 | 4 |
|
5 | 5 | describe 'cd4pe_deployments::create_git_branch' do |
6 | | - let(:ajax_op) { 'CreateGitBranch' } |
7 | | - |
8 | 6 | context 'table steaks' do |
9 | 7 | include_context 'deployment' |
10 | 8 |
|
|
21 | 19 | include_context 'deployment' |
22 | 20 |
|
23 | 21 | let(:repo_type) { 'CONTROL_REPO' } |
24 | | - let(:git_branch) { 'development_b' } |
| 22 | + let(:branch_name) { 'development_b' } |
25 | 23 | let(:commit_sha) { 'c090ea692e67405c5572af6b2a9dc5f11c9080c0' } |
26 | | - let(:response) do |
27 | | - { |
28 | | - 'result' => { |
29 | | - 'success' => true, |
30 | | - }, |
31 | | - 'error' => nil, |
32 | | - } |
| 24 | + let(:full_path) do |
| 25 | + "#{api_v1_path}/deployments/#{deployment_id}:create-git-branch?workspaceId=#{deployment_domain}" |
33 | 26 | end |
34 | 27 |
|
35 | | - it 'succeeds with parameters' do |
36 | | - stub_request(:post, ajax_url) |
| 28 | + it 'returns success on 204' do |
| 29 | + stub_request(:post, full_path) |
37 | 30 | .with( |
38 | 31 | body: { |
39 | | - op: ajax_op, |
40 | | - content: { |
41 | | - repoType: repo_type, |
42 | | - deploymentId: deployment_id, |
43 | | - branchName: git_branch, |
44 | | - commitSha: commit_sha, |
45 | | - cleanup: true, |
46 | | - }, |
| 32 | + repoType: repo_type, |
| 33 | + branchName: branch_name, |
| 34 | + commitSha: commit_sha, |
| 35 | + cleanup: true, |
47 | 36 | }, |
48 | 37 | headers: { |
49 | 38 | 'authorization' => ENV['DEPLOYMENT_TOKEN'], |
50 | 39 | }, |
51 | 40 | ) |
52 | | - .to_return(body: JSON.generate(response['result'])) |
| 41 | + .to_return(status: 204, body: '') |
53 | 42 | .times(1) |
54 | 43 |
|
55 | | - is_expected.to run.with_params(repo_type, git_branch, commit_sha).and_return(response) |
| 44 | + is_expected |
| 45 | + .to run |
| 46 | + .with_params(repo_type, branch_name, commit_sha) |
| 47 | + .and_return({'result' => 'success', 'error' => nil}) |
56 | 48 | end |
57 | 49 |
|
58 | | - it 'fails with non-200 response code' do |
59 | | - stub_request(:post, ajax_url) |
| 50 | + it 'returns error result on 4xx with a V1 error body' do |
| 51 | + v1_error_body = { |
| 52 | + 'message' => 'Some error message', |
| 53 | + 'traceId' => 'abc', |
| 54 | + 'uriPath' => full_path, |
| 55 | + } |
| 56 | + stub_request(:post, full_path) |
60 | 57 | .with( |
61 | 58 | body: { |
62 | | - op: ajax_op, |
63 | | - content: { |
64 | | - repoType: repo_type, |
65 | | - deploymentId: deployment_id, |
66 | | - branchName: git_branch, |
67 | | - commitSha: commit_sha, |
68 | | - cleanup: true, |
69 | | - }, |
| 59 | + repoType: repo_type, |
| 60 | + branchName: branch_name, |
| 61 | + commitSha: commit_sha, |
| 62 | + cleanup: true, |
70 | 63 | }, |
71 | 64 | headers: { |
72 | 65 | 'authorization' => ENV['DEPLOYMENT_TOKEN'], |
73 | 66 | }, |
74 | 67 | ) |
75 | | - .to_return(body: JSON.generate(error_response), status: 404) |
| 68 | + .to_return(status: 400, body: JSON.generate(v1_error_body)) |
| 69 | + .times(1) |
| 70 | + |
| 71 | + is_expected |
| 72 | + .to run |
| 73 | + .with_params(repo_type, branch_name, commit_sha) |
| 74 | + .and_return( |
| 75 | + {'result' => nil, 'error' => {'message' => 'Some error message', 'code' => '400'}}, |
| 76 | + ) |
| 77 | + end |
| 78 | + |
| 79 | + it 'raises on 5xx' do |
| 80 | + stub_request(:post, full_path) |
| 81 | + .to_return(status: 500, body: 'boom') |
76 | 82 | .times(1) |
77 | 83 |
|
78 | | - is_expected.to run.with_params(repo_type, git_branch, commit_sha).and_return(error_response) |
| 84 | + is_expected |
| 85 | + .to run |
| 86 | + .with_params(repo_type, branch_name, commit_sha) |
| 87 | + .and_raise_error(Puppet::Error) |
79 | 88 | end |
80 | 89 | end |
81 | 90 | end |
0 commit comments