-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
212 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
module AttachmentMutation | ||
Create = GraphQL::Relay::Mutation.define do | ||
name 'CreateAttachment' | ||
description 'Creates a Attachment' | ||
|
||
input_field :sourceId, !types.ID, 'Source ID' | ||
input_field :name, types.String, 'Attachment name' | ||
input_field :url, !types.String, 'Attachment url' | ||
return_field :attachment, Types::AttachmentType, 'Returns information about the new attachment' | ||
|
||
resolve Resolvers::Attachments::Create | ||
end | ||
|
||
Destroy = GraphQL::Relay::Mutation.define do | ||
name 'DestroyAttachment' | ||
description 'Updates a Attachment' | ||
|
||
input_field :id, !types.ID, 'The Attachment ID' | ||
|
||
return_field :success, types.Boolean, 'Returns operation status' | ||
|
||
resolve Resolvers::Attachments::Destroy | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
module Resolvers | ||
module Attachments | ||
module Create | ||
class << self | ||
def call(_, input, context) | ||
new_attachment = Attachment.new( | ||
name: input[:name], | ||
url: input[:url], | ||
source_id: input[:sourceId], | ||
source_type: Video, | ||
created_by: context[:current_user] | ||
) | ||
|
||
context[:current_user].authorize!(:create, new_attachment) | ||
new_attachment.save! | ||
|
||
{ attachment: new_attachment } | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
module Resolvers | ||
module Attachments | ||
module Destroy | ||
class << self | ||
def call(_, input, context) | ||
attachment_to_delete = Attachment.find(input[:id]) | ||
context[:current_user].authorize!(:destroy, attachment_to_delete) | ||
|
||
{ success: attachment_to_delete.destroy! } | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
Types::AttachmentType = GraphQL::ObjectType.define do | ||
name 'Attachment' | ||
|
||
field :id, types.ID | ||
field :name, types.String | ||
field :url, types.String | ||
field :created_by, Types::UserType | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,11 +3,12 @@ | |
|
||
User.create!(name: 'User Admin',email: '[email protected]' , password: '123123123' , password_confirmation: '123123123', user_role: :admin, organization: organization) | ||
User.create!(name: 'User script writer',email: '[email protected]' , password: '123123123' , password_confirmation: '123123123', user_role: :script_writer, organization: organization) | ||
user = User.create!(name: 'User system admin',email: 'user_role_admin@mail.com' , password: '123123123' , password_confirmation: '123123123', user_role: :system_admin, system_role_params: [{ first_system.id => 'admin'}], organization: organization) | ||
user = User.create!(name: 'User system admin',email: 'user_role_admin2@mail.com' , password: '123123123' , password_confirmation: '123123123', user_role: :system_admin, system_role_params: [{ first_system.id => 'admin'}], organization: organization) | ||
|
||
video = Video.create(title: 'Default Video 1', system: first_system, created_by: user, url: 'https://media.w3.org/2010/05/sintel/trailer_hd.mp4') | ||
Comment.create(video: video, author: user, comment_destination: 'administrative', body: 'Comment test') | ||
Task.create(video: video, created_by: user, name: 'Improve ths video') | ||
Attachment.create(source: video, source_type: Video, created_by: user, url: '/fake/url') | ||
|
||
organization = Organization.create!(name: 'Tutorbox') | ||
User.create!(name: 'Jon',email: '[email protected]' , password: '123123123' , password_confirmation: '123123123', user_role: :admin, organization: organization) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
default_attachment: | ||
name: 'attachment' | ||
url: '/fake/url' | ||
source: default_video_1 | ||
source_type: Video | ||
created_by: user_admin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
require 'rails_helper' | ||
|
||
describe AttachmentMutation do | ||
describe AttachmentMutation::Create do | ||
it { is_expected.to have_an_input_field(:name).of_type('String!') } | ||
it { is_expected.to have_an_input_field(:url).of_type('String!') } | ||
it { is_expected.to have_an_input_field(:sourceId).of_type('ID!') } | ||
it { is_expected.to have_a_return_field(:attachment).returning(Types::AttachmentType) } | ||
end | ||
|
||
describe AttachmentMutation::Destroy do | ||
it { is_expected.to have_an_input_field(:id).of_type('ID!') } | ||
it { is_expected.to have_a_return_field(:success).returning('Boolean') } | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
require 'rails_helper' | ||
|
||
describe Resolvers::Attachments::Create do | ||
let(:current_user) { users(:user_organization_admin) } | ||
let(:video) { videos(:default_video_2) } | ||
let(:input) { | ||
{ | ||
name: 'task', | ||
url: '/fake/url', | ||
sourceId: video.id, | ||
} | ||
} | ||
subject(:result) { described_class::call(nil, input, current_user: current_user ) } | ||
|
||
describe '#call' do | ||
context 'when the attachment has been created' do | ||
let(:new_attachment) { result[:attachment] } | ||
|
||
it 'creates attachment with its rigth attributes' do | ||
expect(new_attachment).to be_persisted | ||
expect(new_attachment.name).to eql input[:name] | ||
expect(new_attachment.url).to eql input[:url] | ||
expect(new_attachment.source_id).to eql input[:sourceId] | ||
expect(new_attachment.created_by).to eql current_user | ||
end | ||
end | ||
|
||
context 'when the attachment has not been created' do | ||
let(:current_user) { users(:software_house_admin) } | ||
|
||
it 'does not create a attachment and returns error' do | ||
expect { subject }.to raise_error(Exceptions::PermissionDeniedError) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
require 'rails_helper' | ||
|
||
describe Resolvers::Attachments::Destroy do | ||
let(:current_user) { users(:user_organization_admin) } | ||
let(:target_attachment) { attachments(:default_attachment) } | ||
|
||
subject(:result) { described_class::call(nil, { id: target_attachment.id } , current_user: current_user ) } | ||
|
||
describe '#call' do | ||
context 'when the attachment has been destroyed' do | ||
|
||
it 'destroys attachment with its rigth attributes' do | ||
expect { result }.to change { Attachment.count }.by(-1) | ||
end | ||
end | ||
|
||
context 'when the attachment has not been destroyed' do | ||
let(:current_user) { users(:software_house_admin) } | ||
|
||
it 'does not destroy a user and returns error' do | ||
expect { subject }.to raise_error(Exceptions::PermissionDeniedError) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,4 +22,4 @@ | |
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters