diff --git a/CHANGELOG.md b/CHANGELOG.md index 4ceeb08..ee99c34 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] - No unreleased changes! +## [0.2.10] +### Changed +- Update API handler to accept zero padded day numbers ([#34](https://github.com/pacso/aoc_rb/pull/34) by [@YozuChris](https://github.com/YozuChris)) + ## [0.2.9] ### Changed - Added missing require to `lib/aoc_rb/app.rb` ([#33](https://github.com/pacso/aoc_rb/pull/33) by [@pacso](https://github.com/pacso)) @@ -74,7 +78,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 Initial release. -[Unreleased]: https://github.com/pacso/aoc_rb/compare/v0.2.9...HEAD +[Unreleased]: https://github.com/pacso/aoc_rb/compare/v0.2.10...HEAD +[0.2.10]: https://github.com/pacso/aoc_rb/compare/v0.2.9...v0.2.10 [0.2.9]: https://github.com/pacso/aoc_rb/compare/v0.2.8...v0.2.9 [0.2.8]: https://github.com/pacso/aoc_rb/compare/v0.2.7...v0.2.8 [0.2.7]: https://github.com/pacso/aoc_rb/compare/v0.2.6...v0.2.7 diff --git a/lib/aoc_rb/aoc_api.rb b/lib/aoc_rb/aoc_api.rb index 91c364f..ff2cab5 100644 --- a/lib/aoc_rb/aoc_api.rb +++ b/lib/aoc_rb/aoc_api.rb @@ -24,7 +24,7 @@ def submit_answer(year, day, level, answer) private def puzzle_path(year, day) - "/#{year}/day/#{day}" + "/#{year}/day/#{day.to_i}" end def input_path(year, day) diff --git a/lib/aoc_rb/version.rb b/lib/aoc_rb/version.rb index 957a635..b88e764 100644 --- a/lib/aoc_rb/version.rb +++ b/lib/aoc_rb/version.rb @@ -1,3 +1,3 @@ module AocRb - VERSION = "0.2.9" + VERSION = "0.2.10" end diff --git a/spec/lib/aoc_rb/api_spec.rb b/spec/lib/aoc_rb/api_spec.rb new file mode 100644 index 0000000..ede56f9 --- /dev/null +++ b/spec/lib/aoc_rb/api_spec.rb @@ -0,0 +1,69 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe AocRb::AocApi do + let(:session_token) { "test_session_token" } + let(:year) { 2024 } + let(:level) { 1 } + let(:answer) { "42" } + let(:api) { described_class.new(session_token) } + + shared_examples "consistent day path" do |day_input, expected_day| + let(:expected_headers) { { 'Cookie' => "session=#{session_token}" } } + + describe "#puzzle_instructions" do + let(:expected_path) { "/2024/day/#{expected_day}" } + + before do + allow(api.class).to receive(:get).and_return(double('Response', body: '')) + end + + it "sends the request to the correct uri" do + api.puzzle_instructions(year, day_input) + expect(api.class).to have_received(:get).with(expected_path, hash_including(headers: expected_headers)) + end + end + + describe "#puzzle_input" do + let(:expected_path) { "/2024/day/#{expected_day}/input" } + + before do + allow(api.class).to receive(:get).and_return(double('Response', body: '')) + end + + it "sends the request to the correct uri" do + api.puzzle_input(year, day_input) + expect(api.class).to have_received(:get).with(expected_path, hash_including(headers: expected_headers)) + end + end + + describe "#submit_answer" do + let(:expected_path) { "/2024/day/#{expected_day}/answer" } + let(:expected_body) { { level: level.to_s, answer: answer.to_s } } + + before do + allow(api.class).to receive(:post).and_return(double('Response', body: '')) + end + + it "sends the request to the correct uri" do + api.submit_answer(year, day_input, level, answer) + expect(api.class).to have_received(:post).with(expected_path, hash_including(headers: expected_headers, body: expected_body)) + end + end + end + + context "when day is an integer" do + include_examples "consistent day path", 1, 1 + include_examples "consistent day path", 17, 17 + end + + context "when day is a two-character string" do + include_examples "consistent day path", "01", 1 + include_examples "consistent day path", "22", 22 + end + + context "when day is a single character string" do + include_examples "consistent day path", "8", 8 + end +end diff --git a/spec/lib/aoc_rb_spec.rb b/spec/lib/aoc_rb_spec.rb index 813d093..aeb21fb 100644 --- a/spec/lib/aoc_rb_spec.rb +++ b/spec/lib/aoc_rb_spec.rb @@ -4,6 +4,6 @@ RSpec.describe AocRb do it "has the expected version number" do - expect(AocRb::VERSION).to eq "0.2.9" + expect(AocRb::VERSION).to eq "0.2.10" end end