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:
Shivam Mishra
2023-05-18 18:42:28 +05:30
committed by GitHub
parent 590ce788b9
commit f2f33038f2
2 changed files with 27 additions and 3 deletions

View File

@@ -8,11 +8,12 @@ json.position article.position
json.account_id article.account_id
json.updated_at article.updated_at.to_i
json.meta article.meta
json.category do
json.id article.category_id
json.name article.category.name
json.slug article.category.slug
json.locale article.category.locale
json.name article.category&.name
json.slug article.category&.slug
json.locale article.category&.locale
end
json.views article.views

View File

@@ -41,6 +41,29 @@ RSpec.describe 'Api::V1::Accounts::Articles', type: :request do
expect(json_response['payload']['position']).to be(3)
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
root_article = create(:article, category: category, slug: 'root-article', portal: portal, account_id: account.id, author_id: agent.id,
associated_article_id: nil)