Sha256: e006da542c7b04cd71102ecc36b56d23d6f216b84d2eba87f075d621df13f462

Contents?: true

Size: 1.69 KB

Versions: 4

Compression:

Stored size: 1.69 KB

Contents

require 'spec_helper'

RSpec.describe RockRMS::Responses::Group, type: :model do
  let(:parsed) { JSON.parse(FixturesHelper.read('groups_with_members.json')) }

  describe '.format' do
    subject(:result) { described_class.format(parsed) }

    context 'when response is array' do
      it 'returns an array' do
        expect(described_class.format([])).to be_a(Array)
      end
    end

    it 'translates keys' do
      result.zip(parsed) do |r, p|
        expect(r[:id]).to eq(p['Id'])
        expect(r[:name]).to eq(p['Name'])
        expect(r[:group_type_id]).to eq(p['GroupTypeId'])
        expect(r[:parent_group_id]).to eq(p['ParentGroupId'])
        expect(r[:campus_id]).to eq(p['CampusId'])
        expect(r[:is_active]).to eq(p['IsActive'])
        expect(r[:guid]).to eq(p['Guid'])
        expect(r[:members]).to eq(p['Members'])
      end
    end

    context 'when locations are included' do
      let(:parsed) { JSON.parse(FixturesHelper.read('groups_with_locations.json')) }

      it 'formats with GroupLocations' do
        expect(RockRMS::Responses::GroupLocation).to receive(:format)
          .with(parsed.first['GroupLocations'])
          .and_return([{ some_key: :value }])
        result
        expect(result.first[:group_locations]).to eq([{ some_key: :value }])
      end
    end

    context 'when campus is included' do
      let(:parsed) { JSON.parse(FixturesHelper.read('groups_with_campus.json')) }

      it 'formats with Campus' do
        expect(RockRMS::Responses::Campus).to receive(:format)
          .with(parsed.first['Campus'])
          .and_return([{ some_key: :value }])
        result
        expect(result.first[:campus]).to eq([{ some_key: :value }])
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
rock_rms-2.0.0 spec/rock_rms/responses/group_spec.rb
rock_rms-1.3.0 spec/rock_rms/responses/group_spec.rb
rock_rms-1.2.0 spec/rock_rms/responses/group_spec.rb
rock_rms-1.1.0 spec/rock_rms/responses/group_spec.rb