-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ticket Show API done #27
Open
shubhh139
wants to merge
3
commits into
master
Choose a base branch
from
feature/sk/show_ticket
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,31 @@ | ||
# frozen_string_literal: true | ||
|
||
module Tickets::V1 | ||
class Show | ||
def initialize(params) | ||
@ticket_id = params[:id] | ||
end | ||
|
||
def call | ||
find_ticket && response | ||
end | ||
|
||
def find_ticket | ||
@ticket = Ticket.find_by(id: @ticket_id) | ||
return true if @ticket | ||
|
||
false | ||
end | ||
|
||
def response | ||
@ticket.as_json( | ||
only: %i[id status title description ticket_number ticket_type priority created_at resolved_at], | ||
include: [{ | ||
activities: { only: %i[created_at asset_url description id] }, | ||
resolver: { only: %i[id name] } | ||
}], | ||
methods: %i[department_name category_name] | ||
) | ||
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
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 |
---|---|---|
|
@@ -10,8 +10,9 @@ | |
let!(:category) { FactoryBot.create(:category, name: "Hardware", priority: 0, department_id: department.id)} | ||
let!(:role) { FactoryBot.create(:role, name: 'super_admin')} | ||
let!(:role1) { FactoryBot.create(:role, name: 'employee')} | ||
let(:user) { FactoryBot.create(:user, role_id: role.id, department_id: department.id) } | ||
let(:user1) { FactoryBot.create(:user, role_id: role.id) } | ||
let(:user) { FactoryBot.create(:user, role_id: role.id, email: "[email protected]") } | ||
let(:user1) { FactoryBot.create(:user, role_id: role.id, email: "[email protected]") } | ||
let!(:ticket) { FactoryBot.create(:ticket, description: "For laptop with high graphics", ticket_number: "12", status: "assigned", priority: 0, department_id: department.id, category_id: category.id, ticket_type: "request", resolver_id: user.id, requester_id: user1.id) } | ||
|
||
post '/tickets' do | ||
before do | ||
|
@@ -43,6 +44,29 @@ | |
end | ||
end | ||
|
||
get '/tickets/:ticket_id'do | ||
before do | ||
header 'Accept', 'application/vnd.providesk; version=1' | ||
header 'Authorization', JsonWebToken.encode({user_id: user.id, email: user.email, name: user.name}) | ||
end | ||
context '200' do | ||
example 'Ticket show success' do | ||
do_request({ticket_id: ticket.id}) | ||
response_data = JSON.parse(response_body) | ||
expect(response_status).to eq(200) | ||
end | ||
end | ||
|
||
context '404' do | ||
example 'Unable to show ticket' do | ||
do_request({ticket_id: Faker::Number.numerify('#')}) | ||
response_data = JSON.parse(response_body) | ||
expect(response_status).to eq(422) | ||
expect(response_data["message"]).to eq(I18n.t('tickets.error.show')) | ||
end | ||
end | ||
end | ||
|
||
private | ||
|
||
def create_params(title, description, category_id, department_id, ticket_type, resolver_id) | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any issue faced in the spec for for using Faker? - we have hard coded emails for creating user - we can use the factory right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes but there is validation for using same email @varungadde99