|
2 | 2 |
|
3 | 3 | describe "isomorphic operations", js: true do |
4 | 4 |
|
| 5 | + let(:response_spy) { spy('response_spy') } |
| 6 | + |
5 | 7 | before(:each) do |
| 8 | + |
| 9 | + allow(Hyperstack::ServerOp).to receive(:run_from_client).and_wrap_original do |m, *args| |
| 10 | + m.call(*args).tap { |r| response_spy.status = r[:status] } |
| 11 | + end |
| 12 | + |
6 | 13 | on_client do |
7 | 14 | class Test |
8 | 15 | include Hyperstack::Component |
@@ -65,28 +72,65 @@ def fact(x) |
65 | 72 |
|
66 | 73 | it "will pass server failures back" do |
67 | 74 | ServerFacts.param :acting_user, nils: true |
| 75 | + |
68 | 76 | expect_promise do |
69 | | - ServerFacts.run(n: -1).fail { |exception| Promise.new.resolve(exception) } |
70 | | - end.to eq('N is too small') |
| 77 | + ServerFacts.run(n: -1).fail { |exception| Promise.new.resolve(exception.inspect) } |
| 78 | + end.to eq('#<Hyperstack::Operation::ValidationException: n is too small>') |
| 79 | + expect(response_spy).to have_received(:status=).with(400) |
71 | 80 | expect_promise do |
72 | | - ServerFacts.run(n: 10000000000).fail { |exception| Promise.new.resolve(exception) } |
73 | | - end.to eq('stack level too deep') |
| 81 | + ServerFacts.run(n: 10000000000).fail { |exception| Promise.new.resolve(exception.inspect) } |
| 82 | + end.to eq('#<Exception: stack level too deep>') |
| 83 | + expect(response_spy).to have_received(:status=).with(500) |
| 84 | + end |
| 85 | + |
| 86 | + it "pass abort status back" do |
| 87 | + # just to check we will actually interrogate the structure of the exception in this spec |
| 88 | + ServerFacts.param :acting_user, nils: true |
| 89 | + class ServerFacts < Hyperstack::ServerOp |
| 90 | + step { abort! } |
| 91 | + end |
| 92 | + expect_promise do |
| 93 | + ServerFacts.run(n: 5).fail do |exception| |
| 94 | + Promise.new.resolve(exception.inspect) |
| 95 | + end |
| 96 | + end.to eq('#<Hyperstack::Operation::Exit: Hyperstack::Operation::Exit>') |
| 97 | + expect(response_spy).to have_received(:status=).with(500) |
| 98 | + end |
| 99 | + |
| 100 | + it "pass failure data back" do |
| 101 | + # just to check we will actually interrogate the structure of the exception in this spec |
| 102 | + ServerFacts.param :acting_user, nils: true |
| 103 | + class ServerFacts < Hyperstack::ServerOp |
| 104 | + step { raise 'failure' } |
| 105 | + failed { [{'some' => 'data'}] } |
| 106 | + end |
| 107 | + expect_promise do |
| 108 | + ServerFacts.run(n: 5).fail do |exception| |
| 109 | + Promise.new.resolve(exception) |
| 110 | + end |
| 111 | + end.to eq([{'some' => 'data'}]) |
| 112 | + expect(response_spy).to have_received(:status=).with(500) |
74 | 113 | end |
75 | 114 |
|
76 | 115 | it "pass validation failures back" do |
| 116 | + # just to check we will actually interrogate the structure of the exception in this spec |
77 | 117 | ServerFacts.param :acting_user, nils: true |
78 | 118 | class ServerFacts < Hyperstack::ServerOp |
79 | 119 | validate { false } |
80 | 120 | end |
81 | 121 | expect_promise do |
82 | | - ServerFacts.run(n: 5).fail { |exception| Promise.new.resolve(exception) } |
83 | | - end.to include('param validation 1 failed') |
| 122 | + ServerFacts.run(n: 5).fail do |exception| |
| 123 | + Promise.new.resolve(exception.errors.message_list) |
| 124 | + end |
| 125 | + end.to eq(['param validation 1 failed']) |
| 126 | + expect(response_spy).to have_received(:status=).with(400) |
84 | 127 | end |
85 | 128 |
|
86 | 129 | it "will reject uplinks that don't accept acting_user" do |
87 | 130 | expect_promise do |
88 | 131 | ServerFacts.run(n: 5).fail { |exception| Promise.new.resolve(exception) } |
89 | 132 | end.to include('Hyperstack::AccessViolation') |
| 133 | + expect(response_spy).to have_received(:status=).with(403) |
90 | 134 | end |
91 | 135 | end |
92 | 136 |
|
|
0 commit comments