#215 テスト・ケース追加
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
require 'rails_helper'
|
||||
|
||||
|
||||
RSpec.describe 'NicoTags', type: :request do
|
||||
describe 'GET /tags/nico' do
|
||||
it 'returns tags and next_cursor when overflowing limit' do
|
||||
create_list(:tag, 21, :nico)
|
||||
get '/tags/nico', params: { limit: 20 }
|
||||
expect(response).to have_http_status(:ok)
|
||||
expect(json['tags'].size).to eq(20)
|
||||
expect(json['next_cursor']).to be_present
|
||||
end
|
||||
end
|
||||
|
||||
describe 'PATCH /tags/nico/:id' do
|
||||
let(:member) { create(:user, :member) }
|
||||
let(:nico_tag) { create(:tag, :nico) }
|
||||
|
||||
it '401 when not logged in' do
|
||||
sign_out
|
||||
patch "/tags/nico/#{nico_tag.id}", params: { tags: 'a b' }
|
||||
expect(response).to have_http_status(:unauthorized)
|
||||
end
|
||||
|
||||
it '403 when not member' do
|
||||
sign_in_as(create(:user, role: 'guest'))
|
||||
patch "/tags/nico/#{nico_tag.id}", params: { tags: 'a b' }
|
||||
expect(response).to have_http_status(:forbidden)
|
||||
end
|
||||
|
||||
it '400 when target is not nico category' do
|
||||
sign_in_as(member)
|
||||
non_nico = create(:tag, :general)
|
||||
patch "/tags/nico/#{non_nico.id}", params: { tags: 'a b' }
|
||||
expect(response).to have_http_status(:bad_request)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -4,7 +4,7 @@ require 'rails_helper'
|
||||
RSpec.describe 'Posts API', type: :request do
|
||||
describe 'GET /posts' do
|
||||
it 'returns tags with name in JSON' do
|
||||
tn = TagName.create!(name: 'gen:spec_tag')
|
||||
tn = TagName.create!(name: 'spec_tag')
|
||||
tag = Tag.create!(tag_name: tn, category: 'general')
|
||||
|
||||
post = Post.create!(title: 'spec post', url: 'https://example.com/spec')
|
||||
@@ -14,7 +14,6 @@ RSpec.describe 'Posts API', type: :request do
|
||||
|
||||
expect(response).to have_http_status(:ok)
|
||||
|
||||
json = JSON.parse(response.body)
|
||||
expect(json).to have_key('posts')
|
||||
expect(json['posts']).to be_a(Array)
|
||||
expect(json['posts']).not_to be_empty
|
||||
@@ -24,7 +23,10 @@ RSpec.describe 'Posts API', type: :request do
|
||||
expect(tags).not_to be_empty
|
||||
|
||||
expect(tags[0]).to have_key('name')
|
||||
expect(tags[0]['name']).to eq('gen:spec_tag')
|
||||
expect(tags[0]['name']).to eq('spec_tag')
|
||||
|
||||
expect(tags.map { |t| t['name'] }).to include('spec_tag')
|
||||
expect(tags[0]).to include('category')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
require "rails_helper"
|
||||
|
||||
|
||||
RSpec.describe "Preview", type: :request do
|
||||
describe "GET /preview/title" do
|
||||
it "401 unless logged in" do
|
||||
sign_out
|
||||
get "/preview/title", params: { url: "example.com" }
|
||||
expect(response).to have_http_status(:unauthorized)
|
||||
end
|
||||
|
||||
it "400 when url blank" do
|
||||
sign_in_as(create(:user))
|
||||
get "/preview/title", params: { url: "" }
|
||||
expect(response).to have_http_status(:bad_request)
|
||||
end
|
||||
|
||||
it "returns parsed title (stubbing URI.open)" do
|
||||
sign_in_as(create(:user))
|
||||
fake_html = "<html><head><title> Hello </title></head></html>"
|
||||
allow(URI).to receive(:open).and_return(StringIO.new(fake_html))
|
||||
|
||||
get "/preview/title", params: { url: "example.com" }
|
||||
expect(response).to have_http_status(:ok)
|
||||
expect(json["title"]).to eq("Hello")
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -44,5 +44,10 @@ RSpec.describe 'Tags API', type: :request do
|
||||
expect(json['id']).to eq(tag.id)
|
||||
expect(json['name']).to eq('spec_tag')
|
||||
end
|
||||
|
||||
it 'returns 404 when not found' do
|
||||
get "/tags/name/#{ CGI.escape('nope') }"
|
||||
expect(response).to have_http_status(:not_found)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
require "rails_helper"
|
||||
|
||||
|
||||
RSpec.describe "Users", type: :request do
|
||||
describe "POST /users" do
|
||||
it "creates guest user and returns code" do
|
||||
post "/users"
|
||||
expect(response).to have_http_status(:ok)
|
||||
expect(json["code"]).to be_present
|
||||
expect(json["user"]["role"]).to eq("guest")
|
||||
end
|
||||
end
|
||||
|
||||
describe "POST /users/code/renew" do
|
||||
it "should be 401 when not logged in (recommended behavior)" do
|
||||
sign_out
|
||||
post "/users/code/renew"
|
||||
expect(response).to have_http_status(:unauthorized)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -4,7 +4,7 @@ require 'securerandom'
|
||||
|
||||
|
||||
RSpec.describe 'Wiki API', type: :request do
|
||||
let!(:user) { create_user_for_wiki! }
|
||||
let!(:user) { create_member_user! }
|
||||
|
||||
let!(:tn) { TagName.create!(name: 'spec_wiki_title') }
|
||||
let!(:page) do
|
||||
@@ -38,5 +38,10 @@ RSpec.describe 'Wiki API', type: :request do
|
||||
expect(json['id']).to eq(page.id)
|
||||
expect(json['title']).to eq('spec_wiki_title')
|
||||
end
|
||||
|
||||
it 'returns 404 when not found' do
|
||||
get "/wiki/title/#{ CGI.escape('nope') }"
|
||||
expect(response).to have_http_status(:not_found)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user