File tree 4 files changed +48
-5
lines changed
4 files changed +48
-5
lines changed Original file line number Diff line number Diff line change @@ -10,7 +10,7 @@ module Client
10
10
11
11
def self . push ( json_payload )
12
12
res = HTTParty . post (
13
- Spree :: configuration . push_url ,
13
+ Wombat . configuration . push_url ,
14
14
{
15
15
body : json_payload ,
16
16
headers : {
@@ -25,11 +25,10 @@ def self.push(json_payload)
25
25
end
26
26
27
27
private
28
- def validate ( res )
28
+ def self . validate ( res )
29
29
raise PushApiError , "Push not successful. Wombat returned response code #{ res . code } and message: #{ res . body } " if res . code != 202
30
30
end
31
- end
32
-
33
- class PushApiError < StandardError ; end
34
31
32
+ class PushApiError < StandardError ; end
33
+ end
35
34
end
Original file line number Diff line number Diff line change 1
1
require 'wombat'
2
+ require 'webmock/rspec'
2
3
3
4
RSpec . configure do |config |
4
5
config . color = true
Original file line number Diff line number Diff line change 1
1
require "spec_helper"
2
2
3
3
describe Wombat ::Client do
4
+
5
+ context "push json" do
6
+
7
+ before do
8
+ Wombat . configure do |config |
9
+ config . connection_id = "123"
10
+ config . connection_token = "token"
11
+ end
12
+ stub_request ( :post , "https://push.wombat.co/" ) .
13
+ with (
14
+ :body => "name:value" ,
15
+ :headers => {
16
+ 'Content-Type' => 'application/json' ,
17
+ 'X-Hub-Access-Token' => 'token' ,
18
+ 'X-Hub-Store' => '123' ,
19
+ 'X-Hub-Timestamp' => /.*/ }
20
+ ) . to_return ( :status => 202 , :body => "" , :headers => { } )
21
+ end
22
+
23
+ it "sends the connection_id and token as headers" do
24
+ Wombat ::Client . push ( "name:value" )
25
+ end
26
+
27
+ context "with response not 202" do
28
+ before do
29
+ stub_request ( :post , "https://push.wombat.co/" ) .
30
+ with (
31
+ :body => "name:value" ,
32
+ :headers => {
33
+ 'Content-Type' => 'application/json' ,
34
+ 'X-Hub-Access-Token' => 'token' ,
35
+ 'X-Hub-Store' => '123' ,
36
+ 'X-Hub-Timestamp' => /.*/ }
37
+ ) . to_return ( :status => 404 , :body => "wombat error" , :headers => { } )
38
+ end
39
+
40
+ it "will raise PushApiException" do
41
+ expect { Wombat ::Client . push ( "name:value" ) } . to raise_error ( Wombat ::Client ::PushApiError , "Push not successful. Wombat returned response code 404 and message: wombat error" )
42
+ end
43
+ end
44
+ end
45
+
4
46
end
Original file line number Diff line number Diff line change @@ -21,6 +21,7 @@ Gem::Specification.new do |spec|
21
21
spec . add_development_dependency "bundler" , "~> 1.5"
22
22
spec . add_development_dependency "rake"
23
23
spec . add_development_dependency "rspec" , "~> 3.0.0"
24
+ spec . add_development_dependency "webmock"
24
25
spec . add_dependency 'active_model_serializers' , '0.9.0.alpha1'
25
26
spec . add_dependency 'httparty'
26
27
end
You can’t perform that action at this time.
0 commit comments