Skip to content

Commit

Permalink
feat: Updating tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
JakubKopys committed Feb 11, 2021
1 parent ccdc0c2 commit bfc9089
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
12 changes: 12 additions & 0 deletions lib/click_up/tasks/service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,18 @@ def create(attributes)

Oj.load(resp.body).then { |task| Task.new(task) }
end

# @param task_id [String]
# @param attributes [Hash]
# @return [ClickUp::Tasks::Task]
def update(task_id:, attributes:)
url = "task/#{task_id}"

payload = Oj.dump(attributes, mode: :compat)
resp = @http_client.put(url, payload, { "Content-Type" => "application/json" })

Oj.load(resp.body).then { |task| Task.new(task) }
end
end
end
end
17 changes: 17 additions & 0 deletions spec/click_up/tasks/service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,21 @@
expect(result.name).to eq("created_task")
end
end

describe "#update" do
it "sends a request to update a task" do
task_params = build_task(name: "updated_task", id: "abc").to_h
response = instance_double(Faraday::Response, body: Oj.generate(task_params))
http_client = instance_double(ClickUp::Client::HttpClient, put: response)

tasks_service = described_class.new(http_client: http_client, list_id: list_id)
result = tasks_service.update(attributes: { name: "updated_task" }, task_id: "abc")

expected_body = Oj.generate({ name: "updated_task" })
expect(http_client).to have_received(:put)
.with("task/abc", expected_body, { "Content-Type" => "application/json" })
expect(result).to be_an_instance_of(ClickUp::Tasks::Task)
expect(result.name).to eq("updated_task")
end
end
end

0 comments on commit bfc9089

Please sign in to comment.