fix: Make category non-mandatory (#7117)
Creating articles in a new help center without categories throws an error. This PR fixes that.
This commit is contained in:
@@ -8,11 +8,12 @@ json.position article.position
|
|||||||
json.account_id article.account_id
|
json.account_id article.account_id
|
||||||
json.updated_at article.updated_at.to_i
|
json.updated_at article.updated_at.to_i
|
||||||
json.meta article.meta
|
json.meta article.meta
|
||||||
|
|
||||||
json.category do
|
json.category do
|
||||||
json.id article.category_id
|
json.id article.category_id
|
||||||
json.name article.category.name
|
json.name article.category&.name
|
||||||
json.slug article.category.slug
|
json.slug article.category&.slug
|
||||||
json.locale article.category.locale
|
json.locale article.category&.locale
|
||||||
end
|
end
|
||||||
|
|
||||||
json.views article.views
|
json.views article.views
|
||||||
|
|||||||
@@ -41,6 +41,29 @@ RSpec.describe 'Api::V1::Accounts::Articles', type: :request do
|
|||||||
expect(json_response['payload']['position']).to be(3)
|
expect(json_response['payload']['position']).to be(3)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'creates article even if category is not provided' do
|
||||||
|
article_params = {
|
||||||
|
article: {
|
||||||
|
category_id: nil,
|
||||||
|
description: 'test description',
|
||||||
|
title: 'MyTitle',
|
||||||
|
slug: 'my-title',
|
||||||
|
content: 'This is my content.',
|
||||||
|
status: :published,
|
||||||
|
author_id: agent.id,
|
||||||
|
position: 3
|
||||||
|
}
|
||||||
|
}
|
||||||
|
post "/api/v1/accounts/#{account.id}/portals/#{portal.slug}/articles",
|
||||||
|
params: article_params,
|
||||||
|
headers: agent.create_new_auth_token
|
||||||
|
expect(response).to have_http_status(:success)
|
||||||
|
json_response = JSON.parse(response.body)
|
||||||
|
expect(json_response['payload']['title']).to eql('MyTitle')
|
||||||
|
expect(json_response['payload']['status']).to eql('draft')
|
||||||
|
expect(json_response['payload']['position']).to be(3)
|
||||||
|
end
|
||||||
|
|
||||||
it 'associate to the root article' do
|
it 'associate to the root article' do
|
||||||
root_article = create(:article, category: category, slug: 'root-article', portal: portal, account_id: account.id, author_id: agent.id,
|
root_article = create(:article, category: category, slug: 'root-article', portal: portal, account_id: account.id, author_id: agent.id,
|
||||||
associated_article_id: nil)
|
associated_article_id: nil)
|
||||||
|
|||||||
Reference in New Issue
Block a user