Explicitly select fragment from API JSON schema in specs

this should make them more strict and robust at the same time
This commit is contained in:
Jonne Haß 2020-01-24 16:59:04 +01:00
parent 35bfbc9c82
commit 654b81b8f1
13 changed files with 34 additions and 34 deletions

View file

@ -46,7 +46,7 @@ describe Api::V1::AspectsController do
expect(aspect["order"]).to eq(found_aspect.order_id)
end
expect(aspects.to_json).to match_json_schema(:api_v1_schema)
expect(aspects.to_json).to match_json_schema(:api_v1_schema, fragment: "#/definitions/aspects")
end
context "without impromper credentials" do
@ -81,7 +81,7 @@ describe Api::V1::AspectsController do
expect(aspect["name"]).to eq(@aspect2.name)
expect(aspect["order"]).to eq(@aspect2.order_id)
expect(aspect.to_json).to match_json_schema(:api_v1_schema)
expect(aspect.to_json).to match_json_schema(:api_v1_schema, fragment: "#/definitions/aspect")
end
end

View file

@ -144,7 +144,7 @@ describe Api::V1::CommentsController do
confirm_comment_format(comments[0], auth.user, @comment_text1)
confirm_comment_format(comments[1], auth.user, @comment_text2)
expect(comments.to_json).to match_json_schema(:api_v1_schema)
expect(comments.to_json).to match_json_schema(:api_v1_schema, fragment: "#/definitions/comments_or_messages")
end
end

View file

@ -58,7 +58,7 @@ describe Api::V1::ContactsController do
contacts = response_body_data(response)
expect(contacts.length).to eq(@aspect1.contacts.length)
expect(contacts.to_json).to match_json_schema(:api_v1_schema)
expect(contacts.to_json).to match_json_schema(:api_v1_schema, fragment: "#/definitions/users")
end
end

View file

@ -170,7 +170,7 @@ describe Api::V1::ConversationsController do
actual_conversation = returned_conversations.select {|c| c["guid"] == @read_conversation_guid }[0]
confirm_conversation_format(actual_conversation, @read_conversation, [auth.user, alice])
expect(returned_conversations.to_json).to match_json_schema(:api_v1_schema)
expect(returned_conversations.to_json).to match_json_schema(:api_v1_schema, fragment: "#/definitions/conversations")
end
it "returns all the user unread conversations" do
@ -227,7 +227,7 @@ describe Api::V1::ConversationsController do
conversation = response_body(response)
confirm_conversation_format(conversation, @conversation, [auth.user, alice])
expect(conversation.to_json).to match_json_schema(:api_v1_schema)
expect(conversation.to_json).to match_json_schema(:api_v1_schema, fragment: "#/definitions/conversation")
end
end

View file

@ -75,7 +75,7 @@ describe Api::V1::LikesController do
confirm_like_format(likes, bob)
confirm_like_format(likes, auth.user)
expect(likes.to_json).to match_json_schema(:api_v1_schema)
expect(likes.to_json).to match_json_schema(:api_v1_schema, fragment: "#/definitions/likes")
end
end

View file

@ -131,7 +131,7 @@ describe Api::V1::MessagesController do
messages = response_body_data(response)
expect(messages.length).to eq(1)
expect(messages.to_json).to match_json_schema(:api_v1_schema)
expect(messages.to_json).to match_json_schema(:api_v1_schema, fragment: "#/definitions/comments_or_messages")
confirm_message_format(messages[0], "first message", auth.user)
conversation = get_conversation(@conversation_guid)

View file

@ -41,7 +41,7 @@ describe Api::V1::NotificationsController do
expect(notifications.length).to eq(2)
confirm_notification_format(notifications[1], @notification, "also_commented", nil)
expect(notifications.to_json).to match_json_schema(:api_v1_schema)
expect(notifications.to_json).to match_json_schema(:api_v1_schema, fragment: "#/definitions/notifications")
end
it "with proper credentials and unread only" do
@ -120,7 +120,7 @@ describe Api::V1::NotificationsController do
notification = JSON.parse(response.body)
confirm_notification_format(notification, @notification, "also_commented", @post)
expect(notification.to_json).to match_json_schema(:api_v1_schema)
expect(notification.to_json).to match_json_schema(:api_v1_schema, fragment: "#/definitions/notification")
end
end

View file

@ -78,7 +78,7 @@ describe Api::V1::PhotosController do
expect(photo.has_key?("post")).to be_falsey
confirm_photo_format(photo, @user_photo1)
expect(photo.to_json).to match_json_schema(:api_v1_schema)
expect(photo.to_json).to match_json_schema(:api_v1_schema, fragment: "#/definitions/photo")
end
it "with correct GUID user's photo used in post and access token" do
@ -152,7 +152,7 @@ describe Api::V1::PhotosController do
photos = response_body_data(response)
expect(photos.length).to eq(2)
expect(photos.to_json).to match_json_schema(:api_v1_schema)
expect(photos.to_json).to match_json_schema(:api_v1_schema, fragment: "#/definitions/photos")
end
end

View file

@ -74,7 +74,7 @@ describe Api::V1::PostsController do
post = response_body(response)
confirm_post_format(post, alice, @status, [bob, eve])
expect(post.to_json).to match_json_schema(:api_v1_schema)
expect(post.to_json).to match_json_schema(:api_v1_schema, fragment: "#/definitions/post")
end
end
@ -98,7 +98,7 @@ describe Api::V1::PostsController do
post = response_body(response)
confirm_post_format(post, alice, status_message)
expect(post.to_json).to match_json_schema(:api_v1_schema)
expect(post.to_json).to match_json_schema(:api_v1_schema, fragment: "#/definitions/post")
end
end
@ -115,7 +115,7 @@ describe Api::V1::PostsController do
post = response_body(response)
confirm_reshare_format(post, @status, alice)
expect(post.to_json).to match_json_schema(:api_v1_schema)
expect(post.to_json).to match_json_schema(:api_v1_schema, fragment: "#/definitions/post")
end
end

View file

@ -63,7 +63,7 @@ describe Api::V1::SearchController do
users = response_body_data(response)
expect(users.length).to eq(15)
expect(users.to_json).to match_json_schema(:api_v1_schema)
expect(users.to_json).to match_json_schema(:api_v1_schema, fragment: "#/definitions/users")
end
it "succeeds by name" do
@ -75,7 +75,7 @@ describe Api::V1::SearchController do
users = response_body_data(response)
expect(users.length).to eq(1)
expect(users.to_json).to match_json_schema(:api_v1_schema)
expect(users.to_json).to match_json_schema(:api_v1_schema, fragment: "#/definitions/users")
end
it "succeeds by handle" do
@ -87,7 +87,7 @@ describe Api::V1::SearchController do
users = response_body_data(response)
expect(users.length).to eq(1)
expect(users.to_json).to match_json_schema(:api_v1_schema)
expect(users.to_json).to match_json_schema(:api_v1_schema, fragment: "#/definitions/users")
end
it "doesn't return closed accounts" do
@ -184,7 +184,7 @@ describe Api::V1::SearchController do
posts = response_body_data(response)
expect(posts.length).to eq(2)
expect(posts.to_json).to match_json_schema(:api_v1_schema)
expect(posts.to_json).to match_json_schema(:api_v1_schema, fragment: "#/definitions/posts")
end
it "only returns public posts without private scope" do

View file

@ -84,7 +84,7 @@ describe Api::V1::StreamsController do
posts = response_body_data(response)
expect(posts.to_json).to match_json_schema(:api_v1_schema)
expect(posts.to_json).to match_json_schema(:api_v1_schema, fragment: "#/definitions/posts")
end
it "contains expected aspect message" do
@ -146,7 +146,7 @@ describe Api::V1::StreamsController do
posts = response_body_data(response)
expect(posts.length).to eq(3)
expect(posts.to_json).to match_json_schema(:api_v1_schema)
expect(posts.to_json).to match_json_schema(:api_v1_schema, fragment: "#/definitions/posts")
end
it "public posts only tags expected" do
@ -185,7 +185,7 @@ describe Api::V1::StreamsController do
expect(response.status).to eq(200)
posts = response_body_data(response)
expect(posts.to_json).to match_json_schema(:api_v1_schema)
expect(posts.to_json).to match_json_schema(:api_v1_schema, fragment: "#/definitions/posts")
end
it "contains activity message" do
@ -228,7 +228,7 @@ describe Api::V1::StreamsController do
expect(response.status).to eq(200)
posts = response_body_data(response)
expect(posts.to_json).to match_json_schema(:api_v1_schema)
expect(posts.to_json).to match_json_schema(:api_v1_schema, fragment: "#/definitions/posts")
end
it "contains main message" do
@ -271,7 +271,7 @@ describe Api::V1::StreamsController do
expect(response.status).to eq(200)
posts = response_body_data(response)
expect(posts.to_json).to match_json_schema(:api_v1_schema)
expect(posts.to_json).to match_json_schema(:api_v1_schema, fragment: "#/definitions/posts")
end
it "contains commented message" do
@ -312,7 +312,7 @@ describe Api::V1::StreamsController do
expect(response.status).to eq(200)
posts = response_body_data(response)
expect(posts.to_json).to match_json_schema(:api_v1_schema)
expect(posts.to_json).to match_json_schema(:api_v1_schema, fragment: "#/definitions/posts")
end
it "contains mentions message" do
@ -353,7 +353,7 @@ describe Api::V1::StreamsController do
expect(response.status).to eq(200)
posts = response_body_data(response)
expect(posts.to_json).to match_json_schema(:api_v1_schema)
expect(posts.to_json).to match_json_schema(:api_v1_schema, fragment: "#/definitions/posts")
end
it "contains liked message" do

View file

@ -104,7 +104,7 @@ describe Api::V1::TagFollowingsController do
expect(items.length).to eq(@expected_tags.length)
@expected_tags.each {|tag| expect(items.find(tag)).to be_truthy }
expect(items.to_json).to match_json_schema(:api_v1_schema)
expect(items.to_json).to match_json_schema(:api_v1_schema, fragment: "#/definitions/tags")
end
end

View file

@ -64,7 +64,7 @@ describe Api::V1::UsersController do
expect(user["guid"]).to eq(auth.user.guid)
confirm_self_data_format(user)
expect(user.to_json).to match_json_schema(:api_v1_schema)
expect(user.to_json).to match_json_schema(:api_v1_schema, fragment: "#/definitions/own_user")
end
it "fails if invalid token" do
@ -89,7 +89,7 @@ describe Api::V1::UsersController do
expect(user["guid"]).to eq(alice.person.guid)
confirm_public_profile_hash(user)
expect(user.to_json).to match_json_schema(:api_v1_schema)
expect(user.to_json).to match_json_schema(:api_v1_schema, fragment: "#/definitions/user")
end
it "succeeds with in Aspect valid user" do
@ -106,7 +106,7 @@ describe Api::V1::UsersController do
expect(user["guid"]).to eq(alice.person.guid)
confirm_public_profile_hash(user)
expect(user.to_json).to match_json_schema(:api_v1_schema)
expect(user.to_json).to match_json_schema(:api_v1_schema, fragment: "#/definitions/user")
end
it "succeeds with limited data on non-public/not shared" do
@ -133,7 +133,7 @@ describe Api::V1::UsersController do
expect(user["guid"]).to eq(eve.person.guid)
confirm_public_profile_hash(user)
expect(user.to_json).to match_json_schema(:api_v1_schema)
expect(user.to_json).to match_json_schema(:api_v1_schema, fragment: "#/definitions/user")
end
it "fails if invalid token" do
@ -327,7 +327,7 @@ describe Api::V1::UsersController do
expect(contacts.length).to eq(1)
confirm_person_format(contacts[0], alice)
expect(contacts.to_json).to match_json_schema(:api_v1_schema)
expect(contacts.to_json).to match_json_schema(:api_v1_schema, fragment: "#/definitions/users")
end
it "fails with invalid GUID" do
@ -395,7 +395,7 @@ describe Api::V1::UsersController do
expect(guids).not_to include(@private_photo1.guid)
confirm_photos(photos)
expect(photos.to_json).to match_json_schema(:api_v1_schema)
expect(photos.to_json).to match_json_schema(:api_v1_schema, fragment: "#/definitions/photos")
end
it "returns only public photos of other user without private:read scope in token" do
@ -472,7 +472,7 @@ describe Api::V1::UsersController do
post = posts.select {|p| p["guid"] == @public_post1.guid }
confirm_post_format(post[0], alice, @public_post1)
expect(posts.to_json).to match_json_schema(:api_v1_schema)
expect(posts.to_json).to match_json_schema(:api_v1_schema, fragment: "#/definitions/posts")
end
it "returns logged in user's posts" do