customerio 5.5.1 → 6.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,67 +0,0 @@
1
- require 'spec_helper'
2
- require 'multi_json'
3
- require 'base64'
4
-
5
- describe Customerio::BaseClient do
6
- let(:url) { "https://test.customer.io" }
7
-
8
- let(:site_id) { "SITE_ID" }
9
- let(:api_key) { "API_KEY" }
10
- let(:track_client) { Customerio::BaseClient.new({ site_id: site_id, api_key: api_key }, { url: url }) }
11
-
12
- let(:app_key) { "APP_KEY" }
13
- let(:api_client) { Customerio::BaseClient.new({ app_key: app_key }, { url: url }) }
14
-
15
- def api_uri(path)
16
- "#{url}#{path}"
17
- end
18
-
19
- def track_client_request_headers
20
- token = Base64.strict_encode64("#{site_id}:#{api_key}")
21
- { 'Authorization': "Basic #{token}", 'Content-Type': 'application/json', 'User-Agent': 'Customer.io Ruby Client/' + Customerio::VERSION }
22
- end
23
-
24
- def api_client_request_headers
25
- { 'Authorization': "Bearer #{app_key}", 'Content-Type': 'application/json', 'User-Agent': 'Customer.io Ruby Client/' + Customerio::VERSION }
26
- end
27
-
28
- describe "with a site ID and API key" do
29
- it "uses the correct basic auth" do
30
- stub_request(:put, api_uri('/some/path')).
31
- with(headers: track_client_request_headers).
32
- to_return(status: 200, body: "", headers: {})
33
-
34
- track_client.request(:put, '/some/path', "")
35
- end
36
- end
37
-
38
- describe "with an app key" do
39
- it "uses the correct bearer token" do
40
- stub_request(:put, api_uri('/some/path')).
41
- with(headers: api_client_request_headers).
42
- to_return(status: 200, body: "", headers: {})
43
-
44
- api_client.request(:put, '/some/path', "")
45
- end
46
- end
47
-
48
- describe "#verify_response" do
49
- it "throws an error when the response isn't between 200 and 300" do
50
- stub_request(:put, api_uri('/some/path')).
51
- with(headers: api_client_request_headers).
52
- to_return(status: 400, body: "", headers: {})
53
-
54
- lambda { api_client.request_and_verify_response(:put, '/some/path', "") }.should(
55
- raise_error(Customerio::InvalidResponse)
56
- )
57
- end
58
-
59
- it "returns the response when the status is 200" do
60
- stub_request(:put, api_uri('/some/path')).
61
- with(headers: api_client_request_headers).
62
- to_return(status: 200, body: "Test", headers: {})
63
-
64
- api_client.request_and_verify_response(:put, '/some/path', "").body.should eq("Test")
65
- end
66
- end
67
- end