Skip to content

Commit

Permalink
Merge pull request bsmth#29 from tcob/test
Browse files Browse the repository at this point in the history
Tests
  • Loading branch information
Brian Thomas Smith authored Apr 15, 2018
2 parents ae4d8fb + 38da116 commit e6f437b
Show file tree
Hide file tree
Showing 11 changed files with 129 additions and 17 deletions.
10 changes: 4 additions & 6 deletions lib/orgbots.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,14 @@
require_relative 'tasks/schedule'
require_relative 'config'

Query.new.authed_ratelimit

# Run through the setup checklist before proceeding
Config.new.checklist

# GO!
# Clear the screen and show a welcome message
system 'clear'
puts Octokit.say("Sup #{Query.new.user}")
puts %(\n🤖 Welcome to GitHub Simulator!
Select how and when you would like to commit to GitHub:
)
Reporter.new.welcome

# Prompt the user to select which mode to run Orgbots in
Config.new.mode_config
1 change: 1 addition & 0 deletions lib/utils/prompts.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ def initialize

def confirm
exit unless @prompt.yes?('Ready to rock, Y/N?')
system 'clear'
end

def ask_date
Expand Down
12 changes: 12 additions & 0 deletions lib/utils/queries.rb
Original file line number Diff line number Diff line change
@@ -1,16 +1,28 @@
require 'octokit'
require 'dotenv/load'
require_relative 'utils'

Dotenv.load('orgbot.env')

# Simple Queries
class Query
def initialize
@prompt = TTY::Prompt.new
@c = Octokit::Client.new(access_token: @t)
@r = ENV['REPO']
@t = ENV['TOKEN']
end

def ratelimit(client = Octokit)
rem = client.rate_limit['remaining']
total = Util.new.seconds_to_str(client.rate_limit['resets_in'].to_i)
puts "#{rem} remaining requests, Rate Limit resets in #{total}"
end

def authed_ratelimit
ratelimit(@c)
end

def user
@c = Octokit::Client.new(access_token: @t)
@c.user[:login]
Expand Down
26 changes: 26 additions & 0 deletions lib/utils/reporter.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
require_relative 'queries'
require 'octokit'

Dotenv.load('orgbot.env')

# Simple Console Reporting or usage instructions
class Reporter
def initialize
@prompt = TTY::Prompt.new
@c = Octokit::Client.new(access_token: @t)
@r = ENV['REPO']
@t = ENV['TOKEN']
end

def welcome
puts @c.say("Sup #{Query.new.user}")
puts "\n🤖 Welcome to GitHub Simulator!"\
'Select how and when you would like to commit to GitHub:'
end

def configs
puts 'Place configs in orgbot.env in the format:'\
'OCTOKIT_TOKEN=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'\
'REPO=someuseraccount/coolrepo'
end
end
10 changes: 0 additions & 10 deletions lib/utils/reports.rb

This file was deleted.

2 changes: 1 addition & 1 deletion lib/utils/utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
require_relative 'reacter'
require_relative 'queries'
require_relative 'prompts'
require_relative 'reports'
require_relative 'reporter'
require 'octokit'

# Some basic utilities
Expand Down
4 changes: 4 additions & 0 deletions test/suite.rb
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
require_relative 'test_dotenv'
require_relative 'test_config'
require_relative 'test_utils'
require_relative 'test_reporter'
require_relative 'test_queries'
42 changes: 42 additions & 0 deletions test/test_config.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
require 'test/unit'
require_relative '../lib/config'

class TestConfig < Test::Unit::TestCase
def test_repo
conf = Config.new
assert_nothing_raised do
conf.validate_repo
end
end

def test_token
conf = Config.new
assert_nothing_raised do
conf.validate_token
end
end

# requires user input, look into IO pipe here
# to simulate gets
#
# def test_mode_select
# conf = Config.new
# assert_nothing_raised do
# conf.mode_select
# end
# end
#
# def test_mode_select
# conf = Config.new
# assert_nothing_raised do
# conf.mode_config
# end
# end
#
# def test_mode_select
# conf = Config.new
# assert_nothing_raised do
# conf.checklist
# end
# end
end
11 changes: 11 additions & 0 deletions test/test_queries.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
require 'test/unit'
require_relative '../lib/utils/queries'

class TestConfig < Test::Unit::TestCase
def test_user_login
query = Query.new
assert_nothing_raised do
query.user
end
end
end
11 changes: 11 additions & 0 deletions test/test_reporter.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
require 'test/unit'
require_relative '../lib/utils/reporter'

class TestReporter < Test::Unit::TestCase
def test_welcome
rep = Reporter.new
assert_nothing_raised do
rep.welcome
end
end
end
17 changes: 17 additions & 0 deletions test/test_utils.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
require 'test/unit'
require_relative '../lib/utils/utils'

class TestUtils < Test::Unit::TestCase
def test_ratelimit
util = Util.new
assert_nothing_raised do
util.ratelimit
end
end

def test_time_conversion
util = Util.new
expected = '50m 2s'
assert_equal(expected, util.seconds_to_str(3002))
end
end

0 comments on commit e6f437b

Please sign in to comment.