Changes to use V1 API version instead of V0

This commit is contained in:
Frank Rousseau 2017-11-19 18:09:10 +01:00
parent ec18844e8f
commit f6b57384e7
13 changed files with 87 additions and 66 deletions

View file

@ -1,7 +1,7 @@
# frozen_string_literal: true # frozen_string_literal: true
module Api module Api
module V0 module V1
class BaseController < ApplicationController class BaseController < ApplicationController
include Api::OpenidConnect::ProtectedResourceEndpoint include Api::OpenidConnect::ProtectedResourceEndpoint

View file

@ -1,8 +1,8 @@
# frozen_string_literal: true # frozen_string_literal: true
module Api module Api
module V0 module V1
class CommentsController < Api::V0::BaseController class CommentsController < Api::V1::BaseController
before_action only: %i[create destroy] do before_action only: %i[create destroy] do
require_access_token %w[read write] require_access_token %w[read write]
end end

View file

@ -1,8 +1,8 @@
# frozen_string_literal: true # frozen_string_literal: true
module Api module Api
module V0 module V1
class ConversationsController < Api::V0::BaseController class ConversationsController < Api::V1::BaseController
include ConversationsHelper include ConversationsHelper
before_action only: %i[create index show] do before_action only: %i[create index show] do

View file

@ -1,8 +1,8 @@
# frozen_string_literal: true # frozen_string_literal: true
module Api module Api
module V0 module V1
class LikesController < Api::V0::BaseController class LikesController < Api::V1::BaseController
before_action only: %i[create destroy] do before_action only: %i[create destroy] do
require_access_token %w[read write] require_access_token %w[read write]
end end

View file

@ -1,8 +1,8 @@
# frozen_string_literal: true # frozen_string_literal: true
module Api module Api
module V0 module V1
class MessagesController < Api::V0::BaseController class MessagesController < Api::V1::BaseController
before_action only: %i[create] do before_action only: %i[create] do
require_access_token %w[read write] require_access_token %w[read write]
end end

View file

@ -1,8 +1,8 @@
# frozen_string_literal: true # frozen_string_literal: true
module Api module Api
module V0 module V1
class PostsController < Api::V0::BaseController class PostsController < Api::V1::BaseController
include PostsHelper include PostsHelper
before_action only: :show do before_action only: :show do

View file

@ -1,8 +1,8 @@
# frozen_string_literal: true # frozen_string_literal: true
module Api module Api
module V0 module V1
class StreamsController < Api::V0::BaseController class StreamsController < Api::V1::BaseController
before_action do before_action do
require_access_token %w[read] require_access_token %w[read]
end end

View file

@ -2,7 +2,7 @@
require "spec_helper" require "spec_helper"
describe Api::V0::CommentsController do describe Api::V1::CommentsController do
let(:auth) { FactoryGirl.create(:auth_with_read_and_write) } let(:auth) { FactoryGirl.create(:auth_with_read_and_write) }
let!(:access_token) { auth.create_access_token.to_s } let!(:access_token) { auth.create_access_token.to_s }
@ -20,7 +20,7 @@ describe Api::V0::CommentsController do
context "valid post ID" do context "valid post ID" do
it "succeeds" do it "succeeds" do
post( 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} params: {text: "This is a comment", access_token: access_token}
) )
expect(JSON.parse(response.body)["text"]).to eq("This is a comment") 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 context "comment too long" do
before do before do
post( post(
api_v0_post_comments_path(post_id: @status.id), api_v1_post_comments_path(post_id: @status.id),
params: { params: {
text: "This is a long comment" * 99_999, text: "This is a long comment" * 99_999,
access_token: access_token access_token: access_token
@ -48,7 +48,7 @@ describe Api::V0::CommentsController do
context "valid comment ID" do context "valid comment ID" do
before do before do
post( 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} params: {text: "This is a comment", access_token: access_token}
) )
end end
@ -56,7 +56,7 @@ describe Api::V0::CommentsController do
it "succeeds" do it "succeeds" do
first_comment_id = JSON.parse(response.body)["id"] first_comment_id = JSON.parse(response.body)["id"]
delete( delete(
api_v0_post_comment_path(id: first_comment_id), api_v1_post_comment_path(id: first_comment_id),
params: {access_token: access_token} params: {access_token: access_token}
) )
expect(response).to be_success expect(response).to be_success
@ -66,14 +66,14 @@ describe Api::V0::CommentsController do
context "invalid comment ID" do context "invalid comment ID" do
before do before do
post( 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} params: {text: "This is a comment", access_token: access_token}
) )
end end
it "fails to delete" do it "fails to delete" do
delete( delete(
api_v0_post_comment_path(id: 1_234_567), api_v1_post_comment_path(id: 1_234_567),
params: {access_token: access_token} params: {access_token: access_token}
) )
expect(response.body).to eq("Post or comment not found") expect(response.body).to eq("Post or comment not found")

View file

@ -2,7 +2,7 @@
require "spec_helper" require "spec_helper"
describe Api::V0::ConversationsController do describe Api::V1::ConversationsController do
let(:auth) { FactoryGirl.create(:auth_with_read_and_write) } let(:auth) { FactoryGirl.create(:auth_with_read_and_write) }
let!(:access_token) { auth.create_access_token.to_s } let!(:access_token) { auth.create_access_token.to_s }
let(:auth_participant) { FactoryGirl.create(:auth_with_read_and_write) } let(:auth_participant) { FactoryGirl.create(:auth_with_read_and_write) }
@ -25,7 +25,7 @@ describe Api::V0::ConversationsController do
describe "#create" do describe "#create" do
context "with valid data" do context "with valid data" do
it "creates the conversation" 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_guid = JSON.parse(response.body)["conversation"]["guid"]
conversation = JSON.parse(response.body)["conversation"] conversation = JSON.parse(response.body)["conversation"]
@ -40,7 +40,7 @@ describe Api::V0::ConversationsController do
context "without valid data" do context "without valid data" do
it "fails at creating the conversation" 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 expect(response.status).to eq 400
end end
end end
@ -48,10 +48,10 @@ describe Api::V0::ConversationsController do
describe "#index" do describe "#index" do
before do before do
post api_v0_conversations_path, params: @conversation post api_v1_conversations_path, params: @conversation
post api_v0_conversations_path, params: @conversation post api_v1_conversations_path, params: @conversation
sleep(1) 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_guid = JSON.parse(response.body)["conversation"]["guid"]
conversation = conversation_service.find!(conversation_guid) conversation = conversation_service.find!(conversation_guid)
conversation.conversation_visibilities[0].unread = 1 conversation.conversation_visibilities[0].unread = 1
@ -62,14 +62,14 @@ describe Api::V0::ConversationsController do
end end
it "returns all the user conversations" do 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(response.status).to eq 200
expect(JSON.parse(response.body).length).to eq 3 expect(JSON.parse(response.body).length).to eq 3
end end
it "returns all the user unread conversations" do it "returns all the user unread conversations" do
get( get(
api_v0_conversations_path, api_v1_conversations_path,
params: {unread: true, access_token: access_token} params: {unread: true, access_token: access_token}
) )
expect(response.status).to eq 200 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 it "returns all the user conversations after a given date" do
get( get(
api_v0_conversations_path, api_v1_conversations_path,
params: {only_after: @date, access_token: access_token} params: {only_after: @date, access_token: access_token}
) )
expect(response.status).to eq 200 expect(response.status).to eq 200
@ -89,13 +89,13 @@ describe Api::V0::ConversationsController do
describe "#show" do describe "#show" do
context "valid conversation ID" do context "valid conversation ID" do
before do before do
post api_v0_conversations_path, params: @conversation post api_v1_conversations_path, params: @conversation
end end
it "returns the corresponding conversation" do it "returns the corresponding conversation" do
conversation_guid = JSON.parse(response.body)["conversation"]["guid"] conversation_guid = JSON.parse(response.body)["conversation"]["guid"]
get( get(
api_v0_conversation_path(conversation_guid), api_v1_conversation_path(conversation_guid),
params: {access_token: access_token} params: {access_token: access_token}
) )
expect(response.status).to eq 200 expect(response.status).to eq 200
@ -110,7 +110,7 @@ describe Api::V0::ConversationsController do
context "non existing conversation ID" do context "non existing conversation ID" do
it "returns a not found error (404)" do it "returns a not found error (404)" do
get( get(
api_v0_conversation_path(42), api_v1_conversation_path(42),
params: {access_token: access_token} params: {access_token: access_token}
) )
expect(response.status).to eq 404 expect(response.status).to eq 404
@ -133,23 +133,23 @@ describe Api::V0::ConversationsController do
recipients: [auth_participant.user.person.id], recipients: [auth_participant.user.person.id],
access_token: access_token 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"] @conversation_guid = JSON.parse(response.body)["conversation"]["guid"]
end end
context "destroy" do context "destroy" do
it "destroys the first participant visibility" do it "destroys the first participant visibility" do
delete( delete(
api_v0_conversation_path(@conversation_guid), api_v1_conversation_path(@conversation_guid),
params: {access_token: access_token} params: {access_token: access_token}
) )
expect(response.status).to eq 204 expect(response.status).to eq 204
get api_v0_conversation_path( get api_v1_conversation_path(
@conversation_guid, @conversation_guid,
params: {access_token: access_token} params: {access_token: access_token}
) )
expect(response.status).to eq 404 expect(response.status).to eq 404
get api_v0_conversation_path( get api_v1_conversation_path(
@conversation_guid, @conversation_guid,
params: {access_token: access_token_participant} params: {access_token: access_token_participant}
) )
@ -160,16 +160,16 @@ describe Api::V0::ConversationsController do
context "destroy all visibilities" do context "destroy all visibilities" do
it "destroys the second participant visibilty and the conversation" do it "destroys the second participant visibilty and the conversation" do
delete( delete(
api_v0_conversation_path(@conversation_guid), api_v1_conversation_path(@conversation_guid),
params: {access_token: access_token} params: {access_token: access_token}
) )
delete( delete(
api_v0_conversation_path(@conversation_guid), api_v1_conversation_path(@conversation_guid),
params: {access_token: access_token_participant} params: {access_token: access_token_participant}
) )
expect(response.status).to eq 204 expect(response.status).to eq 204
get api_v0_conversation_path( get api_v1_conversation_path(
@conversation_guid, @conversation_guid,
params: {access_token: access_token_participant} params: {access_token: access_token_participant}
) )
@ -184,7 +184,7 @@ describe Api::V0::ConversationsController do
context "non existing conversation ID" do context "non existing conversation ID" do
it "returns a not found error (404)" do it "returns a not found error (404)" do
delete( delete(
api_v0_conversation_path(42), api_v1_conversation_path(42),
params: {access_token: access_token} params: {access_token: access_token}
) )
expect(response.status).to eq 404 expect(response.status).to eq 404

View file

@ -1,19 +1,40 @@
# frozen_string_literal: true # frozen_sTring_literal: true
require "spec_helper" require "spec_helper"
describe Api::V0::LikesController do describe Api::V1::LikesController do
let(:auth) { FactoryGirl.create(:auth_with_read_and_write) } let(:auth) { FactoryGirl.create(:auth_with_read_and_write) }
let!(:access_token) { auth.create_access_token.to_s } let!(:access_token) { auth.create_access_token.to_s }
before do 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 end
describe "#create" do describe "#create" do
it "returns the expected author" do it "returns the expected author" do
post( post(
api_v0_post_likes_path(post_id: @status.id), api_v1_post_likes_path(post_id: @status.id),
params: {access_token: access_token} params: {access_token: access_token}
) )
json = JSON.parse(response.body) json = JSON.parse(response.body)
@ -29,7 +50,7 @@ describe Api::V0::LikesController do
describe "#delete" do describe "#delete" do
before do before do
post( post(
api_v0_post_likes_path(post_id: @status.id), api_v1_post_likes_path(post_id: @status.id),
params: {access_token: access_token} params: {access_token: access_token}
) )
@like_id = JSON.parse(response.body)["id"] @like_id = JSON.parse(response.body)["id"]
@ -37,7 +58,7 @@ describe Api::V0::LikesController do
it "succeeds" do it "succeeds" do
delete( 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} params: {access_token: access_token}
) )
expect(response).to be_success expect(response).to be_success
@ -45,7 +66,7 @@ describe Api::V0::LikesController do
it "fails on random like id" do it "fails on random like id" do
delete( 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} params: {access_token: access_token}
) )
expect(response.body).to eq("Post or like not found") expect(response.body).to eq("Post or like not found")

View file

@ -2,7 +2,7 @@
require "spec_helper" require "spec_helper"
describe Api::V0::MessagesController do describe Api::V1::MessagesController do
let(:auth) { FactoryGirl.create(:auth_with_read_and_write) } let(:auth) { FactoryGirl.create(:auth_with_read_and_write) }
let!(:access_token) { auth.create_access_token.to_s } let!(:access_token) { auth.create_access_token.to_s }
@ -27,14 +27,14 @@ describe Api::V0::MessagesController do
describe "#create " do describe "#create " do
before 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"] @conversation_guid = JSON.parse(response.body)["conversation"]["guid"]
end end
context "with valid data" do context "with valid data" do
it "creates the message in the conversation scope" do it "creates the message in the conversation scope" do
post( post(
api_v0_conversation_messages_path(@conversation_guid), api_v1_conversation_messages_path(@conversation_guid),
params: {body: @message, access_token: access_token} params: {body: @message, access_token: access_token}
) )
expect(response.status).to eq 201 expect(response.status).to eq 201
@ -46,7 +46,7 @@ describe Api::V0::MessagesController do
expect(message["body"]).to_not be_nil expect(message["body"]).to_not be_nil
get( get(
api_v0_conversation_messages_path(@conversation_guid), api_v1_conversation_messages_path(@conversation_guid),
params: {access_token: access_token} params: {access_token: access_token}
) )
messages = JSON.parse(response.body) messages = JSON.parse(response.body)
@ -59,7 +59,7 @@ describe Api::V0::MessagesController do
context "without valid data" do context "without valid data" do
it "returns a wrong parameter error (400)" do it "returns a wrong parameter error (400)" do
post( post(
api_v0_conversation_messages_path(@conversation_guid), api_v1_conversation_messages_path(@conversation_guid),
params: {access_token: access_token} params: {access_token: access_token}
) )
expect(response.status).to eq 400 expect(response.status).to eq 400
@ -69,7 +69,7 @@ describe Api::V0::MessagesController do
context "with wrong conversation id" do context "with wrong conversation id" do
it "returns a a not found error (404)" do it "returns a a not found error (404)" do
post( post(
api_v0_conversation_messages_path(42), api_v1_conversation_messages_path(42),
params: {access_token: access_token} params: {access_token: access_token}
) )
expect(response.status).to eq 404 expect(response.status).to eq 404
@ -79,14 +79,14 @@ describe Api::V0::MessagesController do
describe "#index " do describe "#index " do
before 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"] @conversation_guid = JSON.parse(response.body)["conversation"]["guid"]
end end
context "retrieving messages" do context "retrieving messages" do
it "returns all messages related to conversation" do it "returns all messages related to conversation" do
get( get(
api_v0_conversation_messages_path(@conversation_guid), api_v1_conversation_messages_path(@conversation_guid),
params: {access_token: access_token} params: {access_token: access_token}
) )
messages = JSON.parse(response.body) messages = JSON.parse(response.body)

View file

@ -2,7 +2,7 @@
require "spec_helper" require "spec_helper"
describe Api::V0::PostsController do describe Api::V1::PostsController do
let!(:auth_with_read) { FactoryGirl.create(:auth_with_read) } let!(:auth_with_read) { FactoryGirl.create(:auth_with_read) }
let!(:access_token_with_read) { auth_with_read.create_access_token.to_s } 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) } 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) expect(post_service_double).to receive(:mark_user_notifications)
@status = auth_with_read.user.post(:status_message, text: "hello", public: true, to: "all") @status = auth_with_read.user.post(:status_message, text: "hello", public: true, to: "all")
get( get(
api_v0_post_path(@status.id), api_v1_post_path(@status.id),
params: {access_token: access_token_with_read} params: {access_token: access_token_with_read}
) )
end end
@ -33,7 +33,7 @@ describe Api::V0::PostsController do
it "shows attempts to show the info" do it "shows attempts to show the info" do
@status = auth_with_read.user.post(:status_message, text: "hello", public: true, to: "all") @status = auth_with_read.user.post(:status_message, text: "hello", public: true, to: "all")
get( get(
api_v0_post_path(@status.id), api_v1_post_path(@status.id),
params: { params: {
access_token: access_token_with_read, access_token: access_token_with_read,
mark_notifications: "false" mark_notifications: "false"
@ -47,7 +47,7 @@ describe Api::V0::PostsController do
context "when given read-write access token" do context "when given read-write access token" do
it "creates a public post" do it "creates a public post" do
post( post(
api_v0_posts_path, api_v1_posts_path,
params: { params: {
access_token: access_token_with_read_and_write, access_token: access_token_with_read_and_write,
status_message: {text: "Hello this is a public post!"}, status_message: {text: "Hello this is a public post!"},
@ -59,7 +59,7 @@ describe Api::V0::PostsController do
it "creates a private post" do it "creates a private post" do
post( post(
api_v0_posts_path, api_v1_posts_path,
params: { params: {
access_token: access_token_with_read_and_write, access_token: access_token_with_read_and_write,
status_message: {text: "Hello this is a post!"}, 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 context "when given read only access token" do
before do before do
post( post(
api_v0_posts_path, api_v1_posts_path,
params: { params: {
access_token: access_token_with_read, access_token: access_token_with_read,
status_message: {text: "Hello this is a post!"}, 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) expect(post_service_double).to receive(:retract_post)
@status = auth_with_read_and_write.user.post(:status_message, text: "hello", public: true, to: "all") @status = auth_with_read_and_write.user.post(:status_message, text: "hello", public: true, to: "all")
delete( delete(
api_v0_post_path(@status.id), api_v1_post_path(@status.id),
params: {access_token: access_token_with_read_and_write} params: {access_token: access_token_with_read_and_write}
) )
end end
@ -105,7 +105,7 @@ describe Api::V0::PostsController do
before do before do
@status = auth_with_read.user.post(:status_message, text: "hello", public: true, to: "all") @status = auth_with_read.user.post(:status_message, text: "hello", public: true, to: "all")
delete( delete(
api_v0_post_path(@status.id), api_v1_post_path(@status.id),
params: {access_token: access_token_with_read} params: {access_token: access_token_with_read}
) )
end end

View file

@ -2,7 +2,7 @@
require "spec_helper" require "spec_helper"
describe Api::V0::PostsController do describe Api::V1::PostsController do
let(:auth) { FactoryGirl.create(:auth_with_read_and_write) } let(:auth) { FactoryGirl.create(:auth_with_read_and_write) }
let!(:access_token) { auth.create_access_token.to_s } let!(:access_token) { auth.create_access_token.to_s }
@ -14,7 +14,7 @@ describe Api::V0::PostsController do
describe "#aspect" do describe "#aspect" do
it "contains expected aspect message" do it "contains expected aspect message" do
get( get(
api_v0_aspects_stream_path(a_ids: [@aspect.id]), api_v1_aspects_stream_path(a_ids: [@aspect.id]),
params: {access_token: access_token} params: {access_token: access_token}
) )
expect(response.body).to include("This is a status message") 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 it "does not save to requested aspects to session" do
get( get(
api_v0_aspects_stream_path(a_ids: [@aspect.id]), api_v1_aspects_stream_path(a_ids: [@aspect.id]),
params: {access_token: access_token} params: {access_token: access_token}
) )
expect(session[:a_ids]).to be_nil expect(session[:a_ids]).to be_nil