Browse Source

Add support for report publishing

David Schwartz 8 years ago
parent
commit
62d09b42cf
4 changed files with 59 additions and 0 deletions
  1. 4 0
      lib/shopify_api/resources/report.rb
  2. 9 0
      test/fixtures/report.json
  3. 11 0
      test/fixtures/reports.json
  4. 35 0
      test/report_test.rb

+ 4 - 0
lib/shopify_api/resources/report.rb

@@ -0,0 +1,4 @@
+module ShopifyAPI
+  class Report < Base
+  end
+end

+ 9 - 0
test/fixtures/report.json

@@ -0,0 +1,9 @@
+{
+  "report": {
+    "id": 987,
+    "name": "Custom App Report",
+    "shopify_ql": "SHOW quantity_count, total_sales BY product_type, vendor, product_title FROM products SINCE -1m UNTIL -0m ORDER BY total_sales DESC",
+    "updated_at": "2017-04-12T14:00:54-04:00",
+    "category": "custom_app_reports"
+  }
+}

+ 11 - 0
test/fixtures/reports.json

@@ -0,0 +1,11 @@
+{
+  "reports": [
+    {
+      "id": 987,
+      "name": "Custom App Report",
+      "shopify_ql": "SHOW quantity_count, total_sales BY product_type, vendor, product_title FROM products SINCE -1m UNTIL -0m ORDER BY total_sales DESC",
+      "updated_at": "2017-04-12T14:00:54-04:00",
+      "category": "custom_app_reports"
+    }
+  ]
+}

+ 35 - 0
test/report_test.rb

@@ -0,0 +1,35 @@
+require 'test_helper'
+
+class ReportTest < Test::Unit::TestCase
+  test 'get should get a report' do
+    fake 'reports/987', method: :get, status: 200, body: load_fixture('report')
+
+    report = ShopifyAPI::Report.find(987)
+    assert_equal 987, report.id
+  end
+
+  test 'get all should get all reports' do
+    fake 'reports', method: :get, status: 200, body: load_fixture('reports')
+
+    reports = ShopifyAPI::Report.all
+    assert_equal 'custom_app_reports', reports.first.category
+  end
+
+  test 'create should create a report' do
+    fake 'reports', method: :post, status: 201, body: load_fixture('report')
+
+    report = ShopifyAPI::Report.create(
+      name: 'Custom App Report',
+      shopify_ql: 'SHOW quantity_count, total_sales BY product_type, vendor, product_title FROM products SINCE -1m UNTIL -0m ORDER BY total_sales DESC'
+    )
+    assert_equal 'custom_app_reports', report.category
+  end
+
+  test 'delete should delete report' do
+    fake 'reports/987', method: :get, status: 200, body: load_fixture('report')
+    fake 'reports/987', method: :delete, status: 200, body: '[]'
+
+    report = ShopifyAPI::Report.find(987)
+    assert report.destroy
+  end
+end