File tree 3 files changed +14
-4
lines changed
3 files changed +14
-4
lines changed Original file line number Diff line number Diff line change 15
15
require_relative "write_mark_group"
16
16
17
17
module FeverAPI
18
+ API_VERSION = 3
19
+
18
20
class Response
19
21
ACTIONS = [
20
22
Authentication ,
@@ -39,7 +41,7 @@ def initialize(params)
39
41
end
40
42
41
43
def to_json
42
- base_response = { api_version : 3 }
44
+ base_response = { api_version : API_VERSION }
43
45
ACTIONS
44
46
. inject ( base_response ) { |a , e | a . merge! ( e . new . call ( @params ) ) }
45
47
. to_json
Original file line number Diff line number Diff line change @@ -13,7 +13,9 @@ class Endpoint < Sinatra::Base
13
13
end
14
14
15
15
before do
16
- halt 403 unless authenticated? ( params [ :api_key ] )
16
+ headers = { "Content-Type" => "application/json" }
17
+ body = { api_version : FeverAPI ::API_VERSION , auth : 0 } . to_json
18
+ halt 200 , headers , body unless authenticated? ( params [ :api_key ] )
17
19
end
18
20
19
21
def authenticated? ( api_key )
Original file line number Diff line number Diff line change @@ -17,6 +17,9 @@ def app
17
17
let ( :standard_answer ) do
18
18
{ api_version : 3 , auth : 1 , last_refreshed_on_time : 123456789 }
19
19
end
20
+ let ( :cannot_auth ) do
21
+ { api_version : 3 , auth : 0 }
22
+ end
20
23
let ( :headers ) { { api_key : api_key } }
21
24
22
25
before do
@@ -34,16 +37,19 @@ def last_response_as_object
34
37
it "authenticates request with correct api_key" do
35
38
get "/" , headers
36
39
expect ( last_response ) . to be_ok
40
+ expect ( last_response_as_object ) . to include ( standard_answer )
37
41
end
38
42
39
43
it "does not authenticate request with incorrect api_key" do
40
44
get "/" , api_key : "foo"
41
- expect ( last_response ) . not_to be_ok
45
+ expect ( last_response ) . to be_ok
46
+ expect ( last_response_as_object ) . to include ( cannot_auth )
42
47
end
43
48
44
49
it "does not authenticate request when api_key is not provided" do
45
50
get "/"
46
- expect ( last_response ) . not_to be_ok
51
+ expect ( last_response ) . to be_ok
52
+ expect ( last_response_as_object ) . to include ( cannot_auth )
47
53
end
48
54
end
49
55
You can’t perform that action at this time.
0 commit comments