Sha256: aa31315fdeaa7c66e2bb4e9d1351e86ebb45c08e194f7f33a1d9fb5e7932642e

Contents?: true

Size: 1.84 KB

Versions: 4

Compression:

Stored size: 1.84 KB

Contents

require 'test_helper'

module Workarea
  module Api
    module Admin
      class UsersIntegrationTest < IntegrationTest
        include Workarea::Admin::IntegrationTest

        def sample_attributes
          @count ||= 0
          @count += 1

          create_user
            .as_json
            .except('_id', 'token')
            .merge('email' => "api#{@count}@workarea.com")
        end

        def test_lists_users
          users = [create_user, create_user]
          get admin_api.users_path
          result = JSON.parse(response.body)['users']

          assert_equal(3, result.length) # plus one for API auth
          assert_equal(users.second, User.new(result.first))
          assert_equal(users.first, User.new(result.second))
        end

        def test_creates_users
          data = sample_attributes
          assert_difference 'User.count', 1 do
            post admin_api.users_path, params: { user: data }
          end
        end

        def test_shows_users
          user = create_user
          get admin_api.user_path(user.id)
          result = JSON.parse(response.body)['user']
          assert(result['password_digest'].blank?)
          assert_equal(user, User.new(result))
        end

        def test_updates_users
          user = create_user
          patch admin_api.user_path(user.id), params: { user: { first_name: 'Foo' } }
          assert_equal('Foo', user.reload.first_name)
        end

        def test_bulk_upserts_users
          data = Array.new(10) { sample_attributes }
          assert_difference 'User.count', 10 do
            patch admin_api.bulk_users_path, params: { users: data }
          end
        end

        def test_destroys_users
          user = create_user

          assert_difference 'User.count', -1 do
            delete admin_api.user_path(user.id)
          end
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 2 rubygems

Version Path
workarea-api-4.4.7 admin/test/integration/workarea/api/admin/users_integration_test.rb
workarea-api-admin-4.4.7 test/integration/workarea/api/admin/users_integration_test.rb
workarea-api-4.4.6 admin/test/integration/workarea/api/admin/users_integration_test.rb
workarea-api-admin-4.4.6 test/integration/workarea/api/admin/users_integration_test.rb