2020-05-13 17:01:42 +00:00
|
|
|
require 'rails_helper'
|
|
|
|
|
2020-06-18 11:51:25 +00:00
|
|
|
RSpec.describe 'Admin Knowledge Base Public Menu', type: :request, authenticated_as: :current_user do
|
2020-05-13 17:01:42 +00:00
|
|
|
let(:url) { "/api/v1/knowledge_bases/manage/#{knowledge_base.id}/update_menu_items" }
|
|
|
|
let(:params) do
|
|
|
|
{
|
|
|
|
menu_items_sets: [{
|
2021-02-01 12:42:44 +00:00
|
|
|
kb_locale_id: kb_locale.id,
|
|
|
|
location: location,
|
|
|
|
menu_items: menu_items
|
2020-05-13 17:01:42 +00:00
|
|
|
}]
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2020-06-18 11:51:25 +00:00
|
|
|
let(:current_user) { create(:admin) }
|
2020-05-13 17:01:42 +00:00
|
|
|
let(:menu_item) { create(:knowledge_base_menu_item) }
|
|
|
|
let(:kb_locale) { menu_item.kb_locale }
|
|
|
|
let(:knowledge_base) { kb_locale.knowledge_base }
|
|
|
|
let(:location) { 'header' }
|
|
|
|
|
|
|
|
it 'edit title' do
|
|
|
|
attrs = to_params(menu_item)
|
|
|
|
attrs[:title] = 'new title'
|
|
|
|
|
|
|
|
params = build_params([attrs])
|
|
|
|
|
|
|
|
expect { make_request(params) }.to change { menu_item.reload.title }.to 'new title'
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'delete item' do
|
|
|
|
attrs = to_params(menu_item)
|
|
|
|
attrs[:_destroy] = true
|
|
|
|
|
|
|
|
params = build_params([attrs])
|
|
|
|
|
|
|
|
expect { make_request(params) }.to change { KnowledgeBase::MenuItem.count }.by(-1)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'add item' do
|
|
|
|
new_item = {
|
|
|
|
title: 'new item',
|
|
|
|
new_tab: false,
|
|
|
|
url: '/new_url'
|
|
|
|
}
|
|
|
|
|
|
|
|
params = build_params([to_params(menu_item), new_item])
|
|
|
|
|
|
|
|
expect { make_request(params) }.to change { KnowledgeBase::MenuItem.count }.by(1)
|
|
|
|
end
|
|
|
|
|
|
|
|
def to_params(item)
|
|
|
|
item.slice :id, :title, :url, :new_tab
|
|
|
|
end
|
|
|
|
|
|
|
|
def make_request(params)
|
|
|
|
patch url, params: params, as: :json
|
|
|
|
end
|
|
|
|
|
|
|
|
def build_params(menu_items)
|
|
|
|
{
|
|
|
|
menu_items_sets: [{
|
2021-02-01 12:42:44 +00:00
|
|
|
kb_locale_id: kb_locale.id,
|
|
|
|
location: location,
|
|
|
|
menu_items: menu_items
|
2020-05-13 17:01:42 +00:00
|
|
|
}]
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|