Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update failing specs #33

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
2 changes: 1 addition & 1 deletion lib/reportsv2.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module TogglV8
TOGGL_REPORTS_URL = 'https://toggl.com/reports/api/'
TOGGL_REPORTS_URL = 'https://api.track.toggl.com/reports/api/'

class ReportsV2
include TogglV8::Connection
Expand Down
4 changes: 2 additions & 2 deletions lib/togglv8/connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def self.open(username=nil, password=API_TOKEN, url=nil, opts={})
faraday.response :logger, Logger.new('faraday.log') if opts[:log]
faraday.adapter Faraday.default_adapter
faraday.headers = { "Content-Type" => "application/json" }
faraday.basic_auth username, password
faraday.request :authorization, :basic, username, password
end
end

Expand Down Expand Up @@ -65,7 +65,7 @@ def get(resource, params={})
resp = Oj.load(full_resp.body)
return resp['data'] if resp.respond_to?(:has_key?) && resp.has_key?('data')
return resp
rescue Oj::ParseError
rescue Oj::ParseError, EncodingError
return full_resp.body
end
end
Expand Down
14 changes: 1 addition & 13 deletions lib/togglv8/togglv8.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
require_relative 'workspaces'

module TogglV8
TOGGL_API_URL = 'https://www.toggl.com/api/'
TOGGL_API_URL = 'https://api.track.toggl.com/api/'

class API
include TogglV8::Connection
Expand Down Expand Up @@ -41,15 +41,3 @@ def initialize(username=nil, password=API_TOKEN, opts={})
end
end
end












5 changes: 2 additions & 3 deletions spec/lib/reportsv2_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,10 @@
expect(env['user']['id']).to eq Testing::USER_ID
end

it 'index returns endpoints' do
it 'index returns empty string' do
reports = TogglV8::ReportsV2.new(api_token: Testing::API_TOKEN)
reports.workspace_id = @workspace_id
index = reports.index
expect(index['Welcome to reports api V2. VALID requests are:']).to_not be nil
expect(reports.index).to eq ""
end

it 'revision has not changed' do
Expand Down
25 changes: 15 additions & 10 deletions spec/lib/togglv8/time_entries_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
@time_entry.delete(key)
end

expect(retrieved_time_entry).to eq @time_entry
expect(retrieved_time_entry).to include @time_entry
end

it 'updates a time entry' do
Expand All @@ -70,8 +70,9 @@
deleted_time_entry = @toggl.delete_time_entry(@time_entry['id'])
expect(deleted_time_entry).to eq "[#{ @time_entry['id'] }]"

zombie_time_entry = @toggl.get_time_entry(@time_entry['id'])
expect(zombie_time_entry.has_key?('server_deleted_at')).to eq true
expect do
@toggl.get_time_entry(@time_entry['id'])
end.to raise_error(RuntimeError, "HTTP Status: 404")
end
end

Expand Down Expand Up @@ -110,7 +111,9 @@
end

it 'gets a time entry' do
retrieved_time_entry = @toggl.get_time_entry(@time_entry['id'])
retrieved_time_entry = normalize_entry(
@toggl.get_time_entry(@time_entry['id'])
)

['start', 'stop'].each do |key|
expect(retrieved_time_entry[key]).to eq_ts @time_entry[key]
Expand Down Expand Up @@ -140,8 +143,9 @@
deleted_time_entry = @toggl.delete_time_entry(@time_entry['id'])
expect(deleted_time_entry).to eq "[#{ @time_entry['id'] }]"

zombie_time_entry = @toggl.get_time_entry(@time_entry['id'])
expect(zombie_time_entry.has_key?('server_deleted_at')).to eq true
expect do
@toggl.get_time_entry(@time_entry['id'])
end.to raise_error(RuntimeError, "HTTP Status: 404")
end
end

Expand Down Expand Up @@ -203,12 +207,13 @@
}

# start time entry
running_time_entry = @toggl.start_time_entry(time_entry_info)
running_time_entry = normalize_entry(@toggl.start_time_entry(time_entry_info))

# get current time entry by '/current'
time_entry_current = @toggl.get_current_time_entry
time_entry_current = normalize_entry(@toggl.get_current_time_entry)

# get current time entry by id
time_entry_by_id = @toggl.get_time_entry(running_time_entry['id'])
time_entry_by_id = normalize_entry(@toggl.get_time_entry(running_time_entry['id']))

# compare two methods of getting current time entry
expect(time_entry_current).to eq time_entry_by_id
Expand Down Expand Up @@ -422,4 +427,4 @@
DateTime.parse(actual) == DateTime.parse(expected)
end
end
end
end
4 changes: 2 additions & 2 deletions spec/lib/togglv8/workspaces_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
end

it 'shows users' do
users = @toggl.users(@workspace_id)
users = @toggl.users(@workspace_id).sort_by { |user| user["email"] }
expect(users.length).to eq 2

expect(users.first['id']).to eq Testing::OTHER_USER_ID
Expand Down Expand Up @@ -42,4 +42,4 @@
expect(tasks.first['wid']).to eq @workspace_id
end
end
end
end
6 changes: 6 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ def file_is_xls(filename)
expect(header).to eq ['D0CF11E0A1B11AE1'].pack("H*")
end

def normalize_entry(entry)
entry = entry.reject { |k, _| k == "guid" }
entry['start'] = Time.parse(entry['start']).utc.iso8601
entry
end

class Testing
API_TOKEN = ENV['API_TOKEN'] || '4880adbe1bee9a241fa08070d33bd49f'
EMAIL = ENV['EMAIL'] || 'togglv8@mailinator.com'
Expand Down