feat: Portal endpoint (#4633)
This commit is contained in:
@@ -1,15 +1,15 @@
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe 'Api::V1::Accounts::Kbase::Categories', type: :request do
|
||||
RSpec.describe 'Api::V1::Accounts::Categories', type: :request do
|
||||
let(:account) { create(:account) }
|
||||
let(:agent) { create(:user, account: account, role: :agent) }
|
||||
let!(:portal) { create(:kbase_portal, name: 'test_portal', account_id: account.id) }
|
||||
let!(:category) { create(:kbase_category, name: 'category', portal: portal, account_id: account.id) }
|
||||
let!(:portal) { create(:portal, name: 'test_portal', account_id: account.id) }
|
||||
let!(:category) { create(:category, name: 'category', portal: portal, account_id: account.id) }
|
||||
|
||||
describe 'POST /api/v1/accounts/{account.id}/kbase/portals/{portal.slug}/categories' do
|
||||
describe 'POST /api/v1/accounts/{account.id}/portals/{portal.slug}/categories' do
|
||||
context 'when it is an unauthenticated user' do
|
||||
it 'returns unauthorized' do
|
||||
post "/api/v1/accounts/#{account.id}/kbase/portals/#{portal.slug}/categories", params: {}
|
||||
post "/api/v1/accounts/#{account.id}/portals/#{portal.slug}/categories", params: {}
|
||||
expect(response).to have_http_status(:unauthorized)
|
||||
end
|
||||
end
|
||||
@@ -23,7 +23,7 @@ RSpec.describe 'Api::V1::Accounts::Kbase::Categories', type: :request do
|
||||
position: 1
|
||||
}
|
||||
}
|
||||
post "/api/v1/accounts/#{account.id}/kbase/portals/#{portal.slug}/categories",
|
||||
post "/api/v1/accounts/#{account.id}/portals/#{portal.slug}/categories",
|
||||
params: category_params,
|
||||
headers: agent.create_new_auth_token
|
||||
expect(response).to have_http_status(:success)
|
||||
@@ -33,10 +33,10 @@ RSpec.describe 'Api::V1::Accounts::Kbase::Categories', type: :request do
|
||||
end
|
||||
end
|
||||
|
||||
describe 'PUT /api/v1/accounts/{account.id}/kbase/portals/{portal.slug}/categories/{category.id}' do
|
||||
describe 'PUT /api/v1/accounts/{account.id}/portals/{portal.slug}/categories/{category.id}' do
|
||||
context 'when it is an unauthenticated user' do
|
||||
it 'returns unauthorized' do
|
||||
put "/api/v1/accounts/#{account.id}/kbase/portals/#{portal.slug}/categories/#{category.id}", params: {}
|
||||
put "/api/v1/accounts/#{account.id}/portals/#{portal.slug}/categories/#{category.id}", params: {}
|
||||
expect(response).to have_http_status(:unauthorized)
|
||||
end
|
||||
end
|
||||
@@ -53,7 +53,7 @@ RSpec.describe 'Api::V1::Accounts::Kbase::Categories', type: :request do
|
||||
|
||||
expect(category.name).not_to eql(category_params[:category][:name])
|
||||
|
||||
put "/api/v1/accounts/#{account.id}/kbase/portals/#{portal.slug}/categories/#{category.id}",
|
||||
put "/api/v1/accounts/#{account.id}/portals/#{portal.slug}/categories/#{category.id}",
|
||||
params: category_params,
|
||||
headers: agent.create_new_auth_token
|
||||
expect(response).to have_http_status(:success)
|
||||
@@ -63,39 +63,39 @@ RSpec.describe 'Api::V1::Accounts::Kbase::Categories', type: :request do
|
||||
end
|
||||
end
|
||||
|
||||
describe 'DELETE /api/v1/accounts/{account.id}/kbase/portals/{portal.slug}/categories/{category.id}' do
|
||||
describe 'DELETE /api/v1/accounts/{account.id}/portals/{portal.slug}/categories/{category.id}' do
|
||||
context 'when it is an unauthenticated user' do
|
||||
it 'returns unauthorized' do
|
||||
delete "/api/v1/accounts/#{account.id}/kbase/portals/#{portal.slug}/categories/#{category.id}", params: {}
|
||||
delete "/api/v1/accounts/#{account.id}/portals/#{portal.slug}/categories/#{category.id}", params: {}
|
||||
expect(response).to have_http_status(:unauthorized)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when it is an authenticated user' do
|
||||
it 'deletes category' do
|
||||
delete "/api/v1/accounts/#{account.id}/kbase/portals/#{portal.slug}/categories/#{category.id}",
|
||||
delete "/api/v1/accounts/#{account.id}/portals/#{portal.slug}/categories/#{category.id}",
|
||||
headers: agent.create_new_auth_token
|
||||
expect(response).to have_http_status(:success)
|
||||
deleted_category = Kbase::Category.find_by(id: category.id)
|
||||
deleted_category = Category.find_by(id: category.id)
|
||||
expect(deleted_category).to be nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'GET /api/v1/accounts/{account.id}/kbase/portals/{portal.slug}/categories' do
|
||||
describe 'GET /api/v1/accounts/{account.id}/portals/{portal.slug}/categories' do
|
||||
context 'when it is an unauthenticated user' do
|
||||
it 'returns unauthorized' do
|
||||
get "/api/v1/accounts/#{account.id}/kbase/portals/#{portal.slug}/categories"
|
||||
get "/api/v1/accounts/#{account.id}/portals/#{portal.slug}/categories"
|
||||
expect(response).to have_http_status(:unauthorized)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when it is an authenticated user' do
|
||||
it 'get all portals' do
|
||||
category2 = create(:kbase_category, name: 'test_category_2', portal: portal)
|
||||
category2 = create(:category, name: 'test_category_2', portal: portal)
|
||||
expect(category2.id).not_to be nil
|
||||
|
||||
get "/api/v1/accounts/#{account.id}/kbase/portals/#{portal.slug}/categories",
|
||||
get "/api/v1/accounts/#{account.id}/portals/#{portal.slug}/categories",
|
||||
headers: agent.create_new_auth_token
|
||||
expect(response).to have_http_status(:success)
|
||||
json_response = JSON.parse(response.body)
|
||||
@@ -1,23 +1,23 @@
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe 'Api::V1::Accounts::Kbase::Portals', type: :request do
|
||||
RSpec.describe 'Api::V1::Accounts::Portals', type: :request do
|
||||
let(:account) { create(:account) }
|
||||
let(:agent) { create(:user, account: account, role: :agent) }
|
||||
let!(:portal) { create(:kbase_portal, slug: 'portal-1', name: 'test_portal', account_id: account.id) }
|
||||
let!(:portal) { create(:portal, slug: 'portal-1', name: 'test_portal', account_id: account.id) }
|
||||
|
||||
describe 'GET /api/v1/accounts/{account.id}/kbase/portals' do
|
||||
describe 'GET /api/v1/accounts/{account.id}/portals' do
|
||||
context 'when it is an unauthenticated user' do
|
||||
it 'returns unauthorized' do
|
||||
get "/api/v1/accounts/#{account.id}/kbase/portals"
|
||||
get "/api/v1/accounts/#{account.id}/portals"
|
||||
expect(response).to have_http_status(:unauthorized)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when it is an authenticated user' do
|
||||
it 'get all portals' do
|
||||
portal2 = create(:kbase_portal, name: 'test_portal_2', account_id: account.id, slug: 'portal-2')
|
||||
portal2 = create(:portal, name: 'test_portal_2', account_id: account.id, slug: 'portal-2')
|
||||
expect(portal2.id).not_to be nil
|
||||
get "/api/v1/accounts/#{account.id}/kbase/portals",
|
||||
get "/api/v1/accounts/#{account.id}/portals",
|
||||
headers: agent.create_new_auth_token
|
||||
expect(response).to have_http_status(:success)
|
||||
json_response = JSON.parse(response.body)
|
||||
@@ -26,17 +26,17 @@ RSpec.describe 'Api::V1::Accounts::Kbase::Portals', type: :request do
|
||||
end
|
||||
end
|
||||
|
||||
describe 'GET /api/v1/accounts/{account.id}/kbase/portals/{portal.slug}' do
|
||||
describe 'GET /api/v1/accounts/{account.id}/portals/{portal.slug}' do
|
||||
context 'when it is an unauthenticated user' do
|
||||
it 'returns unauthorized' do
|
||||
get "/api/v1/accounts/#{account.id}/kbase/portals"
|
||||
get "/api/v1/accounts/#{account.id}/portals"
|
||||
expect(response).to have_http_status(:unauthorized)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when it is an authenticated user' do
|
||||
it 'get one portals' do
|
||||
get "/api/v1/accounts/#{account.id}/kbase/portals/#{portal.slug}",
|
||||
get "/api/v1/accounts/#{account.id}/portals/#{portal.slug}",
|
||||
headers: agent.create_new_auth_token
|
||||
expect(response).to have_http_status(:success)
|
||||
json_response = JSON.parse(response.body)
|
||||
@@ -45,10 +45,10 @@ RSpec.describe 'Api::V1::Accounts::Kbase::Portals', type: :request do
|
||||
end
|
||||
end
|
||||
|
||||
describe 'POST /api/v1/accounts/{account.id}/kbase/portals' do
|
||||
describe 'POST /api/v1/accounts/{account.id}/portals' do
|
||||
context 'when it is an unauthenticated user' do
|
||||
it 'returns unauthorized' do
|
||||
post "/api/v1/accounts/#{account.id}/kbase/portals", params: {}
|
||||
post "/api/v1/accounts/#{account.id}/portals", params: {}
|
||||
expect(response).to have_http_status(:unauthorized)
|
||||
end
|
||||
end
|
||||
@@ -61,7 +61,7 @@ RSpec.describe 'Api::V1::Accounts::Kbase::Portals', type: :request do
|
||||
slug: 'test_kbase'
|
||||
}
|
||||
}
|
||||
post "/api/v1/accounts/#{account.id}/kbase/portals",
|
||||
post "/api/v1/accounts/#{account.id}/portals",
|
||||
params: portal_params,
|
||||
headers: agent.create_new_auth_token
|
||||
expect(response).to have_http_status(:success)
|
||||
@@ -71,10 +71,10 @@ RSpec.describe 'Api::V1::Accounts::Kbase::Portals', type: :request do
|
||||
end
|
||||
end
|
||||
|
||||
describe 'PUT /api/v1/accounts/{account.id}/kbase/portals/{portal.slug}' do
|
||||
describe 'PUT /api/v1/accounts/{account.id}/portals/{portal.slug}' do
|
||||
context 'when it is an unauthenticated user' do
|
||||
it 'returns unauthorized' do
|
||||
put "/api/v1/accounts/#{account.id}/kbase/portals/#{portal.slug}", params: {}
|
||||
put "/api/v1/accounts/#{account.id}/portals/#{portal.slug}", params: {}
|
||||
expect(response).to have_http_status(:unauthorized)
|
||||
end
|
||||
end
|
||||
@@ -89,30 +89,50 @@ RSpec.describe 'Api::V1::Accounts::Kbase::Portals', type: :request do
|
||||
|
||||
expect(portal.name).to eql('test_portal')
|
||||
|
||||
put "/api/v1/accounts/#{account.id}/kbase/portals/#{portal.slug}",
|
||||
put "/api/v1/accounts/#{account.id}/portals/#{portal.slug}",
|
||||
params: portal_params,
|
||||
headers: agent.create_new_auth_token
|
||||
expect(response).to have_http_status(:success)
|
||||
json_response = JSON.parse(response.body)
|
||||
expect(json_response['name']).to eql(portal_params[:portal][:name])
|
||||
end
|
||||
|
||||
it 'archive portal' do
|
||||
portal_params = {
|
||||
portal: {
|
||||
archived: true
|
||||
}
|
||||
}
|
||||
|
||||
expect(portal.archived).to be_falsy
|
||||
|
||||
put "/api/v1/accounts/#{account.id}/portals/#{portal.slug}",
|
||||
params: portal_params,
|
||||
headers: agent.create_new_auth_token
|
||||
expect(response).to have_http_status(:success)
|
||||
json_response = JSON.parse(response.body)
|
||||
expect(json_response['archived']).to eql(portal_params[:portal][:archived])
|
||||
|
||||
portal.reload
|
||||
expect(portal.archived).to be_truthy
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'DELETE /api/v1/accounts/{account.id}/kbase/portals/{portal.slug}' do
|
||||
describe 'DELETE /api/v1/accounts/{account.id}/portals/{portal.slug}' do
|
||||
context 'when it is an unauthenticated user' do
|
||||
it 'returns unauthorized' do
|
||||
delete "/api/v1/accounts/#{account.id}/kbase/portals/#{portal.slug}", params: {}
|
||||
delete "/api/v1/accounts/#{account.id}/portals/#{portal.slug}", params: {}
|
||||
expect(response).to have_http_status(:unauthorized)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when it is an authenticated user' do
|
||||
it 'deletes portal' do
|
||||
delete "/api/v1/accounts/#{account.id}/kbase/portals/#{portal.slug}",
|
||||
delete "/api/v1/accounts/#{account.id}/portals/#{portal.slug}",
|
||||
headers: agent.create_new_auth_token
|
||||
expect(response).to have_http_status(:success)
|
||||
deleted_portal = Kbase::Portal.find_by(id: portal.slug)
|
||||
deleted_portal = Portal.find_by(id: portal.slug)
|
||||
expect(deleted_portal).to be nil
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user