Sha256: f84130a14922d53b0178af623723ddf729b14ed7944c46430a3e66c3b7447dcf

Contents?: true

Size: 1.23 KB

Versions: 2

Compression:

Stored size: 1.23 KB

Contents

require 'spec_helper'

describe CrystalApi::WebhookEnvelope do

  subject { CrystalApi::WebhookEnvelope.new }

  describe "#from_json" do
    let(:json_hash) {{
      "webhook_envelope" => {
        "topic"       => "product/update",
        "store_name"  => "examplestore",
        "resource_id" => 385,
        "payload"     => {'variant' => {'id' => 1}}}
    }}

    subject { CrystalApi::WebhookEnvelope.from_json(json_hash) }

    its(:topic)       { should == "product/update" }
    its(:store_name)  { should == "examplestore"}
    its(:resource_id) { should == 385 }
    its(:payload)     { should be_a(CrystalApi::Variant) }

    context "multiple items in the payload" do
      let(:json_hash) {{
        "webhook_envelope" => {
          "topic"       => "product/update",
          "store_name"  => "examplestore",
          "resource_id" => 385,
          "payload"     => [
            {'variant' => {'id' => 1}},
            {'variant' => {'id' => 2}}
          ]}
      }}

      subject { CrystalApi::WebhookEnvelope.from_json(json_hash) }

      it "has both variants in the payload" do
        subject.payload.should == [
          CrystalApi::Variant.new(id: 1),
          CrystalApi::Variant.new(id: 2)
        ]
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
crystal_api-0.1.0 spec/crystal_api/webhook_envelope_spec.rb
crystal_api-0.0.1 spec/crystal_api/webhook_envelope_spec.rb