feat: テスト自動化(#104) (#220)
#104 Co-authored-by: miteruzo <miteruzo@naver.com> Reviewed-on: #220
This commit was merged in pull request #220.
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
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')
|
||||
tag = Tag.create!(tag_name: tn, category: 'general')
|
||||
|
||||
post = Post.create!(title: 'spec post', url: 'https://example.com/spec')
|
||||
PostTag.create!(post: post, tag: tag)
|
||||
|
||||
get '/posts'
|
||||
|
||||
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
|
||||
|
||||
tags = json['posts'][0]['tags']
|
||||
expect(tags).to be_a(Array)
|
||||
expect(tags).not_to be_empty
|
||||
|
||||
expect(tags[0]).to have_key('name')
|
||||
expect(tags[0]['name']).to eq('gen:spec_tag')
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,48 @@
|
||||
require 'cgi'
|
||||
require 'rails_helper'
|
||||
|
||||
|
||||
RSpec.describe 'Tags API', type: :request do
|
||||
let!(:tn) { TagName.create!(name: 'spec_tag') }
|
||||
let!(:tag) { Tag.create!(tag_name: tn, category: 'general') }
|
||||
|
||||
describe 'GET /tags' do
|
||||
it 'returns tags with name' do
|
||||
get '/tags'
|
||||
|
||||
expect(response).to have_http_status(:ok)
|
||||
json = JSON.parse(response.body)
|
||||
|
||||
expect(json).to be_a(Array)
|
||||
expect(json).not_to be_empty
|
||||
expect(json[0]).to have_key('name')
|
||||
expect(json.map { |t| t['name'] }).to include('spec_tag')
|
||||
end
|
||||
end
|
||||
|
||||
describe 'GET /tags/autocomplete' do
|
||||
it 'returns matching tags by q' do
|
||||
get '/tags/autocomplete', params: { q: 'spec' }
|
||||
|
||||
expect(response).to have_http_status(:ok)
|
||||
json = JSON.parse(response.body)
|
||||
|
||||
expect(json).to be_a(Array)
|
||||
expect(json.map { |t| t['name'] }).to include('spec_tag')
|
||||
end
|
||||
end
|
||||
|
||||
describe 'GET /tags/name/:name' do
|
||||
it 'returns tag by name' do
|
||||
get "/tags/name/#{ CGI.escape('spec_tag') }"
|
||||
|
||||
expect(response).to have_http_status(:ok)
|
||||
json = JSON.parse(response.body)
|
||||
|
||||
expect(json).to have_key('id')
|
||||
expect(json).to have_key('name')
|
||||
expect(json['id']).to eq(tag.id)
|
||||
expect(json['name']).to eq('spec_tag')
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,42 @@
|
||||
require 'cgi'
|
||||
require 'rails_helper'
|
||||
require 'securerandom'
|
||||
|
||||
|
||||
RSpec.describe 'Wiki API', type: :request do
|
||||
let!(:user) { create_user_for_wiki! }
|
||||
|
||||
let!(:tn) { TagName.create!(name: 'spec_wiki_title') }
|
||||
let!(:page) do
|
||||
WikiPage.create!(tag_name: tn, created_user: user, updated_user: user)
|
||||
end
|
||||
|
||||
describe 'GET /wiki' do
|
||||
it 'returns wiki pages with title' do
|
||||
get '/wiki'
|
||||
|
||||
expect(response).to have_http_status(:ok)
|
||||
json = JSON.parse(response.body)
|
||||
|
||||
expect(json).to be_a(Array)
|
||||
expect(json).not_to be_empty
|
||||
|
||||
expect(json[0]).to have_key('title')
|
||||
expect(json.map { |p| p['title'] }).to include('spec_wiki_title')
|
||||
end
|
||||
end
|
||||
|
||||
describe 'GET /wiki/title/:title' do
|
||||
it 'returns wiki page by title' do
|
||||
get "/wiki/title/#{CGI.escape('spec_wiki_title')}"
|
||||
|
||||
expect(response).to have_http_status(:ok)
|
||||
json = JSON.parse(response.body)
|
||||
|
||||
expect(json).to have_key('id')
|
||||
expect(json).to have_key('title')
|
||||
expect(json['id']).to eq(page.id)
|
||||
expect(json['title']).to eq('spec_wiki_title')
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user