Skip to content

Commit

Permalink
create issues creator
Browse files Browse the repository at this point in the history
  • Loading branch information
kaiomagalhaes committed Oct 18, 2023
1 parent 0f29e0b commit df81b90
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 6 deletions.
8 changes: 8 additions & 0 deletions app/services/application_service.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# frozen_string_literal: true

# app/services/application_service.rb
class ApplicationService
def self.call(*, &)
new(*, &).call
end
end
22 changes: 22 additions & 0 deletions app/services/issues_creator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# frozen_string_literal: true

class IssuesCreator < ApplicationService
def initialize(project)
super()
@project = project
end

def call
issues = Clients::Tts::Azure::Issue.new(@project).list
issues.map do |issue|
next unless issue.user

Issue.create!(
effort: issue.effort,
user: issue.user,
state: issue.state,
closed_date: issue.closed_date
)
end
end
end
2 changes: 1 addition & 1 deletion app/views/issues/_issue.json.jbuilder
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
json.extract! issue, :id, :effort, :user_id, :state, :closed_date

json.user do |json|
json.partial! "users/user", user: issue.user
json.partial! 'users/user', user: issue.user
end
12 changes: 7 additions & 5 deletions spec/controllers/issues_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
require "rails_helper"
# frozen_string_literal: true

require 'rails_helper'

RSpec.describe IssuesController, type: :controller do
include_context "authentication"
include_context 'authentication'
render_views

describe "GET #index" do
it "returns a success response" do
issue = FactoryBot.create(:issue)
describe 'GET #index' do
it 'returns a success response' do
FactoryBot.create(:issue)
get :index
expect(response).to be_successful
end
Expand Down
32 changes: 32 additions & 0 deletions spec/services/issues_creator_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# frozen_string_literal: true

require 'rails_helper'

RSpec.describe IssuesCreator, type: :service do
let(:customer) do
FactoryBot.create(:customer, name: 'Ministry Brands', ticket_tracking_system_token: 'place-real-token-here')
end

let(:user) do
user = FactoryBot.create(:user)
FactoryBot.create(:user_service_identifier, customer:, user:,
identifier: '[email protected]')
user
end

let(:project) do
FactoryBot.create(:project, customer:,
metadata: { azure_project_name: '1ES', area_path: '1ES\\DDC UI Refresh\\2023' })
end

describe '#call' do
it 'creates a list of issues' do
VCR.use_cassette('clients#tts#azure#issue#list') do
user
expect do
IssuesCreator.call(project)
end.to change(Issue, :count).by(4)
end
end
end
end

0 comments on commit df81b90

Please sign in to comment.