half of the spec created

Judy Ngai 8 years ago
parent
commit
71926e2cd7
2 changed files with 38 additions and 4 deletions
  1. 2 4
      app/models/agents/aftership_agent.rb
  2. 36 0
      spec/models/agents/aftership_agent_spec.rb

+ 2 - 4
app/models/agents/aftership_agent.rb

@@ -3,7 +3,7 @@ require 'uri'
3 3
 module Agents
4 4
   class AftershipAgent < Agent
5 5
 
6
-    API_URL = 'https://api.aftership.com/v4'
6
+    default_schedule "every_10m"
7 7
 
8 8
     description <<-MD
9 9
       The Aftership agent allows you to track your shipment from aftership and emit them into events.
@@ -23,7 +23,6 @@ module Agents
23 23
 
24 24
       Required Options:
25 25
 
26
-      * `Content-Type` application/json
27 26
       * `api_key` - YOUR_API_KEY.
28 27
       * `get/delete and its associated options`
29 28
     MD
@@ -106,7 +105,6 @@ module Agents
106 105
 
107 106
     def default_options
108 107
       { 'api_key' => 'YOUR_API_KEY',
109
-        'Content_Type' => 'application/json',
110 108
         'get' => '/trackings'
111 109
       }
112 110
     end
@@ -125,7 +123,7 @@ module Agents
125 123
 
126 124
     def validate_options
127 125
       errors.add(:base, "You need to specify a api key") unless options['api_key'].present?
128
-      errors.add(:base, "Content-Type must be set to application/json") unless options['Content_Type'].present? && options['Content_Type'] == 'application/json'
126
+      errors.add(:base, "You need to specify a get request") unless options['get'].present?
129 127
     end
130 128
 
131 129
     def check

+ 36 - 0
spec/models/agents/aftership_agent_spec.rb

@@ -0,0 +1,36 @@
1
+require 'rails_helper'
2
+
3
+describe Agents::AftershipAgent do
4
+  before do
5
+
6
+    @opts = {
7
+      "api_key" => '800deeaf-e285-9d62-bc90-j999c1973cc9',
8
+      "get" => 'trackings'
9
+    }
10
+
11
+    @checker = Agents::AftershipAgent.new(:name => "tectonic", :options => @opts)
12
+    @checker.user = users(:bob)
13
+    @checker.save!
14
+  end
15
+
16
+  describe "#that checker should be valid" do
17
+    it "should check that the aftership object is valid" do
18
+      expect(@checker).to be_valid
19
+    end
20
+
21
+    it "should require credentials" do
22
+      @checker.options['api_key'] = nil
23
+      expect(@checker).not_to be_valid
24
+    end
25
+  end
26
+
27
+  describe "get request must exist" do
28
+    it "should check that validation added if get does not exist" do
29
+      opts = @opts.tap { |o| o.delete('get') }
30
+      @checker = Agents::AftershipAgent.new(:name => "tectonic", :options => opts)
31
+      @checker.user = users(:bob)
32
+      expect(@checker.save).to eq false
33
+      expect(@checker.errors.full_messages.first).to eq("You need to specify a get request")
34
+    end
35
+  end
36
+end