Sha256: 3dfcc24bf7651723b26c773d94569071b2385c51f557b4c584e7eba560bbd649

Contents?: true

Size: 1.56 KB

Versions: 21

Compression:

Stored size: 1.56 KB

Contents

require 'test_helper'

class SynchronisesTest < ActionDispatch::IntegrationTest
  fixtures :all

  def setup
    @shop = disco_app_shops(:widget_store)
    @product = products(:ipod)
    @routes = DiscoApp::Engine.routes
  end

  def teardown
    @shop = nil
  end

  test 'new product is created when product created webhook is received' do
    post_webhook('product_created', :'products/create')

    # Assert the product was created locally, with the correct attributes.
    product = Product.find(632910392)
    assert_equal 'IPod Nano - 8GB', product.data['title']
  end

  test 'existing product is updated when product updated webhook is received' do
    assert_equal({}, @product.data)

    post_webhook('product_updated', :'products/update')

    # Assert the product was updated locally, with the correct attributes.
    @product.reload
    assert_equal 632910393, @product.id
    assert_equal 'IPod Nano - 8GB', @product.data['title']
  end

  test 'existing product is deleted when product deleted webhook is receieved' do
    post_webhook('product_deleted', :'products/delete')
    assert_equal 0, Product.count
  end

  private

    def webhooks_url
      DiscoApp::Engine.routes.url_helpers.webhooks_url
    end

    def post_webhook(fixture_name, webhook_topic)
      body = webhook_fixture(fixture_name)
      post(webhooks_url, body, {
        HTTP_X_SHOPIFY_TOPIC: webhook_topic,
        HTTP_X_SHOPIFY_SHOP_DOMAIN: @shop.shopify_domain,
        HTTP_X_SHOPIFY_HMAC_SHA256: DiscoApp::WebhookService.calculated_hmac(body, ShopifyApp.configuration.secret)
      })
    end

end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
disco_app-0.8.6 test/integration/synchronises_test.rb
disco_app-0.8.7 test/integration/synchronises_test.rb
disco_app-0.8.8 test/integration/synchronises_test.rb
disco_app-0.8.9 test/integration/synchronises_test.rb
disco_app-0.9.0 test/integration/synchronises_test.rb
disco_app-0.9.1 test/integration/synchronises_test.rb
disco_app-0.9.2 test/integration/synchronises_test.rb
disco_app-0.9.3 test/integration/synchronises_test.rb
disco_app-0.9.4 test/integration/synchronises_test.rb
disco_app-0.9.5 test/integration/synchronises_test.rb
disco_app-0.9.6 test/integration/synchronises_test.rb
disco_app-0.9.7 test/integration/synchronises_test.rb
disco_app-0.9.8 test/integration/synchronises_test.rb
disco_app-0.9.9 test/integration/synchronises_test.rb
disco_app-0.9.10 test/integration/synchronises_test.rb
disco_app-0.9.11 test/integration/synchronises_test.rb
disco_app-0.10.0 test/integration/synchronises_test.rb
disco_app-0.10.1 test/integration/synchronises_test.rb
disco_app-0.10.2 test/integration/synchronises_test.rb
disco_app-0.10.3 test/integration/synchronises_test.rb