docbrown/spec/queries/articles/api_search_query_spec.rb
Ridhwana e67454fa53
Preparation of endpoint and files required for ChatGPT Plugin (#19394)
* feat: add the ./wellknown/ai-plugin.json file

* feat: add a logo

* feat: firts attempt at open_api file with endpoint we thought we'd use

* feat: add a search action to teh articles controller that build up teh appropriate json

* feat: add a query param to the article index

* feat: add some chatgpt endpoints and file paths to CORS

* feat: update the openapi yml file to reflect the article search endpoint

* fix: use the correct concept

* feat: replace the logo

* feat: update the ai-json file

* feat: update the openapi file

* feat: update the api and it's params

* feat: update the search query

* fix: ordering

* feat: cors debug

* fix: logic with markdown

* chore: fix test

* spec: article

* spec: article

* spec: article

* Update public/.well-known/ai-plugin.json

* Update public/openapi.yml

---------

Co-authored-by: Ben Halpern <bendhalpern@gmail.com>
2023-04-27 16:51:24 -04:00

37 lines
1.1 KiB
Ruby

require "rails_helper"
RSpec.describe Articles::ApiSearchQuery, type: :query do
before do
create(:article, published: false)
create(:article, title: "Top ten Interview tips")
create(:article, title: "Top ten Ruby tips")
create(:article, title: "Frontend Frameworks")
create(:article)
end
context "when there is no query parameter" do
it "shows all published and approved articles" do
articles = described_class.call({})
# The one not included has publiched set to false.
expect(articles.count).to eq(4)
end
end
context "when there is a query parameter" do
it "shows articles that match that query" do
articles = described_class.call({ q: "ruby" })
expect(articles.count).to eq(1)
end
end
context "when there is a top parameter" do
it "shows the most popular articles in the last n days" do
article = Article.find_by(title: "Frontend Frameworks")
article.update_column(:published_at, 30.days.ago)
# The two not included is the one that has publiched set to false.
articles = described_class.call({ top: 10 })
expect(articles.count).to eq(3)
end
end
end