mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-09-30 17:04:31 +08:00
Merge pull request #4680 from okriuchykhin/ok_SCI_7455
Add API endpoint for retrieving a list of users [SCI-7455]
This commit is contained in:
commit
6c313f86ac
3 changed files with 33 additions and 0 deletions
|
@ -3,8 +3,16 @@
|
|||
module Api
|
||||
module V1
|
||||
class UsersController < BaseController
|
||||
before_action :load_team, only: :index
|
||||
before_action :load_user, only: :show
|
||||
|
||||
def index
|
||||
users = @team.users
|
||||
.page(params.dig(:page, :number))
|
||||
.per(params.dig(:page, :size))
|
||||
render jsonapi: users, each_serializer: UserSerializer
|
||||
end
|
||||
|
||||
def show
|
||||
render jsonapi: @user, serializer: UserSerializer
|
||||
end
|
||||
|
|
|
@ -871,6 +871,7 @@ Rails.application.routes.draw do
|
|||
end
|
||||
end
|
||||
resources :project_folders, only: %i(index show create update)
|
||||
resources :users, only: %i(index)
|
||||
end
|
||||
resources :users, only: %i(show) do
|
||||
resources :user_identities,
|
||||
|
|
|
@ -19,6 +19,30 @@ RSpec.describe 'Api::V1::UsersController', type: :request do
|
|||
{ 'Authorization': 'Bearer ' + generate_token(@user1.id) }
|
||||
end
|
||||
|
||||
describe 'GET users, #index' do
|
||||
it 'When valid request, requested users are members of the team' do
|
||||
hash_body = nil
|
||||
get api_v1_team_users_path(team_id: @team1.id), headers: @valid_headers
|
||||
expect { hash_body = json }.not_to raise_exception
|
||||
pp hash_body[:data]
|
||||
expect(hash_body[:data]).to match(
|
||||
JSON.parse(
|
||||
ActiveModelSerializers::SerializableResource
|
||||
.new(@team1.users, each_serializer: Api::V1::UserSerializer)
|
||||
.to_json
|
||||
)['data']
|
||||
)
|
||||
end
|
||||
|
||||
it 'When invalid request, non existing team' do
|
||||
hash_body = nil
|
||||
get api_v1_team_users_path(team_id: -1), headers: @valid_headers
|
||||
expect(response).to have_http_status(404)
|
||||
expect { hash_body = json }.not_to raise_exception
|
||||
expect(hash_body['errors'][0]).to include('status': 404)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'GET user, #show' do
|
||||
it 'When valid request, requested user is member of the same teams' do
|
||||
hash_body = nil
|
||||
|
|
Loading…
Add table
Reference in a new issue