Skip to content

Commit

Permalink
Fix tests after merge
Browse files Browse the repository at this point in the history
  • Loading branch information
rich.d.rich authored and fsanggang committed Mar 7, 2024
1 parent 452a18f commit 96bf7f0
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 49 deletions.
12 changes: 6 additions & 6 deletions test/examples/exercise4.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ module Exercise4

def endpoint
group 'Test_Exercise'
http_method 'GET'
path '/examples/exercise1'
method 'GET'
path '/examples/exercise4'
title 'Exercise API 4'
description 'Exercise definition DSL #4'

request_example('"/api/examples/exercise4"')
response_example <<~END_EXAMPLE
{
}
request_example('/api/examples/exercise4')
response_example(<<~END_EXAMPLE
{
}
END_EXAMPLE
end

Expand Down
4 changes: 2 additions & 2 deletions test/examples/exercise4_doc.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
=begin
@api {GET} /examples/exercise1.json Exercise API 4
@api {GET} /examples/exercise4.json Exercise API 4
@apiName Exercise4
@apiGroup Test_Exercise
Expand All @@ -13,7 +13,7 @@
@apiParamExample Request Example
{GET} "/api/examples/exercise4"
{GET} "/api/examples/exercise4"
@apiSuccess (200 Success) {String} a_not
Expand Down
49 changes: 16 additions & 33 deletions test/integration/exercise1_response_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,44 +30,27 @@ class Exercise1ResponseTest < MiniTest::Test
end

should 'respond with a composed block' do
response = @controller.show
response = Examples::Exercise1Controller.new.show

assert_equal({ 'extra' => 150,
'defaulted' => 123,
'data' => [
{ 'n' => 1, 'name' => 'one', 'alt_name' => 'one' },
{ 'n' => 2, 'name' => 'two', 'alt_name' => 'two' }
],
'links' => { 'other' => 'http://test.api/exercise1/other/123/other_api?extra=50',
'self' => 'http://test.api/exercise1/examples/exercise1?defaulted=123&extra=50' } },
assert_equal({ 'extra' => 150, 'defaulted' => 123, 'data' => [{ 'n' => 1, 'name' => 'one' }, { 'n' => 2, 'name' => 'two' }] },
response)
end

should 'respond with a composed block when no param' do
@controller.params = {}
response = @controller.show
controller = Examples::Exercise1Controller.new
controller.params = {}
response = controller.show

assert_equal({ 'extra' => 1334, 'defaulted' => 123,
'data' => [
{ 'n' => 1, 'name' => 'one', 'alt_name' => 'one' },
{ 'n' => 2, 'name' => 'two', 'alt_name' => 'two' }
],
'links' => { 'other' => 'http://test.api/exercise1/other/123/other_api?extra=1234',
'self' => 'http://test.api/exercise1/examples/exercise1?defaulted=123&extra=1234' } },
assert_equal({ 'extra' => 100, 'defaulted' => 123, 'data' => [{ 'n' => 1, 'name' => 'one' }, { 'n' => 2, 'name' => 'two' }] },
response)
end

should 'override a default param from query' do
@controller.params = { defaulted: 888 }
response = @controller.show
controller = Examples::Exercise1Controller.new
controller.params = { defaulted: 888 }
response = controller.show

assert_equal({ 'extra' => 1234 + 100, 'defaulted' => 888,
'data' => [
{ 'n' => 1, 'name' => 'one', 'alt_name' => 'one' },
{ 'n' => 2, 'name' => 'two', 'alt_name' => 'two' }
],
'links' => { 'other' => 'http://test.api/exercise1/other/888/other_api?extra=1234',
'self' => 'http://test.api/exercise1/examples/exercise1?defaulted=888&extra=1234' } },
assert_equal({ 'extra' => 100, 'defaulted' => 888, 'data' => [{ 'n' => 1, 'name' => 'one' }, { 'n' => 2, 'name' => 'two' }] },
response)
end

Expand All @@ -89,12 +72,12 @@ class Exercise1ResponseTest < MiniTest::Test
assert_equal(422, response.status_code)
end

should 'return an error hash when provoked' do
@controller.params = { return_error_hash: true }
response = @controller.show

assert_equal({ e: 'Fail', reason: 'wanted' }, response.status_error_info)
assert_equal(422, response.status_code)
should 'return an error when provoked' do
controller = Examples::Exercise1Controller.new
controller.params = { return_error: true }
response = controller.show
assert_equal response.status_code, 422
assert_equal response.status_message, 'Eek!'
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions test/integration/exercise2_response_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class Exercise2ResponseTest < MiniTest::Test
controller.params = { required: 2.718, version: 'v2.1.0-mobile' }
response = controller.show

assert_equal({ 'all' => 'all_versions', 'v2_1_only' => 2.1, "params" => { "required" => 2.718, "version" => "v2.1.0-mobile" }, "options" => { "test" => "hello" } },
assert_equal({ 'all' => 'all_versions', 'v2_1_only' => 2.1 },
response)
end

Expand All @@ -36,7 +36,7 @@ class Exercise2ResponseTest < MiniTest::Test
controller.params = { required: 3.142, version: 'v2.0-mobile' }
response = controller.show

assert_equal({ 'all' => 'all_versions', 'v2_0_only' => 2.0, "params" => { "required" => 3.142, "version" => "v2.0-mobile" }, "options" => { "test" => "hello" } },
assert_equal({ 'all' => 'all_versions', 'v2_0_only' => 2.0 },
response)
end

Expand Down
3 changes: 1 addition & 2 deletions test/integration/exercise3_response_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ class Exercise3ResponseTest < MiniTest::Test
controller.params = { required: 2.718, version: 'v2.1.0-mobile' }
response = controller.my_method

assert_equal({ 'ok' => true },
response)
assert_equal({ 'ok' => true }, response)
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion test/integration/exercise4_doco_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

module Integration
class Exercise4DocoTest < MiniTest::Test
context 'Documentation of Exercise1' do
context 'Documentation of Exercise4' do
setup do
Flappi.configure do |conf|
conf.version_plan = nil
Expand Down
29 changes: 26 additions & 3 deletions test/integration/exercise4_response_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,29 @@
require_relative '../examples/exercise4'

module Examples
class Exercise4Controller < ExampleController
class Exercise4Controller
attr_accessor :params
attr_accessor :last_render_params

def initialize
self.params = {}
end

def show
Flappi.build_and_respond(self)
end

def request
OpenStruct.new(query_parameters: params)
end

def respond_to
yield JsonFormatter.new
end

def render(params)
self.last_render_params = params
end
end
end

Expand All @@ -20,10 +42,11 @@ class Exercise4ResponseTest < MiniTest::Test
end
end

should 'respond with a composed block' do
should 'respond with only selected fields' do
response = Examples::Exercise4Controller.new.show

assert_equal({ 'a_not' => 100, 'b_how' => 100 }, response)
assert_equal({ "a_not"=>100, "b_how"=>100 },
response)
end
end
end
Expand Down

0 comments on commit 96bf7f0

Please sign in to comment.