mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2024-12-27 10:14:17 +08:00
Merge pull request #796 from Ducz0r/lm-sci-1620
[SCI-1620] Add tests for create new team page
This commit is contained in:
commit
caa8791cad
2 changed files with 118 additions and 2 deletions
|
@ -6,8 +6,10 @@ describe ClientApi::Teams::TeamsController, type: :controller do
|
||||||
before do
|
before do
|
||||||
@user_one = User.first
|
@user_one = User.first
|
||||||
@user_two = FactoryGirl.create :user, email: 'sec_user@asdf.com'
|
@user_two = FactoryGirl.create :user, email: 'sec_user@asdf.com'
|
||||||
@team_one = FactoryGirl.create :team
|
@team_one = FactoryGirl.create :team, created_by: @user_one
|
||||||
@team_two = FactoryGirl.create :team, name: 'Team two'
|
@team_two = FactoryGirl.create :team,
|
||||||
|
name: 'Team two',
|
||||||
|
created_by: @user_two
|
||||||
FactoryGirl.create :user_team, team: @team_one, user: @user_one, role: 2
|
FactoryGirl.create :user_team, team: @team_one, user: @user_one, role: 2
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -19,6 +21,45 @@ describe ClientApi::Teams::TeamsController, type: :controller do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe 'POST #create' do
|
||||||
|
before do
|
||||||
|
@team_one.update_attribute(:name, 'My Team')
|
||||||
|
@team_one.update_attribute(:description, 'Lorem ipsum ipsum')
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should return HTTP success response' do
|
||||||
|
post :create, params: { team: @team_one }, as: :json
|
||||||
|
expect(response).to have_http_status(:ok)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should return HTTP unprocessable_entity response if name too short' do
|
||||||
|
@team_one.update_attribute(
|
||||||
|
:name,
|
||||||
|
('a' * (Constants::NAME_MIN_LENGTH - 1)).to_s
|
||||||
|
)
|
||||||
|
post :create, params: { team: @team_one }, as: :json
|
||||||
|
expect(response).to have_http_status(:unprocessable_entity)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should return HTTP unprocessable_entity response if name too long' do
|
||||||
|
@team_one.update_attribute(
|
||||||
|
:name,
|
||||||
|
('a' * (Constants::NAME_MAX_LENGTH + 1)).to_s
|
||||||
|
)
|
||||||
|
post :create, params: { team: @team_one }, as: :json
|
||||||
|
expect(response).to have_http_status(:unprocessable_entity)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should return HTTP unprocessable_entity response if description too long' do
|
||||||
|
@team_one.update_attribute(
|
||||||
|
:description,
|
||||||
|
('a' * (Constants::TEXT_MAX_LENGTH + 1)).to_s
|
||||||
|
)
|
||||||
|
post :create, params: { team: @team_one }, as: :json
|
||||||
|
expect(response).to have_http_status(:unprocessable_entity)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
describe 'POST #change_team' do
|
describe 'POST #change_team' do
|
||||||
it 'should return HTTP success response' do
|
it 'should return HTTP success response' do
|
||||||
FactoryGirl.create :user_team, team: @team_two, user: @user_one, role: 2
|
FactoryGirl.create :user_team, team: @team_two, user: @user_one, role: 2
|
||||||
|
|
75
spec/services/client_api/teams/create_service_spec.rb
Normal file
75
spec/services/client_api/teams/create_service_spec.rb
Normal file
|
@ -0,0 +1,75 @@
|
||||||
|
require 'rails_helper'
|
||||||
|
|
||||||
|
include ClientApi::Teams
|
||||||
|
|
||||||
|
describe ClientApi::Teams::CreateService do
|
||||||
|
let(:user) { create :user, email: 'user@asdf.com' }
|
||||||
|
let(:team) do
|
||||||
|
build :team, name: 'My Team', description: 'My Description'
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should raise a StandardError if current_user is not assigned' do
|
||||||
|
expect { CreateService.new }.to raise_error(StandardError)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should create a new team' do
|
||||||
|
service = CreateService.new(
|
||||||
|
current_user: user,
|
||||||
|
params: { name: team.name, description: team.description }
|
||||||
|
)
|
||||||
|
result = service.execute
|
||||||
|
expect(result[:status]).to eq :success
|
||||||
|
|
||||||
|
team_n = Team.order(created_at: :desc).first
|
||||||
|
expect(team_n.name).to eq team.name
|
||||||
|
expect(team_n.description).to eq team.description
|
||||||
|
expect(team_n.created_by).to eq user
|
||||||
|
expect(team_n.users.count).to eq 1
|
||||||
|
expect(team_n.users.take).to eq user
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should return error response if params = {}' do
|
||||||
|
service = CreateService.new(current_user: user, params: {})
|
||||||
|
result = service.execute
|
||||||
|
expect(result[:status]).to eq :error
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should return error response if params are missing :name attribute' do
|
||||||
|
service = CreateService.new(
|
||||||
|
current_user: user,
|
||||||
|
params: { description: team.description }
|
||||||
|
)
|
||||||
|
result = service.execute
|
||||||
|
expect(result[:status]).to eq :error
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should return error response if name too short' do
|
||||||
|
team.name = ('a' * (Constants::NAME_MIN_LENGTH - 1)).to_s
|
||||||
|
service = CreateService.new(
|
||||||
|
current_user: user,
|
||||||
|
params: { name: team.name, description: team.description }
|
||||||
|
)
|
||||||
|
result = service.execute
|
||||||
|
expect(result[:status]).to eq :error
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should return error response if name too long' do
|
||||||
|
team.name = ('a' * (Constants::NAME_MAX_LENGTH + 1)).to_s
|
||||||
|
service = CreateService.new(
|
||||||
|
current_user: user,
|
||||||
|
params: { name: team.name, description: team.description }
|
||||||
|
)
|
||||||
|
result = service.execute
|
||||||
|
expect(result[:status]).to eq :error
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should return error response if description too long' do
|
||||||
|
team.description = ('a' * (Constants::TEXT_MAX_LENGTH + 1)).to_s
|
||||||
|
service = CreateService.new(
|
||||||
|
current_user: user,
|
||||||
|
params: { name: team.name, description: team.description }
|
||||||
|
)
|
||||||
|
result = service.execute
|
||||||
|
expect(result[:status]).to eq :error
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in a new issue