Sha256: 2d5df745d3887507bacfd7d71cfa0750e6c7a69fe3bb40846d6b9c328f8b4ec3

Contents?: true

Size: 1.49 KB

Versions: 20

Compression:

Stored size: 1.49 KB

Contents

require "spec_helper"
require "json/jwt"

RSpec.describe CanvasSync::Api::V1::LiveEventsController, type: :controller do
  routes { CanvasSync::Engine.routes }

  let(:event) {
    {
      "metadata" => {
        event_name: "user_created",
      },
      "payload" => {
        user_id: 42660000000000001,
      },
    }.with_indifferent_access
  }

  describe "#transform_ids!" do
    it "transforms sharded IDs to local IDs" do
      controller.send(:transform_ids!, event)
      expect(event[:payload][:user_id]).to eql 1
      expect(event[:payload][:sharded_user_id]).to eql 42660000000000001
    end

    xit "it does not transform cross-shard IDs" do
      # TODO
    end
  end

  describe "#process_dataservices_event" do
    let(:private_key) { OpenSSL::PKey::RSA.new(2048) }
    let(:jwk) { JSON::JWK.new(private_key) }
    let(:jwks) { JSON::JWK::Set.new([jwk]) }

    before :each do
      allow(controller).to receive(:dataservices_jwks).and_return(jwks)
    end

    let(:event_data) { event.to_json }

    it "triggers a background job" do
      expect(controller).to receive(:dispatch_event)
      expect(controller).to receive(:validate_tenant!)
      post :process_event, params: { "_json" => JSON::JWT.new(event).sign(jwk).to_s }
      expect(response).to be_successful
    end

    it "does not allow unsigned events" do
      expect(controller).to_not receive(:validate_tenant!)
      post :process_event, params: { "_json" => event.to_json }
      expect(response).to_not be_successful
    end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
canvas_sync-0.22.9 spec/canvas_sync/live_events/live_events_controller_spec.rb
canvas_sync-0.22.8 spec/canvas_sync/live_events/live_events_controller_spec.rb
canvas_sync-0.22.6 spec/canvas_sync/live_events/live_events_controller_spec.rb
canvas_sync-0.22.5 spec/canvas_sync/live_events/live_events_controller_spec.rb
canvas_sync-0.22.4 spec/canvas_sync/live_events/live_events_controller_spec.rb
canvas_sync-0.22.3 spec/canvas_sync/live_events/live_events_controller_spec.rb
canvas_sync-0.22.2 spec/canvas_sync/live_events/live_events_controller_spec.rb
canvas_sync-0.22.1 spec/canvas_sync/live_events/live_events_controller_spec.rb
canvas_sync-0.22.0 spec/canvas_sync/live_events/live_events_controller_spec.rb
canvas_sync-0.22.0.beta8 spec/canvas_sync/live_events/live_events_controller_spec.rb
canvas_sync-0.22.0.beta7 spec/canvas_sync/live_events/live_events_controller_spec.rb
canvas_sync-0.22.0.beta6 spec/canvas_sync/live_events/live_events_controller_spec.rb
canvas_sync-0.22.0.beta5 spec/canvas_sync/live_events/live_events_controller_spec.rb
canvas_sync-0.22.0.beta4 spec/canvas_sync/live_events/live_events_controller_spec.rb
canvas_sync-0.22.0.beta3 spec/canvas_sync/live_events/live_events_controller_spec.rb
canvas_sync-0.22.0.beta2 spec/canvas_sync/live_events/live_events_controller_spec.rb
canvas_sync-0.22.0.beta1 spec/canvas_sync/live_events/live_events_controller_spec.rb
canvas_sync-0.21.1 spec/canvas_sync/live_events/live_events_controller_spec.rb
canvas_sync-0.21.1.beta1 spec/canvas_sync/live_events/live_events_controller_spec.rb
canvas_sync-0.21.0 spec/canvas_sync/live_events/live_events_controller_spec.rb