Browse Source

test completed

Judy Ngai 9 years ago
parent
commit
75bbb208f6

+ 5 - 3
app/models/agents/aftership_agent.rb

@@ -13,9 +13,11 @@ module Agents
       You can use this agent to retrieve tracking data. You have to provide a specific `get` request and its associated option.
  
       To get all trackings for your packages please enter `get` for key and `trackings` for the option.
-      To get tracking for a specific tracking number, add the extra options `slug`, `tracking_number` and set `single_tracking_request` to true.
+      To get tracking for a specific tracking number, add the extra keys `slug`, `tracking_number` and its associated values.
 
-      To get the last checkpoint of a package set key to `get` and option to `last_checkpoint` plus provide `slug` and `tracking_number`
+      Set `single_tracking_request` to true as well.
+
+      To get the last checkpoint of a package set key to `get` and option to `last_checkpoint`. Please provide `slug` and `tracking_number`
 
       `slug` is a unique courier code. 
 
@@ -24,7 +26,7 @@ module Agents
       Required Options:
 
       * `api_key` - YOUR_API_KEY.
-      * `get/delete and its associated options`
+      * `get and its associated options`
     MD
 
     event_description <<-MD

+ 184 - 0
spec/data_fixtures/aftership.json

@@ -0,0 +1,184 @@
+{
+  "meta": {
+    "code": 200
+  },
+  "data": {
+    "tracking": {
+      "id": "56e6d14a547de4720d9eca7a",
+      "created_at": "2016-03-14T14:57:14+00:00",
+      "updated_at": "2016-03-15T14:01:05+00:00",
+      "last_updated_at": "2016-03-15T14:01:05+00:00",
+      "tracking_number": "9361289684090010005054",
+      "slug": "usps",
+      "active": false,
+      "android": [
+
+      ],
+      "custom_fields": null,
+      "customer_name": null,
+      "delivery_time": 2,
+      "destination_country_iso3": null,
+      "emails": [
+
+      ],
+      "expected_delivery": "2016-03-15",
+      "ios": [
+
+      ],
+      "note": null,
+      "order_id": null,
+      "order_id_path": null,
+      "origin_country_iso3": "USA",
+      "shipment_package_count": 1,
+      "shipment_pickup_date": "2016-03-13T19:35:00",
+      "shipment_delivery_date": "2016-03-15T08:59:00",
+      "shipment_type": "Parcel Select",
+      "shipment_weight": null,
+      "shipment_weight_unit": null,
+      "signed_by": null,
+      "smses": [
+
+      ],
+      "source": "api",
+      "tag": "Delivered",
+      "title": "9361289684090010005054",
+      "tracked_count": 13,
+      "unique_token": "EJjDgTkTl",
+      "checkpoints": [
+        {
+          "slug": "usps",
+          "city": "BALTIMORE",
+          "created_at": "2016-03-14T14:57:14+00:00",
+          "location": "BALTIMORE, MD, 21224",
+          "country_name": null,
+          "message": "Picked Up by Shipping Partner",
+          "country_iso3": null,
+          "tag": "InTransit",
+          "checkpoint_time": "2016-03-13T19:35:00",
+          "coordinates": [
+
+          ],
+          "state": "MD",
+          "zip": "21224"
+        },
+        {
+          "slug": "usps",
+          "city": "BALTIMORE",
+          "created_at": "2016-03-14T14:57:14+00:00",
+          "location": "BALTIMORE, MD, 21224",
+          "country_name": null,
+          "message": "Departed Shipping Partner Facility",
+          "country_iso3": null,
+          "tag": "InTransit",
+          "checkpoint_time": "2016-03-13T23:16:00",
+          "coordinates": [
+
+          ],
+          "state": "MD",
+          "zip": "21224"
+        },
+        {
+          "slug": "usps",
+          "city": "STOUGHTON",
+          "created_at": "2016-03-15T08:00:54+00:00",
+          "location": "STOUGHTON, MA, 02072",
+          "country_name": null,
+          "message": "Departed Shipping Partner Facility",
+          "country_iso3": null,
+          "tag": "InTransit",
+          "checkpoint_time": "2016-03-15T00:11:00",
+          "coordinates": [
+
+          ],
+          "state": "MA",
+          "zip": "02072"
+        },
+        {
+          "slug": "usps",
+          "city": null,
+          "created_at": "2016-03-15T08:00:54+00:00",
+          "location": null,
+          "country_name": null,
+          "message": "Pre-Shipment Info Sent to USPS",
+          "country_iso3": null,
+          "tag": "InfoReceived",
+          "checkpoint_time": "2016-03-15T00:11:00",
+          "coordinates": [
+
+          ],
+          "state": null,
+          "zip": null
+        },
+        {
+          "slug": "usps",
+          "city": "QUINCY",
+          "created_at": "2016-03-15T10:00:57+00:00",
+          "location": "QUINCY, MA, 02169",
+          "country_name": null,
+          "message": "Accepted at USPS Destination Facility",
+          "country_iso3": null,
+          "tag": "InTransit",
+          "checkpoint_time": "2016-03-15T04:14:00",
+          "coordinates": [
+
+          ],
+          "state": "MA",
+          "zip": "02169"
+        },
+        {
+          "slug": "usps",
+          "city": "QUINCY",
+          "created_at": "2016-03-15T10:00:57+00:00",
+          "location": "QUINCY, MA, 02169",
+          "country_name": null,
+          "message": "Arrived at Post Office",
+          "country_iso3": null,
+          "tag": "InTransit",
+          "checkpoint_time": "2016-03-15T05:29:00",
+          "coordinates": [
+
+          ],
+          "state": "MA",
+          "zip": "02169"
+        },
+        {
+          "slug": "usps",
+          "city": "QUINCY",
+          "created_at": "2016-03-15T14:01:00+00:00",
+          "location": "QUINCY, MA, 02169",
+          "country_name": null,
+          "message": "Sorting Complete",
+          "country_iso3": null,
+          "tag": "InTransit",
+          "checkpoint_time": "2016-03-15T08:35:00",
+          "coordinates": [
+
+          ],
+          "state": "MA",
+          "zip": "02169"
+        },
+        {
+          "slug": "usps",
+          "city": "QUINCY",
+          "created_at": "2016-03-15T14:01:00+00:00",
+          "location": "QUINCY, MA, 02169",
+          "country_name": null,
+          "message": "Delivered, Front Door/Porch",
+          "country_iso3": null,
+          "tag": "Delivered",
+          "checkpoint_time": "2016-03-15T08:59:00",
+          "coordinates": [
+
+          ],
+          "state": "MA",
+          "zip": "02169"
+        }
+      ],
+      "tracking_account_number": null,
+      "tracking_destination_country": null,
+      "tracking_key": null,
+      "tracking_postal_code": null,
+      "tracking_ship_date": null
+    }
+  }
+}

+ 20 - 3
spec/models/agents/aftership_agent_spec.rb

@@ -3,12 +3,17 @@ require 'rails_helper'
 describe Agents::AftershipAgent do
   before do
 
+    stub_request(:get, /trackings/).to_return(
+      :body => File.read(Rails.root.join("spec/data_fixtures/aftership.json")),
+      :status => 200,
+      :headers => {"Content-Type" => "text/json"}
+    )
+
     @opts = {
       "api_key" => '800deeaf-e285-9d62-bc90-j999c1973cc9',
       "get" => 'trackings',
       "slug" => 'usps',
       "tracking_number" => "9361289684090010005054"
-
     }
 
     @checker = Agents::AftershipAgent.new(:name => "tectonic", :options => @opts)
@@ -25,9 +30,16 @@ describe Agents::AftershipAgent do
       expect(@checker.send(:event_url)).to eq("https://api.aftership.com/v4/trackings")
     end
 
-    it "should generate the correct single or checkpoint tracking url" do
+    it "should generate the correct single tracking url" do
+      @checker.options['single_tracking_request'] = true
       expect(@checker.send(:single_or_checkpoint_tracking_url)).to eq("https://api.aftership.com/v4/trackings/usps/9361289684090010005054")
     end
+
+    it "should generate the correct checkpoint tracking url" do
+      @checker.options['get'] = 'last_checkpoint'
+      @checker.options['last_checkpoint_request'] = true
+      expect(@checker.send(:single_or_checkpoint_tracking_url)).to eq("https://api.aftership.com/v4/last_checkpoint/usps/9361289684090010005054")
+    end
   end
 
   describe "#that checker should be valid" do
@@ -51,5 +63,10 @@ describe Agents::AftershipAgent do
     end
   end
 
-  describe '#check'
+  describe '#check' do
+    it "should check that initial run creates an event" do
+      @checker.memory[:last_updated_at] = '2016-03-15T14:01:05+00:00'
+      expect { @checker.check }.to change { Event.count }.by(1)
+    end
+  end
 end