Skip to content

Commit

Permalink
add vcr cassettes
Browse files Browse the repository at this point in the history
  • Loading branch information
GrantBirki committed Nov 4, 2024
1 parent 66448bc commit e8998dc
Show file tree
Hide file tree
Showing 25 changed files with 2,119 additions and 0 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ group :development do
gem "simplecov", "~> 0.22"
gem "simplecov-erb", "~> 1.0"
gem "vcr", "~> 6.3", ">= 6.3.1"
gem "webmock", "~> 3.24"
end
13 changes: 13 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ PATH
remote: .
specs:
issue-db (0.0.1)
faraday-retry (~> 2.2, >= 2.2.1)
octokit (~> 9.2)
redacting-logger (~> 1.4)
retryable (~> 3.0, >= 3.0.5)
Expand Down Expand Up @@ -29,6 +30,9 @@ GEM
bigdecimal (3.1.8)
concurrent-ruby (1.3.4)
connection_pool (2.4.1)
crack (1.0.0)
bigdecimal
rexml
diff-lcs (1.5.1)
docile (1.4.1)
drb (2.2.1)
Expand All @@ -38,6 +42,9 @@ GEM
logger
faraday-net_http (3.3.0)
net-http
faraday-retry (2.2.1)
faraday (~> 2.0)
hashdiff (1.1.1)
i18n (1.14.6)
concurrent-ruby (~> 1.0)
io-console (0.7.2)
Expand Down Expand Up @@ -71,6 +78,7 @@ GEM
reline (0.5.10)
io-console (~> 0.5)
retryable (3.0.5)
rexml (3.3.9)
rspec (3.13.0)
rspec-core (~> 3.13.0)
rspec-expectations (~> 3.13.0)
Expand Down Expand Up @@ -130,6 +138,10 @@ GEM
uri (0.13.1)
vcr (6.3.1)
base64
webmock (3.24.0)
addressable (>= 2.8.0)
crack (>= 0.3.2)
hashdiff (>= 0.4.0, < 2.0.0)

PLATFORMS
arm64-darwin-24
Expand All @@ -146,6 +158,7 @@ DEPENDENCIES
simplecov (~> 0.22)
simplecov-erb (~> 1.0)
vcr (~> 6.3, >= 6.3.1)
webmock (~> 3.24)

BUNDLED WITH
2.5.3
1 change: 1 addition & 0 deletions issue-db.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Gem::Specification.new do |spec|
spec.add_dependency "redacting-logger", "~> 1.4"
spec.add_dependency "retryable", "~> 3.0", ">= 3.0.5"
spec.add_dependency "octokit", "~> 9.2"
spec.add_dependency "faraday-retry", "~> 2.2", ">= 2.2.1"

spec.required_ruby_version = Gem::Requirement.new(">= 3.0.0")

Expand Down
111 changes: 111 additions & 0 deletions spec/lib/github_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
# frozen_string_literal: true

require "spec_helper"
require "octokit"

RSpec.describe "GitHub API", :vcr do
before(:all) do
@client = Octokit::Client.new(access_token: ENV["GITHUB_TOKEN"], page_size: 100)
@client.auto_paginate = true
@repo = "monalisa/octo-awesome"
@login = "monalisa"
end

it "fetches all open issues" do
issues = @client.list_issues(@repo, state: "open")
expect(issues).not_to be_empty
end

it "fetches the client rate limit" do
rate_limit = @client.get("rate_limit")
expect(rate_limit[:resources][:core][:remaining]).to be > 0
end

it "fetches all issues including closed issues" do
issues = @client.list_issues(@repo, state: "all")
expect(issues).not_to be_empty
end

it "marks all currently open issues as closed" do
issues = @client.list_issues(@repo, state: "open")
issues.each do |issue|
@client.close_issue(@repo, issue.number)
end
closed_issues = @client.list_issues(@repo, state: "closed")
expect(closed_issues).not_to be_empty
end

it "gets a single issue by number" do
issue_number = 1
issue = @client.issue(@repo, issue_number)
expect(issue.number).to eq(issue_number)
end

it "creates a new issue" do
issue = @client.create_issue(@repo, "New issue title", "New issue body")
expect(issue.title).to eq("New issue title")
end

it "assigns an existing issue to a person" do
issue_number = 1
assignee = @login
issue = @client.update_issue(@repo, issue_number, assignees: [assignee])
expect(issue.assignees.map(&:login)).to include(assignee)
end

it "reopens an issue with a comment" do
issue_number = 1
@client.reopen_issue(@repo, issue_number)
comment = @client.add_comment(@repo, issue_number, "Reopening this issue")
expect(comment.body).to eq("Reopening this issue")
end

it "adds a comment to an already open issue" do
issue_number = 1
comment = @client.add_comment(@repo, issue_number, "Adding a comment")
expect(comment.body).to eq("Adding a comment")
end

it "uses the search API to find issues" do
query = "repo:#{@repo} author:#{@login}"
issues = @client.search_issues(query)
expect(issues.items).not_to be_empty
end

it "locks an issue" do
issue_number = 1
@client.lock_issue(@repo, issue_number)
issue = @client.issue(@repo, issue_number)
expect(issue.locked).to be true
end

it "unlocks an issue" do
issue_number = 1
@client.unlock_issue(@repo, issue_number)
issue = @client.issue(@repo, issue_number)
expect(issue.locked).to be false
end

it "lists comments on an issue" do
issue_number = 1
comments = @client.issue_comments(@repo, issue_number)
expect(comments).not_to be_empty
end

it "edits an issue" do
issue_number = 1
updated_title = "Updated issue title"
updated_body = "Updated issue body"
issue = @client.update_issue(@repo, issue_number, title: updated_title, body: updated_body)
expect(issue.title).to eq(updated_title)
expect(issue.body).to eq(updated_body)
end

it "deletes a comment" do
issue_number = 1
comment = @client.add_comment(@repo, issue_number, "This comment will be deleted")
@client.delete_comment(@repo, comment.id)
comments = @client.issue_comments(@repo, issue_number)
expect(comments.map(&:id)).not_to include(comment.id)
end
end
10 changes: 10 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,13 @@
add_filter "spec/"
add_filter "vendor/gems/"
end

require "vcr"
require "webmock/rspec"

VCR.configure do |config|
config.cassette_library_dir = "spec/vcr_cassettes"
config.hook_into :webmock
config.configure_rspec_metadata!
config.filter_sensitive_data("<GITHUB_TOKEN>") { ENV["GITHUB_TOKEN"] }
end

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit e8998dc

Please sign in to comment.