|
| 1 | +require File.dirname(__FILE__) + '/../../test_helper.rb' |
| 2 | + |
| 3 | +class Drip::Client::ShopperActivityTest < Drip::TestCase |
| 4 | + def setup |
| 5 | + @client = Drip::Client.new { |c| c.account_id = "12345" } |
| 6 | + end |
| 7 | + |
| 8 | + context "#create_cart_activity_event" do |
| 9 | + setup do |
| 10 | + @email = "drippy@drip.com" |
| 11 | + @options = { |
| 12 | + email: @email, |
| 13 | + action: "created", |
| 14 | + provider: "shopify", |
| 15 | + cart_id: "abcdef", |
| 16 | + cart_url: "https://www.example.com/mythingy", |
| 17 | + amount: 4900, |
| 18 | + tax: 100, |
| 19 | + fees: 0, |
| 20 | + discount: 0, |
| 21 | + currency_code: "USD", |
| 22 | + properties: { |
| 23 | + "size" => "medium", |
| 24 | + "color" => "red" |
| 25 | + } |
| 26 | + } |
| 27 | + @response_status = 202 |
| 28 | + @response_body = "{}" |
| 29 | + |
| 30 | + stub_request(:post, "https://api.getdrip.com/v3/12345/shopper_activity/cart"). |
| 31 | + with(headers: { "Content-Type" => "application/json" }). |
| 32 | + to_return(status: @response_status, body: @response_body, headers: {}) |
| 33 | + end |
| 34 | + |
| 35 | + should "send the right request" do |
| 36 | + expected = Drip::Response.new(@response_status, JSON.parse(@response_body)) |
| 37 | + assert_equal expected, @client.create_cart_activity_event(@options) |
| 38 | + end |
| 39 | + |
| 40 | + should "return error when missing fields" do |
| 41 | + @options.delete(:cart_id) |
| 42 | + assert_raises(ArgumentError) { @client.create_cart_activity_event(@options) } |
| 43 | + end |
| 44 | + end |
| 45 | + |
| 46 | + context "#create_order_activity_event" do |
| 47 | + setup do |
| 48 | + @email = "drippy@drip.com" |
| 49 | + @options = { |
| 50 | + email: @email, |
| 51 | + action: "created", |
| 52 | + provider: "shopify", |
| 53 | + order_id: "abcdef", |
| 54 | + amount: 4900, |
| 55 | + tax: 100, |
| 56 | + fees: 0, |
| 57 | + discount: 0, |
| 58 | + currency_code: "USD", |
| 59 | + properties: { |
| 60 | + "size" => "medium", |
| 61 | + "color" => "red" |
| 62 | + } |
| 63 | + } |
| 64 | + @response_status = 202 |
| 65 | + @response_body = "{}" |
| 66 | + |
| 67 | + stub_request(:post, "https://api.getdrip.com/v3/12345/shopper_activity/order"). |
| 68 | + with(headers: { "Content-Type" => "application/json" }). |
| 69 | + to_return(status: @response_status, body: @response_body, headers: {}) |
| 70 | + end |
| 71 | + |
| 72 | + should "send the right request" do |
| 73 | + expected = Drip::Response.new(@response_status, JSON.parse(@response_body)) |
| 74 | + assert_equal expected, @client.create_order_activity_event(@options) |
| 75 | + end |
| 76 | + |
| 77 | + should "return error when missing fields" do |
| 78 | + @options.delete(:order_id) |
| 79 | + assert_raises(ArgumentError) { @client.create_order_activity_event(@options) } |
| 80 | + end |
| 81 | + end |
| 82 | + |
| 83 | + context "#create_product_activity_event" do |
| 84 | + setup do |
| 85 | + @email = "drippy@drip.com" |
| 86 | + @options = { |
| 87 | + provider: "my_custom_platform", |
| 88 | + action: "created", |
| 89 | + occurred_at: "2019-01-28T12:15:23Z", |
| 90 | + product_id: "B01J4SWO1G", |
| 91 | + product_variant_id: "B01J4SWO1G-CW-BOTT", |
| 92 | + sku: "XHB-1234", |
| 93 | + name: "The Coolest Water Bottle", |
| 94 | + brand: "Drip", |
| 95 | + categories: [ |
| 96 | + "Accessories" |
| 97 | + ], |
| 98 | + price: 11.16, |
| 99 | + inventory: 42, |
| 100 | + product_url: "https://mysuperstore.example.com/dp/B01J4SWO1G", |
| 101 | + image_url: "https://www.getdrip.com/images/example_products/water_bottle.png" |
| 102 | + } |
| 103 | + @response_status = 202 |
| 104 | + @response_body = "{}" |
| 105 | + |
| 106 | + stub_request(:post, "https://api.getdrip.com/v3/12345/shopper_activity/product"). |
| 107 | + with(headers: { "Content-Type" => "application/json" }). |
| 108 | + to_return(status: @response_status, body: @response_body, headers: {}) |
| 109 | + end |
| 110 | + |
| 111 | + should "send the right request" do |
| 112 | + expected = Drip::Response.new(@response_status, JSON.parse(@response_body)) |
| 113 | + assert_equal expected, @client.create_product_activity_event(@options) |
| 114 | + end |
| 115 | + |
| 116 | + should "return error when missing fields" do |
| 117 | + @options.delete(:product_id) |
| 118 | + assert_raises(ArgumentError) { @client.create_product_activity_event(@options) } |
| 119 | + end |
| 120 | + end |
| 121 | +end |
0 commit comments