Changes to use V1 API version instead of V0
This commit is contained in:
parent
ec18844e8f
commit
f6b57384e7
13 changed files with 87 additions and 66 deletions
|
|
@ -1,7 +1,7 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module Api
|
||||
module V0
|
||||
module V1
|
||||
class BaseController < ApplicationController
|
||||
include Api::OpenidConnect::ProtectedResourceEndpoint
|
||||
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module Api
|
||||
module V0
|
||||
class CommentsController < Api::V0::BaseController
|
||||
module V1
|
||||
class CommentsController < Api::V1::BaseController
|
||||
before_action only: %i[create destroy] do
|
||||
require_access_token %w[read write]
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module Api
|
||||
module V0
|
||||
class ConversationsController < Api::V0::BaseController
|
||||
module V1
|
||||
class ConversationsController < Api::V1::BaseController
|
||||
include ConversationsHelper
|
||||
|
||||
before_action only: %i[create index show] do
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module Api
|
||||
module V0
|
||||
class LikesController < Api::V0::BaseController
|
||||
module V1
|
||||
class LikesController < Api::V1::BaseController
|
||||
before_action only: %i[create destroy] do
|
||||
require_access_token %w[read write]
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module Api
|
||||
module V0
|
||||
class MessagesController < Api::V0::BaseController
|
||||
module V1
|
||||
class MessagesController < Api::V1::BaseController
|
||||
before_action only: %i[create] do
|
||||
require_access_token %w[read write]
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module Api
|
||||
module V0
|
||||
class PostsController < Api::V0::BaseController
|
||||
module V1
|
||||
class PostsController < Api::V1::BaseController
|
||||
include PostsHelper
|
||||
|
||||
before_action only: :show do
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module Api
|
||||
module V0
|
||||
class StreamsController < Api::V0::BaseController
|
||||
module V1
|
||||
class StreamsController < Api::V1::BaseController
|
||||
before_action do
|
||||
require_access_token %w[read]
|
||||
end
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
require "spec_helper"
|
||||
|
||||
describe Api::V0::CommentsController do
|
||||
describe Api::V1::CommentsController do
|
||||
let(:auth) { FactoryGirl.create(:auth_with_read_and_write) }
|
||||
let!(:access_token) { auth.create_access_token.to_s }
|
||||
|
||||
|
|
@ -20,7 +20,7 @@ describe Api::V0::CommentsController do
|
|||
context "valid post ID" do
|
||||
it "succeeds" do
|
||||
post(
|
||||
api_v0_post_comments_path(post_id: @status.id),
|
||||
api_v1_post_comments_path(post_id: @status.id),
|
||||
params: {text: "This is a comment", access_token: access_token}
|
||||
)
|
||||
expect(JSON.parse(response.body)["text"]).to eq("This is a comment")
|
||||
|
|
@ -30,7 +30,7 @@ describe Api::V0::CommentsController do
|
|||
context "comment too long" do
|
||||
before do
|
||||
post(
|
||||
api_v0_post_comments_path(post_id: @status.id),
|
||||
api_v1_post_comments_path(post_id: @status.id),
|
||||
params: {
|
||||
text: "This is a long comment" * 99_999,
|
||||
access_token: access_token
|
||||
|
|
@ -48,7 +48,7 @@ describe Api::V0::CommentsController do
|
|||
context "valid comment ID" do
|
||||
before do
|
||||
post(
|
||||
api_v0_post_comments_path(post_id: @status.id),
|
||||
api_v1_post_comments_path(post_id: @status.id),
|
||||
params: {text: "This is a comment", access_token: access_token}
|
||||
)
|
||||
end
|
||||
|
|
@ -56,7 +56,7 @@ describe Api::V0::CommentsController do
|
|||
it "succeeds" do
|
||||
first_comment_id = JSON.parse(response.body)["id"]
|
||||
delete(
|
||||
api_v0_post_comment_path(id: first_comment_id),
|
||||
api_v1_post_comment_path(id: first_comment_id),
|
||||
params: {access_token: access_token}
|
||||
)
|
||||
expect(response).to be_success
|
||||
|
|
@ -66,14 +66,14 @@ describe Api::V0::CommentsController do
|
|||
context "invalid comment ID" do
|
||||
before do
|
||||
post(
|
||||
api_v0_post_comments_path(post_id: @status.id),
|
||||
api_v1_post_comments_path(post_id: @status.id),
|
||||
params: {text: "This is a comment", access_token: access_token}
|
||||
)
|
||||
end
|
||||
|
||||
it "fails to delete" do
|
||||
delete(
|
||||
api_v0_post_comment_path(id: 1_234_567),
|
||||
api_v1_post_comment_path(id: 1_234_567),
|
||||
params: {access_token: access_token}
|
||||
)
|
||||
expect(response.body).to eq("Post or comment not found")
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
require "spec_helper"
|
||||
|
||||
describe Api::V0::ConversationsController do
|
||||
describe Api::V1::ConversationsController do
|
||||
let(:auth) { FactoryGirl.create(:auth_with_read_and_write) }
|
||||
let!(:access_token) { auth.create_access_token.to_s }
|
||||
let(:auth_participant) { FactoryGirl.create(:auth_with_read_and_write) }
|
||||
|
|
@ -25,7 +25,7 @@ describe Api::V0::ConversationsController do
|
|||
describe "#create" do
|
||||
context "with valid data" do
|
||||
it "creates the conversation" do
|
||||
post api_v0_conversations_path, params: @conversation
|
||||
post api_v1_conversations_path, params: @conversation
|
||||
@conversation_guid = JSON.parse(response.body)["conversation"]["guid"]
|
||||
conversation = JSON.parse(response.body)["conversation"]
|
||||
|
||||
|
|
@ -40,7 +40,7 @@ describe Api::V0::ConversationsController do
|
|||
|
||||
context "without valid data" do
|
||||
it "fails at creating the conversation" do
|
||||
post api_v0_conversations_path, params: {access_token: access_token}
|
||||
post api_v1_conversations_path, params: {access_token: access_token}
|
||||
expect(response.status).to eq 400
|
||||
end
|
||||
end
|
||||
|
|
@ -48,10 +48,10 @@ describe Api::V0::ConversationsController do
|
|||
|
||||
describe "#index" do
|
||||
before do
|
||||
post api_v0_conversations_path, params: @conversation
|
||||
post api_v0_conversations_path, params: @conversation
|
||||
post api_v1_conversations_path, params: @conversation
|
||||
post api_v1_conversations_path, params: @conversation
|
||||
sleep(1)
|
||||
post api_v0_conversations_path, params: @conversation
|
||||
post api_v1_conversations_path, params: @conversation
|
||||
conversation_guid = JSON.parse(response.body)["conversation"]["guid"]
|
||||
conversation = conversation_service.find!(conversation_guid)
|
||||
conversation.conversation_visibilities[0].unread = 1
|
||||
|
|
@ -62,14 +62,14 @@ describe Api::V0::ConversationsController do
|
|||
end
|
||||
|
||||
it "returns all the user conversations" do
|
||||
get api_v0_conversations_path, params: {access_token: access_token}
|
||||
get api_v1_conversations_path, params: {access_token: access_token}
|
||||
expect(response.status).to eq 200
|
||||
expect(JSON.parse(response.body).length).to eq 3
|
||||
end
|
||||
|
||||
it "returns all the user unread conversations" do
|
||||
get(
|
||||
api_v0_conversations_path,
|
||||
api_v1_conversations_path,
|
||||
params: {unread: true, access_token: access_token}
|
||||
)
|
||||
expect(response.status).to eq 200
|
||||
|
|
@ -78,7 +78,7 @@ describe Api::V0::ConversationsController do
|
|||
|
||||
it "returns all the user conversations after a given date" do
|
||||
get(
|
||||
api_v0_conversations_path,
|
||||
api_v1_conversations_path,
|
||||
params: {only_after: @date, access_token: access_token}
|
||||
)
|
||||
expect(response.status).to eq 200
|
||||
|
|
@ -89,13 +89,13 @@ describe Api::V0::ConversationsController do
|
|||
describe "#show" do
|
||||
context "valid conversation ID" do
|
||||
before do
|
||||
post api_v0_conversations_path, params: @conversation
|
||||
post api_v1_conversations_path, params: @conversation
|
||||
end
|
||||
|
||||
it "returns the corresponding conversation" do
|
||||
conversation_guid = JSON.parse(response.body)["conversation"]["guid"]
|
||||
get(
|
||||
api_v0_conversation_path(conversation_guid),
|
||||
api_v1_conversation_path(conversation_guid),
|
||||
params: {access_token: access_token}
|
||||
)
|
||||
expect(response.status).to eq 200
|
||||
|
|
@ -110,7 +110,7 @@ describe Api::V0::ConversationsController do
|
|||
context "non existing conversation ID" do
|
||||
it "returns a not found error (404)" do
|
||||
get(
|
||||
api_v0_conversation_path(42),
|
||||
api_v1_conversation_path(42),
|
||||
params: {access_token: access_token}
|
||||
)
|
||||
expect(response.status).to eq 404
|
||||
|
|
@ -133,23 +133,23 @@ describe Api::V0::ConversationsController do
|
|||
recipients: [auth_participant.user.person.id],
|
||||
access_token: access_token
|
||||
}
|
||||
post api_v0_conversations_path, params: @conversation
|
||||
post api_v1_conversations_path, params: @conversation
|
||||
@conversation_guid = JSON.parse(response.body)["conversation"]["guid"]
|
||||
end
|
||||
|
||||
context "destroy" do
|
||||
it "destroys the first participant visibility" do
|
||||
delete(
|
||||
api_v0_conversation_path(@conversation_guid),
|
||||
api_v1_conversation_path(@conversation_guid),
|
||||
params: {access_token: access_token}
|
||||
)
|
||||
expect(response.status).to eq 204
|
||||
get api_v0_conversation_path(
|
||||
get api_v1_conversation_path(
|
||||
@conversation_guid,
|
||||
params: {access_token: access_token}
|
||||
)
|
||||
expect(response.status).to eq 404
|
||||
get api_v0_conversation_path(
|
||||
get api_v1_conversation_path(
|
||||
@conversation_guid,
|
||||
params: {access_token: access_token_participant}
|
||||
)
|
||||
|
|
@ -160,16 +160,16 @@ describe Api::V0::ConversationsController do
|
|||
context "destroy all visibilities" do
|
||||
it "destroys the second participant visibilty and the conversation" do
|
||||
delete(
|
||||
api_v0_conversation_path(@conversation_guid),
|
||||
api_v1_conversation_path(@conversation_guid),
|
||||
params: {access_token: access_token}
|
||||
)
|
||||
delete(
|
||||
api_v0_conversation_path(@conversation_guid),
|
||||
api_v1_conversation_path(@conversation_guid),
|
||||
params: {access_token: access_token_participant}
|
||||
)
|
||||
expect(response.status).to eq 204
|
||||
|
||||
get api_v0_conversation_path(
|
||||
get api_v1_conversation_path(
|
||||
@conversation_guid,
|
||||
params: {access_token: access_token_participant}
|
||||
)
|
||||
|
|
@ -184,7 +184,7 @@ describe Api::V0::ConversationsController do
|
|||
context "non existing conversation ID" do
|
||||
it "returns a not found error (404)" do
|
||||
delete(
|
||||
api_v0_conversation_path(42),
|
||||
api_v1_conversation_path(42),
|
||||
params: {access_token: access_token}
|
||||
)
|
||||
expect(response.status).to eq 404
|
||||
|
|
|
|||
|
|
@ -1,19 +1,40 @@
|
|||
# frozen_string_literal: true
|
||||
# frozen_sTring_literal: true
|
||||
|
||||
require "spec_helper"
|
||||
|
||||
describe Api::V0::LikesController do
|
||||
describe Api::V1::LikesController do
|
||||
let(:auth) { FactoryGirl.create(:auth_with_read_and_write) }
|
||||
let!(:access_token) { auth.create_access_token.to_s }
|
||||
|
||||
before do
|
||||
@status = auth.user.post(:status_message, text: "This is a status message", public: true, to: "all")
|
||||
@status = auth.user.post(
|
||||
:status_message,
|
||||
text: "This is a status message",
|
||||
public: true,
|
||||
to: "all"
|
||||
)
|
||||
end
|
||||
|
||||
describe "#show" do
|
||||
it "returns the likes for a given post" do
|
||||
get(
|
||||
api_v1_post_likes_path(post_id: @status.id),
|
||||
params: {access_token: access_token}
|
||||
)
|
||||
end
|
||||
|
||||
it "fails on random post id" do
|
||||
get(
|
||||
api_v1_post_likes_path(post_id: @status.id),
|
||||
params: {access_token: access_token}
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
describe "#create" do
|
||||
it "returns the expected author" do
|
||||
post(
|
||||
api_v0_post_likes_path(post_id: @status.id),
|
||||
api_v1_post_likes_path(post_id: @status.id),
|
||||
params: {access_token: access_token}
|
||||
)
|
||||
json = JSON.parse(response.body)
|
||||
|
|
@ -29,7 +50,7 @@ describe Api::V0::LikesController do
|
|||
describe "#delete" do
|
||||
before do
|
||||
post(
|
||||
api_v0_post_likes_path(post_id: @status.id),
|
||||
api_v1_post_likes_path(post_id: @status.id),
|
||||
params: {access_token: access_token}
|
||||
)
|
||||
@like_id = JSON.parse(response.body)["id"]
|
||||
|
|
@ -37,7 +58,7 @@ describe Api::V0::LikesController do
|
|||
|
||||
it "succeeds" do
|
||||
delete(
|
||||
api_v0_post_like_path(post_id: @status.id, id: @like_id),
|
||||
api_v1_post_like_path(post_id: @status.id, id: @like_id),
|
||||
params: {access_token: access_token}
|
||||
)
|
||||
expect(response).to be_success
|
||||
|
|
@ -45,7 +66,7 @@ describe Api::V0::LikesController do
|
|||
|
||||
it "fails on random like id" do
|
||||
delete(
|
||||
api_v0_post_like_path(post_id: @status.id, id: 99_999_999),
|
||||
api_v1_post_like_path(post_id: @status.id, id: 99_999_999),
|
||||
params: {access_token: access_token}
|
||||
)
|
||||
expect(response.body).to eq("Post or like not found")
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
require "spec_helper"
|
||||
|
||||
describe Api::V0::MessagesController do
|
||||
describe Api::V1::MessagesController do
|
||||
let(:auth) { FactoryGirl.create(:auth_with_read_and_write) }
|
||||
let!(:access_token) { auth.create_access_token.to_s }
|
||||
|
||||
|
|
@ -27,14 +27,14 @@ describe Api::V0::MessagesController do
|
|||
|
||||
describe "#create " do
|
||||
before do
|
||||
post api_v0_conversations_path, params: @conversation
|
||||
post api_v1_conversations_path, params: @conversation
|
||||
@conversation_guid = JSON.parse(response.body)["conversation"]["guid"]
|
||||
end
|
||||
|
||||
context "with valid data" do
|
||||
it "creates the message in the conversation scope" do
|
||||
post(
|
||||
api_v0_conversation_messages_path(@conversation_guid),
|
||||
api_v1_conversation_messages_path(@conversation_guid),
|
||||
params: {body: @message, access_token: access_token}
|
||||
)
|
||||
expect(response.status).to eq 201
|
||||
|
|
@ -46,7 +46,7 @@ describe Api::V0::MessagesController do
|
|||
expect(message["body"]).to_not be_nil
|
||||
|
||||
get(
|
||||
api_v0_conversation_messages_path(@conversation_guid),
|
||||
api_v1_conversation_messages_path(@conversation_guid),
|
||||
params: {access_token: access_token}
|
||||
)
|
||||
messages = JSON.parse(response.body)
|
||||
|
|
@ -59,7 +59,7 @@ describe Api::V0::MessagesController do
|
|||
context "without valid data" do
|
||||
it "returns a wrong parameter error (400)" do
|
||||
post(
|
||||
api_v0_conversation_messages_path(@conversation_guid),
|
||||
api_v1_conversation_messages_path(@conversation_guid),
|
||||
params: {access_token: access_token}
|
||||
)
|
||||
expect(response.status).to eq 400
|
||||
|
|
@ -69,7 +69,7 @@ describe Api::V0::MessagesController do
|
|||
context "with wrong conversation id" do
|
||||
it "returns a a not found error (404)" do
|
||||
post(
|
||||
api_v0_conversation_messages_path(42),
|
||||
api_v1_conversation_messages_path(42),
|
||||
params: {access_token: access_token}
|
||||
)
|
||||
expect(response.status).to eq 404
|
||||
|
|
@ -79,14 +79,14 @@ describe Api::V0::MessagesController do
|
|||
|
||||
describe "#index " do
|
||||
before do
|
||||
post api_v0_conversations_path, params: @conversation
|
||||
post api_v1_conversations_path, params: @conversation
|
||||
@conversation_guid = JSON.parse(response.body)["conversation"]["guid"]
|
||||
end
|
||||
|
||||
context "retrieving messages" do
|
||||
it "returns all messages related to conversation" do
|
||||
get(
|
||||
api_v0_conversation_messages_path(@conversation_guid),
|
||||
api_v1_conversation_messages_path(@conversation_guid),
|
||||
params: {access_token: access_token}
|
||||
)
|
||||
messages = JSON.parse(response.body)
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
require "spec_helper"
|
||||
|
||||
describe Api::V0::PostsController do
|
||||
describe Api::V1::PostsController do
|
||||
let!(:auth_with_read) { FactoryGirl.create(:auth_with_read) }
|
||||
let!(:access_token_with_read) { auth_with_read.create_access_token.to_s }
|
||||
let(:auth_with_read_and_write) { FactoryGirl.create(:auth_with_read_and_write) }
|
||||
|
|
@ -23,7 +23,7 @@ describe Api::V0::PostsController do
|
|||
expect(post_service_double).to receive(:mark_user_notifications)
|
||||
@status = auth_with_read.user.post(:status_message, text: "hello", public: true, to: "all")
|
||||
get(
|
||||
api_v0_post_path(@status.id),
|
||||
api_v1_post_path(@status.id),
|
||||
params: {access_token: access_token_with_read}
|
||||
)
|
||||
end
|
||||
|
|
@ -33,7 +33,7 @@ describe Api::V0::PostsController do
|
|||
it "shows attempts to show the info" do
|
||||
@status = auth_with_read.user.post(:status_message, text: "hello", public: true, to: "all")
|
||||
get(
|
||||
api_v0_post_path(@status.id),
|
||||
api_v1_post_path(@status.id),
|
||||
params: {
|
||||
access_token: access_token_with_read,
|
||||
mark_notifications: "false"
|
||||
|
|
@ -47,7 +47,7 @@ describe Api::V0::PostsController do
|
|||
context "when given read-write access token" do
|
||||
it "creates a public post" do
|
||||
post(
|
||||
api_v0_posts_path,
|
||||
api_v1_posts_path,
|
||||
params: {
|
||||
access_token: access_token_with_read_and_write,
|
||||
status_message: {text: "Hello this is a public post!"},
|
||||
|
|
@ -59,7 +59,7 @@ describe Api::V0::PostsController do
|
|||
|
||||
it "creates a private post" do
|
||||
post(
|
||||
api_v0_posts_path,
|
||||
api_v1_posts_path,
|
||||
params: {
|
||||
access_token: access_token_with_read_and_write,
|
||||
status_message: {text: "Hello this is a post!"},
|
||||
|
|
@ -73,7 +73,7 @@ describe Api::V0::PostsController do
|
|||
context "when given read only access token" do
|
||||
before do
|
||||
post(
|
||||
api_v0_posts_path,
|
||||
api_v1_posts_path,
|
||||
params: {
|
||||
access_token: access_token_with_read,
|
||||
status_message: {text: "Hello this is a post!"},
|
||||
|
|
@ -95,7 +95,7 @@ describe Api::V0::PostsController do
|
|||
expect(post_service_double).to receive(:retract_post)
|
||||
@status = auth_with_read_and_write.user.post(:status_message, text: "hello", public: true, to: "all")
|
||||
delete(
|
||||
api_v0_post_path(@status.id),
|
||||
api_v1_post_path(@status.id),
|
||||
params: {access_token: access_token_with_read_and_write}
|
||||
)
|
||||
end
|
||||
|
|
@ -105,7 +105,7 @@ describe Api::V0::PostsController do
|
|||
before do
|
||||
@status = auth_with_read.user.post(:status_message, text: "hello", public: true, to: "all")
|
||||
delete(
|
||||
api_v0_post_path(@status.id),
|
||||
api_v1_post_path(@status.id),
|
||||
params: {access_token: access_token_with_read}
|
||||
)
|
||||
end
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
require "spec_helper"
|
||||
|
||||
describe Api::V0::PostsController do
|
||||
describe Api::V1::PostsController do
|
||||
let(:auth) { FactoryGirl.create(:auth_with_read_and_write) }
|
||||
let!(:access_token) { auth.create_access_token.to_s }
|
||||
|
||||
|
|
@ -14,7 +14,7 @@ describe Api::V0::PostsController do
|
|||
describe "#aspect" do
|
||||
it "contains expected aspect message" do
|
||||
get(
|
||||
api_v0_aspects_stream_path(a_ids: [@aspect.id]),
|
||||
api_v1_aspects_stream_path(a_ids: [@aspect.id]),
|
||||
params: {access_token: access_token}
|
||||
)
|
||||
expect(response.body).to include("This is a status message")
|
||||
|
|
@ -22,7 +22,7 @@ describe Api::V0::PostsController do
|
|||
|
||||
it "does not save to requested aspects to session" do
|
||||
get(
|
||||
api_v0_aspects_stream_path(a_ids: [@aspect.id]),
|
||||
api_v1_aspects_stream_path(a_ids: [@aspect.id]),
|
||||
params: {access_token: access_token}
|
||||
)
|
||||
expect(session[:a_ids]).to be_nil
|
||||
|
|
|
|||
Loading…
Reference in a new issue