feat: Added portal logo and the updated the JSON (#4996)
This commit is contained in:
@@ -3,7 +3,7 @@ require 'rails_helper'
|
||||
RSpec.describe 'Api::V1::Accounts::Categories', type: :request do
|
||||
let(:account) { create(:account) }
|
||||
let(:agent) { create(:user, account: account, role: :agent) }
|
||||
let!(:portal) { create(:portal, name: 'test_portal', account_id: account.id) }
|
||||
let!(:portal) { create(:portal, name: 'test_portal', account_id: account.id, config: { allowed_locales: %w[en es] }) }
|
||||
let!(:category) { create(:category, name: 'category', portal: portal, account_id: account.id, slug: 'category_slug') }
|
||||
let!(:category_to_associate) do
|
||||
create(:category, name: 'associated category', portal: portal, account_id: account.id, slug: 'associated_category_slug')
|
||||
|
||||
@@ -67,11 +67,14 @@ RSpec.describe 'Api::V1::Accounts::Portals', type: :request do
|
||||
|
||||
context 'when it is an authenticated user' do
|
||||
it 'creates portal' do
|
||||
file = fixture_file_upload(Rails.root.join('spec/assets/avatar.png'), 'image/png')
|
||||
|
||||
portal_params = {
|
||||
portal: {
|
||||
name: 'test_portal',
|
||||
slug: 'test_kbase'
|
||||
}
|
||||
},
|
||||
logo: file
|
||||
}
|
||||
post "/api/v1/accounts/#{account.id}/portals",
|
||||
params: portal_params,
|
||||
@@ -80,6 +83,7 @@ RSpec.describe 'Api::V1::Accounts::Portals', type: :request do
|
||||
expect(response).to have_http_status(:success)
|
||||
json_response = JSON.parse(response.body)
|
||||
expect(json_response['name']).to eql('test_portal')
|
||||
expect(json_response['logo']['filename']).to eql('avatar.png')
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -97,7 +101,8 @@ RSpec.describe 'Api::V1::Accounts::Portals', type: :request do
|
||||
it 'updates portal' do
|
||||
portal_params = {
|
||||
portal: {
|
||||
name: 'updated_test_portal'
|
||||
name: 'updated_test_portal',
|
||||
config: { 'allowed_locales' => %w[en es] }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -110,6 +115,7 @@ RSpec.describe 'Api::V1::Accounts::Portals', type: :request do
|
||||
expect(response).to have_http_status(:success)
|
||||
json_response = JSON.parse(response.body)
|
||||
expect(json_response['name']).to eql(portal_params[:portal][:name])
|
||||
expect(json_response['config']).to eql({ 'allowed_locales' => %w[en es] })
|
||||
end
|
||||
|
||||
it 'archive portal' do
|
||||
|
||||
@@ -3,7 +3,7 @@ require 'rails_helper'
|
||||
RSpec.describe 'Public Articles API', type: :request do
|
||||
let!(:account) { create(:account) }
|
||||
let(:agent) { create(:user, account: account, role: :agent) }
|
||||
let!(:portal) { create(:portal, slug: 'test-portal') }
|
||||
let!(:portal) { create(:portal, slug: 'test-portal', config: { allowed_locales: %w[en es] }) }
|
||||
let!(:category) { create(:category, name: 'category', portal: portal, account_id: account.id, locale: 'en', slug: 'category_slug') }
|
||||
let!(:category_2) { create(:category, name: 'category', portal: portal, account_id: account.id, locale: 'es', slug: 'category_2_slug') }
|
||||
let!(:article) { create(:article, category: category, portal: portal, account_id: account.id, author_id: agent.id) }
|
||||
|
||||
@@ -18,8 +18,8 @@ RSpec.describe Article, type: :model do
|
||||
describe 'search' do
|
||||
let!(:account) { create(:account) }
|
||||
let(:user) { create(:user, account_ids: [account.id], role: :agent) }
|
||||
let!(:portal_1) { create(:portal, account_id: account.id) }
|
||||
let!(:portal_2) { create(:portal, account_id: account.id) }
|
||||
let!(:portal_1) { create(:portal, account_id: account.id, config: { allowed_locales: %w[en es] }) }
|
||||
let!(:portal_2) { create(:portal, account_id: account.id, config: { allowed_locales: %w[en es] }) }
|
||||
let!(:category_1) { create(:category, slug: 'category_1', locale: 'en', portal_id: portal_1.id) }
|
||||
let!(:category_2) { create(:category, slug: 'category_2', locale: 'es', portal_id: portal_1.id) }
|
||||
let!(:category_3) { create(:category, slug: 'category_3', locale: 'es', portal_id: portal_2.id) }
|
||||
|
||||
@@ -15,11 +15,24 @@ RSpec.describe Category, type: :model do
|
||||
it { is_expected.to have_many(:related_categories) }
|
||||
end
|
||||
|
||||
describe 'validations' do
|
||||
let!(:account) { create(:account) }
|
||||
let(:user) { create(:user, account_ids: [account.id], role: :agent) }
|
||||
let!(:portal) { create(:portal, account_id: account.id, config: { allowed_locales: ['en'] }) }
|
||||
|
||||
it 'returns erros when locale is not allowed in the portal' do
|
||||
category = create(:category, slug: 'category_1', locale: 'en', portal_id: portal.id)
|
||||
expect(category).to be_valid
|
||||
category.update(locale: 'es')
|
||||
expect(category.errors.full_messages[0]).to eq("Locale es of category is not part of portal's [\"en\"].")
|
||||
end
|
||||
end
|
||||
|
||||
describe 'search' do
|
||||
let!(:account) { create(:account) }
|
||||
let(:user) { create(:user, account_ids: [account.id], role: :agent) }
|
||||
let!(:portal_1) { create(:portal, account_id: account.id) }
|
||||
let!(:portal_2) { create(:portal, account_id: account.id) }
|
||||
let!(:portal_1) { create(:portal, account_id: account.id, config: { allowed_locales: %w[en es] }) }
|
||||
let!(:portal_2) { create(:portal, account_id: account.id, config: { allowed_locales: %w[en es] }) }
|
||||
|
||||
before do
|
||||
create(:category, slug: 'category_1', locale: 'en', portal_id: portal_1.id)
|
||||
|
||||
@@ -15,4 +15,22 @@ RSpec.describe Portal, type: :model do
|
||||
it { is_expected.to have_many(:portal_members) }
|
||||
it { is_expected.to have_many(:members) }
|
||||
end
|
||||
|
||||
describe 'validations' do
|
||||
let!(:account) { create(:account) }
|
||||
let!(:portal) { create(:portal, account_id: account.id) }
|
||||
|
||||
context 'when set portal config' do
|
||||
it 'Adds default allowed_locales en' do
|
||||
expect(portal.config).to be_present
|
||||
expect(portal.config['allowed_locales']).to eq(['en'])
|
||||
end
|
||||
|
||||
it 'Does not allow any other config than allowed_locales' do
|
||||
portal.update(config: { 'some_other_key': 'test_value' })
|
||||
expect(portal).not_to be_valid
|
||||
expect(portal.errors.full_messages[0]).to eq('Cofig in portal on some_other_key is not supported.')
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user