ruby-lokalise-api 6.0.0 → 6.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (54) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -1
  3. data/lib/ruby_lokalise_api/rest/comments.rb +5 -5
  4. data/lib/ruby_lokalise_api/rest/contributors.rb +5 -5
  5. data/lib/ruby_lokalise_api/rest/custom_translation_statuses.rb +6 -6
  6. data/lib/ruby_lokalise_api/rest/files.rb +14 -3
  7. data/lib/ruby_lokalise_api/rest/keys.rb +7 -7
  8. data/lib/ruby_lokalise_api/rest/languages.rb +6 -6
  9. data/lib/ruby_lokalise_api/rest/payment_cards.rb +3 -3
  10. data/lib/ruby_lokalise_api/rest/projects.rb +6 -6
  11. data/lib/ruby_lokalise_api/rest/queued_processes.rb +2 -2
  12. data/lib/ruby_lokalise_api/rest/screenshots.rb +5 -5
  13. data/lib/ruby_lokalise_api/rest/segments.rb +3 -3
  14. data/lib/ruby_lokalise_api/rest/snapshots.rb +4 -4
  15. data/lib/ruby_lokalise_api/rest/tasks.rb +5 -5
  16. data/lib/ruby_lokalise_api/rest/team_user_billing_details.rb +3 -3
  17. data/lib/ruby_lokalise_api/rest/team_users.rb +4 -4
  18. data/lib/ruby_lokalise_api/rest/teams.rb +1 -1
  19. data/lib/ruby_lokalise_api/rest/translation_providers.rb +2 -2
  20. data/lib/ruby_lokalise_api/rest/translations.rb +3 -3
  21. data/lib/ruby_lokalise_api/rest/webhooks.rb +5 -5
  22. data/lib/ruby_lokalise_api/version.rb +1 -1
  23. data/ruby-lokalise-api.gemspec +1 -1
  24. metadata +18 -64
  25. data/spec/lib/ruby_lokalise_api/client/branches_spec.rb +0 -140
  26. data/spec/lib/ruby_lokalise_api/client/comments_spec.rb +0 -118
  27. data/spec/lib/ruby_lokalise_api/client/contributors_spec.rb +0 -132
  28. data/spec/lib/ruby_lokalise_api/client/custom_translation_statuses_spec.rb +0 -131
  29. data/spec/lib/ruby_lokalise_api/client/files_spec.rb +0 -66
  30. data/spec/lib/ruby_lokalise_api/client/keys_spec.rb +0 -199
  31. data/spec/lib/ruby_lokalise_api/client/languages_spec.rb +0 -134
  32. data/spec/lib/ruby_lokalise_api/client/orders_spec.rb +0 -113
  33. data/spec/lib/ruby_lokalise_api/client/payment_cards_spec.rb +0 -92
  34. data/spec/lib/ruby_lokalise_api/client/projects_spec.rb +0 -150
  35. data/spec/lib/ruby_lokalise_api/client/queued_processes_spec.rb +0 -57
  36. data/spec/lib/ruby_lokalise_api/client/screenshots_spec.rb +0 -127
  37. data/spec/lib/ruby_lokalise_api/client/segments_spec.rb +0 -106
  38. data/spec/lib/ruby_lokalise_api/client/snapshots_spec.rb +0 -117
  39. data/spec/lib/ruby_lokalise_api/client/tasks_spec.rb +0 -145
  40. data/spec/lib/ruby_lokalise_api/client/team_user_billing_details_spec.rb +0 -48
  41. data/spec/lib/ruby_lokalise_api/client/team_user_groups_spec.rb +0 -278
  42. data/spec/lib/ruby_lokalise_api/client/team_users_spec.rb +0 -95
  43. data/spec/lib/ruby_lokalise_api/client/teams_spec.rb +0 -25
  44. data/spec/lib/ruby_lokalise_api/client/translation_providers_spec.rb +0 -48
  45. data/spec/lib/ruby_lokalise_api/client/translations_spec.rb +0 -118
  46. data/spec/lib/ruby_lokalise_api/client/webhooks_spec.rb +0 -126
  47. data/spec/lib/ruby_lokalise_api/connection_spec.rb +0 -68
  48. data/spec/lib/ruby_lokalise_api/custom_json_parser_spec.rb +0 -81
  49. data/spec/lib/ruby_lokalise_api/error_spec.rb +0 -41
  50. data/spec/lib/ruby_lokalise_api/oauth2/auth_spec.rb +0 -73
  51. data/spec/lib/ruby_lokalise_api_spec.rb +0 -47
  52. data/spec/spec_helper.rb +0 -22
  53. data/spec/support/test_client.rb +0 -15
  54. data/spec/support/vcr.rb +0 -15
@@ -1,118 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe RubyLokaliseApi::Client do
4
- let(:project_id) { '803826145ba90b42d5d860.46800099' }
5
- let(:translation_id) { 80_015_147 }
6
- let(:another_translation_id) { 82_070_312 }
7
-
8
- describe '#translations' do
9
- it 'returns all translations' do
10
- translations = VCR.use_cassette('translations') do
11
- test_client.translations project_id
12
- end.collection
13
-
14
- expect(translations.count).to eq(9)
15
- end
16
-
17
- it 'supports pagination' do
18
- translations = VCR.use_cassette('all_translations_pagination') do
19
- test_client.translations project_id, limit: 4, page: 2, disable_references: 0,
20
- filter_is_reviewed: 0
21
- end
22
-
23
- expect(translations.collection.count).to eq(4)
24
- expect(translations.total_results).to eq(187)
25
- expect(translations.total_pages).to eq(47)
26
- expect(translations.results_per_page).to eq(4)
27
- expect(translations.current_page).to eq(2)
28
- expect(translations.request_params[:page]).to eq(2)
29
- expect(translations.request_params[:disable_references]).to eq(0)
30
- expect(translations.request_params[:filter_is_reviewed]).to eq(0)
31
-
32
- next_page_trans = VCR.use_cassette('translations_next_page') do
33
- translations.next_page
34
- end
35
-
36
- expect(next_page_trans).to be_an_instance_of(RubyLokaliseApi::Collections::Translation)
37
- expect(next_page_trans.client).to be_an_instance_of(described_class)
38
- expect(next_page_trans.request_params[:page]).to eq(3)
39
- expect(next_page_trans.request_params[:disable_references]).to eq(0)
40
- expect(next_page_trans.total_results).to eq(187)
41
- expect(next_page_trans.current_page).to eq(3)
42
- expect(next_page_trans.next_page?).to be(true)
43
- expect(next_page_trans.prev_page?).to be(true)
44
-
45
- prev_page_trans = VCR.use_cassette('translations_prev_page') do
46
- translations.prev_page
47
- end
48
-
49
- expect(prev_page_trans).to be_an_instance_of(RubyLokaliseApi::Collections::Translation)
50
- expect(prev_page_trans.client).to be_an_instance_of(described_class)
51
- expect(prev_page_trans.request_params[:page]).to eq(1)
52
- expect(next_page_trans.request_params[:disable_references]).to eq(0)
53
- expect(prev_page_trans.total_results).to eq(187)
54
- expect(prev_page_trans.current_page).to eq(1)
55
- expect(prev_page_trans.next_page?).to be(true)
56
- expect(prev_page_trans.prev_page?).to be(false)
57
- end
58
- end
59
-
60
- specify '#translation' do
61
- translation = VCR.use_cassette('translation') do
62
- test_client.translation project_id, 304_581_218
63
- end
64
-
65
- expect(translation.translation_id).to eq(304_581_218)
66
- expect(translation.key_id).to eq(44_596_059)
67
- expect(translation.language_iso).to eq('ru')
68
- expect(translation.modified_at).to eq('2020-05-15 10:44:42 (Etc/UTC)')
69
- expect(translation.modified_at_timestamp).to eq(1_589_539_482)
70
- expect(translation.modified_by).to eq(20_181)
71
- expect(translation.modified_by_email).to eq('bodrovis@protonmail.com')
72
- expect(translation.translation).to eq('Сообщение')
73
- expect(translation.is_fuzzy).to be(false)
74
- expect(translation.is_reviewed).to be(false)
75
- expect(translation.words).to eq(1)
76
- expect(translation.custom_translation_statuses).to eq([])
77
- expect(translation.task_id).to be_nil
78
- end
79
-
80
- specify '#reload_data' do
81
- translation = VCR.use_cassette('translation') do
82
- test_client.translation project_id, 304_581_218
83
- end
84
-
85
- reloaded_translation = VCR.use_cassette('translation') do
86
- translation.reload_data
87
- end
88
-
89
- expect(reloaded_translation.translation_id).to eq(translation.translation_id)
90
- end
91
-
92
- specify '#update_translation' do
93
- translation = VCR.use_cassette('update_translation') do
94
- test_client.update_translation project_id, translation_id, translation: 'rspec trans',
95
- is_reviewed: true
96
- end
97
-
98
- expect(translation.translation_id).to eq(translation_id)
99
- expect(translation.translation).to eq('rspec trans')
100
- expect(translation.is_reviewed).to be(true)
101
- end
102
-
103
- context 'when translation chained methods are used' do
104
- it 'supports update' do
105
- translation = VCR.use_cassette('another_translation') do
106
- test_client.translation project_id, another_translation_id
107
- end
108
-
109
- updated_translation = VCR.use_cassette('update_translation_chained') do
110
- translation.update translation: 'chained updated'
111
- end
112
-
113
- expect(updated_translation.client.token).to eq(test_client.token)
114
- expect(updated_translation.translation).to eq('chained updated')
115
- expect(updated_translation.translation_id).to eq(translation.translation_id)
116
- end
117
- end
118
- end
@@ -1,126 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe RubyLokaliseApi::Client do
4
- let(:project_id) { '803826145ba90b42d5d860.46800099' }
5
- let(:webhook_id) { 'c7eb7e6e3c2fb2b26d0b64d0de083a5a71675b3d' }
6
- let(:new_webhook_id) { 'b345ccc6499920c490e8f4fe9487b1378dbf1dbf' }
7
- let(:serious_webhook_id) { '795565582e5ab15a59bb68156c7e2e9eaa1e8d1a' }
8
-
9
- describe '#webhooks' do
10
- it 'returns all webhooks' do
11
- webhooks = VCR.use_cassette('webhooks') do
12
- test_client.webhooks project_id
13
- end.collection
14
-
15
- expect(webhooks.count).to eq(3)
16
- expect(webhooks.first.url).to eq('https://serios.webhook')
17
- end
18
-
19
- it 'supports pagination' do
20
- webhooks = VCR.use_cassette('all_webhooks_pagination') do
21
- test_client.webhooks project_id, limit: 1, page: 2
22
- end
23
-
24
- expect(webhooks.collection.count).to eq(1)
25
- expect(webhooks.total_results).to eq(3)
26
- expect(webhooks.total_pages).to eq(3)
27
- expect(webhooks.results_per_page).to eq(1)
28
- expect(webhooks.current_page).to eq(2)
29
- end
30
- end
31
-
32
- specify '#webhook' do
33
- webhook = VCR.use_cassette('webhook') do
34
- test_client.webhook project_id, webhook_id
35
- end
36
-
37
- expect(webhook.webhook_id).to eq(webhook_id)
38
- expect(webhook.url).to eq('https://canihaz.hook')
39
- expect(webhook.secret).to eq('a62450cd9eeca8dfc84f3c0cf9b7a6a370267d6f')
40
- expect(webhook.events).to include('project.snapshot')
41
- expect(webhook.event_lang_map.first['event']).to eq('project.translation.updated')
42
- end
43
-
44
- specify '#reload_data' do
45
- webhook = VCR.use_cassette('webhook') do
46
- test_client.webhook project_id, webhook_id
47
- end
48
-
49
- reloaded_webhook = VCR.use_cassette('webhook') do
50
- webhook.reload_data
51
- end
52
-
53
- expect(reloaded_webhook.webhook_id).to eq(webhook.webhook_id)
54
- end
55
-
56
- specify '#create_webhook' do
57
- webhook = VCR.use_cassette('create_webhook') do
58
- test_client.create_webhook project_id,
59
- url: 'http://thatz.ahook',
60
- events: ['project.imported', 'project.exported']
61
- end
62
-
63
- expect(webhook.webhook_id).to eq(new_webhook_id)
64
- expect(webhook.url).to eq('http://thatz.ahook')
65
- expect(webhook.events).to include('project.imported', 'project.exported')
66
- end
67
-
68
- specify '#update_webhook' do
69
- webhook = VCR.use_cassette('update_webhook') do
70
- test_client.update_webhook project_id,
71
- new_webhook_id,
72
- url: 'http://ihaz.cheezburger'
73
- end
74
-
75
- expect(webhook.webhook_id).to eq(new_webhook_id)
76
- expect(webhook.url).to eq('http://ihaz.cheezburger')
77
- expect(webhook.events).to include('project.imported', 'project.exported')
78
- end
79
-
80
- specify '#destroy_webhook' do
81
- response = VCR.use_cassette('destroy_webhook') do
82
- test_client.destroy_webhook project_id,
83
- new_webhook_id
84
- end
85
-
86
- expect(response['project_id']).to eq(project_id)
87
- expect(response['webhook_deleted']).to be(true)
88
- end
89
-
90
- specify '#regenerate_webhook_secret' do
91
- response = VCR.use_cassette('regenerate_webhook_secret') do
92
- test_client.regenerate_webhook_secret project_id,
93
- serious_webhook_id
94
- end
95
-
96
- expect(response['project_id']).to eq(project_id)
97
- expect(response['secret']).not_to be_nil
98
- end
99
-
100
- context 'when webhook chained methods are used' do
101
- it 'supports regenerate_webhook_secret' do
102
- webhook = VCR.use_cassette('webhook_2') do
103
- test_client.webhook project_id, serious_webhook_id
104
- end
105
-
106
- expect(webhook.branch).to eq('master')
107
- expect(webhook.webhook_id).to eq(serious_webhook_id)
108
-
109
- response = VCR.use_cassette('regenerate_webhook_secret_2') do
110
- webhook.regenerate_secret
111
- end
112
-
113
- expect(response['project_id']).to eq(project_id)
114
- expect(response['secret']).not_to be_nil
115
- end
116
-
117
- it 'supports update and destroy' do
118
- webhook = VCR.use_cassette('webhook_2') do
119
- test_client.webhook project_id, serious_webhook_id
120
- end
121
-
122
- expect(webhook).to respond_to(:update)
123
- expect(webhook).to respond_to(:destroy)
124
- end
125
- end
126
- end
@@ -1,68 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe RubyLokaliseApi::Connection do
4
- let(:dummy) { Class.new { include RubyLokaliseApi::Connection }.new }
5
-
6
- let(:project_id) { '803826145ba90b42d5d860.46800099' }
7
- let(:key_id) { 44_596_059 }
8
-
9
- before { RubyLokaliseApi.reset_client! }
10
-
11
- after { RubyLokaliseApi.reset_client! }
12
-
13
- it 'Authorization header must be present for OAuth2 client' do
14
- conn = dummy.connection test_oauth2_client
15
- expect(conn.headers['Authorization']).to eq(test_oauth2_client.token)
16
- expect(conn.headers['X-api-token']).to be_nil
17
- end
18
-
19
- it 'timeouts are not be set by default but the token must be present' do
20
- conn = dummy.connection test_client
21
- expect(conn.options.timeout).to be_nil
22
- expect(conn.options.open_timeout).to be_nil
23
- expect(conn.headers['X-api-token']).to eq(test_client.token)
24
- end
25
-
26
- it 'allows to customize timeouts' do
27
- custom_client = RubyLokaliseApi.client(ENV['LOKALISE_API_TOKEN'],
28
- open_timeout: 100, timeout: 500)
29
- conn = dummy.connection custom_client
30
- expect(conn.options.timeout).to eq(500)
31
- expect(conn.options.open_timeout).to eq(100)
32
- expect(conn.headers['X-api-token']).to eq(custom_client.token)
33
-
34
- custom_client.timeout = 300
35
- custom_client.open_timeout = 200
36
- another_conn = dummy.connection custom_client
37
- expect(another_conn.options.timeout).to eq(300)
38
- expect(another_conn.options.open_timeout).to eq(200)
39
- end
40
-
41
- it 'works with gzip compression' do
42
- gzip_client = RubyLokaliseApi.client(ENV['LOKALISE_API_TOKEN'])
43
- keys = VCR.use_cassette('all_keys_gzip') do
44
- gzip_client.keys project_id, limit: 30
45
- end.collection
46
-
47
- expect(keys.first.key_id).to eq(key_id)
48
- end
49
-
50
- it 'gzip compression is on by default' do
51
- custom_client = RubyLokaliseApi.client(ENV['LOKALISE_API_TOKEN'])
52
- conn = dummy.connection custom_client
53
- expect(conn.headers['X-api-token']).to eq(custom_client.token)
54
- expect(conn.builder.handlers).to include(Faraday::Gzip::Middleware)
55
- end
56
-
57
- it 'is possible to customize adapter' do
58
- conn = dummy.connection test_client
59
- expect(conn.builder.adapter).to eq(Faraday::Adapter::NetHttp)
60
-
61
- Faraday.default_adapter = :test
62
-
63
- another_conn = dummy.connection test_client
64
-
65
- expect(another_conn.builder.adapter).to eq(Faraday::Adapter::Test)
66
- expect(conn.builder.adapter).to eq(Faraday::Adapter::NetHttp)
67
- end
68
- end
@@ -1,81 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'oj'
4
-
5
- RSpec.describe RubyLokaliseApi::JsonHandler do
6
- let(:loaded_json) do
7
- {'projects' => [{'project_id' => '547879415c01a0e6e0b855.29978928',
8
- 'name' => 'demo phoenix copy',
9
- 'description' => '',
10
- 'created_at' => '2018-11-30 20:43:18 (Etc/UTC)',
11
- 'created_by' => 20_181,
12
- 'created_by_email' => 'bodrovis@protonmail.com',
13
- 'team_id' => 176_692,
14
- 'statistics' =>
15
- {'progress' => 0,
16
- 'keys' => 1,
17
- 'team' => 1,
18
- 'base_words' => 0,
19
- 'qa_issues' => 1,
20
- 'languages' =>
21
- [{'language_id' => 640, 'language_iso' => 'en', 'progress' => 0, 'words_to_do' => 0},
22
- {'language_id' => 597, 'language_iso' => 'ru', 'progress' => 0, 'words_to_do' => 0},
23
- {'language_id' => 673, 'language_iso' => 'f_over', 'progress' => 0, 'words_to_do' => 0}]}}]}
24
- end
25
-
26
- let(:dumped_json) do
27
- '{":name":"rspec proj",":description":"demo project for rspec"}'
28
- end
29
-
30
- # rubocop:disable RSpec/LeakyConstantDeclaration, Lint/ConstantDefinitionInBlock
31
- before do
32
- module RubyLokaliseApi
33
- module JsonHandler
34
- def custom_dump(obj)
35
- Oj.dump obj
36
- end
37
-
38
- def custom_load(obj)
39
- Oj.load obj
40
- end
41
- end
42
- end
43
- end
44
-
45
- after do
46
- module RubyLokaliseApi
47
- module JsonHandler
48
- def custom_dump(obj)
49
- JSON.dump obj
50
- end
51
-
52
- def custom_load(obj)
53
- JSON.parse obj
54
- end
55
- end
56
- end
57
- end
58
- # rubocop:enable RSpec/LeakyConstantDeclaration, Lint/ConstantDefinitionInBlock
59
-
60
- it 'allows to customize #load' do
61
- allow(Oj).to receive(:load).and_return(loaded_json)
62
- expect(JSON).not_to receive(:parse)
63
- projects = VCR.use_cassette('all_projects_pagination') do
64
- test_client.projects limit: 1, page: 2
65
- end
66
-
67
- expect(projects.collection.count).to eq(1)
68
- expect(projects.total_results).to eq(5)
69
- expect(projects.collection.first.name).to eq('demo phoenix copy')
70
- end
71
-
72
- it 'allows to customize #dump' do
73
- allow(Oj).to receive(:dump).and_return(dumped_json)
74
- expect(JSON).not_to receive(:dump)
75
- project = VCR.use_cassette('new_project') do
76
- test_client.create_project name: 'rspec proj', description: 'demo project for rspec'
77
- end
78
-
79
- expect(project.name).to eq('rspec proj')
80
- end
81
- end
@@ -1,41 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe RubyLokaliseApi::Error do
4
- include RubyLokaliseApi::Request
5
-
6
- before { RubyLokaliseApi.reset_client! }
7
-
8
- after { RubyLokaliseApi.reset_client! }
9
-
10
- it 'raises a generic error when the code is unknown' do
11
- expect do
12
- VCR.use_cassette('error_unknown_code') do
13
- get 'projects', RubyLokaliseApi.client('invalid')
14
- end
15
- end.to raise_error(described_class)
16
- end
17
-
18
- it 'handles an exception when the response does not contain an error key' do
19
- expect do
20
- VCR.use_cassette('error_no_error_key') do
21
- get 'projects', RubyLokaliseApi.client('invalid')
22
- end
23
- end.to raise_error(RubyLokaliseApi::Error::BadRequest)
24
- end
25
-
26
- it 'raises BadRequest when API token is invalid' do
27
- expect do
28
- VCR.use_cassette('error_invalid_token') do
29
- get 'projects', RubyLokaliseApi.client('invalid')
30
- end
31
- end.to raise_error(RubyLokaliseApi::Error::BadRequest)
32
- end
33
-
34
- it 'raises NotFound when the provided path cannot be found' do
35
- expect do
36
- VCR.use_cassette('error_not_found') do
37
- get 'invalid_path', test_client
38
- end
39
- end.to raise_error(RubyLokaliseApi::Error::NotFound)
40
- end
41
- end
@@ -1,73 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe RubyLokaliseApi::OAuth2::Auth do
4
- describe '#auth' do
5
- it 'returns auth code' do
6
- uri = auth_client.auth scope: 'read_projects'
7
- expect(uri).to include(described_class::BASE_URL.to_s)
8
- expect(uri).to include('auth?client_id=')
9
- expect(uri).to include('&scope=read_projects')
10
- end
11
-
12
- it 'allows to pass an array of scopes' do
13
- scopes = %w[write_projects write_team_groups write_tasks]
14
- uri = auth_client.auth scope: scopes
15
- expect(uri).to include(described_class::BASE_URL.to_s)
16
- expect(uri).to include('auth?client_id=')
17
- expect(uri).to include("&scope=#{scopes.join('+')}")
18
- end
19
-
20
- it 'allows to set redirect_uri' do
21
- uri = auth_client.auth scope: 'read_projects', redirect_uri: 'http://example.com/callback'
22
- expect(uri).to include(described_class::BASE_URL.to_s)
23
- expect(uri).to include('example.com%2Fcallback')
24
- end
25
-
26
- it 'allows to set state' do
27
- state = '123abc'
28
- uri = auth_client.auth scope: 'read_projects', state: state
29
- expect(uri).to include(described_class::BASE_URL.to_s)
30
- expect(uri).to include(state)
31
- end
32
- end
33
-
34
- describe '#token' do
35
- it 'returns an OAuth2 token' do
36
- resp = VCR.use_cassette('oauth2/token') do
37
- auth_client.token ENV['OAUTH2_CODE']
38
- end
39
- expect(resp['access_token']).not_to be_nil
40
- expect(resp['refresh_token']).not_to be_nil
41
- expect(resp['expires_in']).to eq(3600)
42
- expect(resp['token_type']).to eq('Bearer')
43
- end
44
-
45
- it 'raises an error when the code is invalid' do
46
- expect do
47
- VCR.use_cassette('oauth2/token_error') do
48
- auth_client.token 'incorrect_code'
49
- end
50
- end.to raise_error(RubyLokaliseApi::Error::BadRequest)
51
- end
52
- end
53
-
54
- describe '#refresh' do
55
- it 'returns a refreshed OAuth2 token' do
56
- resp = VCR.use_cassette('oauth2/refresh') do
57
- auth_client.refresh ENV['OAUTH2_REFRESH_TOKEN']
58
- end
59
- expect(resp['access_token']).not_to be_nil
60
- expect(resp['refresh_token']).to be_nil
61
- expect(resp['expires_in']).to eq(3600)
62
- expect(resp['token_type']).to eq('Bearer')
63
- end
64
-
65
- it 'raises an error when the token is invalid' do
66
- expect do
67
- VCR.use_cassette('oauth2/refresh_error') do
68
- auth_client.refresh 'incorrect_token'
69
- end
70
- end.to raise_error(RubyLokaliseApi::Error::BadRequest)
71
- end
72
- end
73
- end
@@ -1,47 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe RubyLokaliseApi do
4
- specify '.client' do
5
- expect(test_client).to be_an_instance_of(RubyLokaliseApi::Client)
6
- expect(test_client.token).to eq(ENV['LOKALISE_API_TOKEN'])
7
- expect(test_client.timeout).to be_nil
8
- expect(test_client.open_timeout).to be_nil
9
- end
10
-
11
- specify '.reset_client!' do
12
- expect(test_client).to be_an_instance_of(RubyLokaliseApi::Client)
13
- described_class.reset_client!
14
- current_client = described_class.instance_variable_get :@client
15
- expect(current_client).to be_nil
16
- end
17
-
18
- specify '.oauth2_client' do
19
- expect(test_oauth2_client).to be_an_instance_of(RubyLokaliseApi::OAuth2Client)
20
- expect(test_oauth2_client.token).to eq("Bearer #{ENV['OAUTH2_TOKEN']}")
21
- expect(test_oauth2_client.timeout).to be_nil
22
- expect(test_oauth2_client.open_timeout).to be_nil
23
- end
24
-
25
- specify '.reset_oauth2_client!' do
26
- expect(test_oauth2_client).to be_an_instance_of(RubyLokaliseApi::OAuth2Client)
27
- described_class.reset_oauth2_client!
28
- current_oauth_client = described_class.instance_variable_get :@oauth2_client
29
- expect(current_oauth_client).to be_nil
30
- end
31
-
32
- context 'with client params' do
33
- before { described_class.reset_client! }
34
-
35
- after { described_class.reset_client! }
36
-
37
- it 'is possible to customize timeout' do
38
- custom_client = described_class.client(ENV['LOKALISE_API_TOKEN'], timeout: 600)
39
- expect(custom_client.timeout).to eq(600)
40
- end
41
-
42
- it 'is possible to customize open timeout' do
43
- custom_client = described_class.client(ENV['LOKALISE_API_TOKEN'], open_timeout: 100)
44
- expect(custom_client.open_timeout).to eq(100)
45
- end
46
- end
47
- end
data/spec/spec_helper.rb DELETED
@@ -1,22 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'dotenv/load'
4
- require 'simplecov'
5
- SimpleCov.start do
6
- add_filter 'spec/'
7
- add_filter '.github/'
8
- end
9
-
10
- if ENV['CI'] == 'true'
11
- require 'codecov'
12
- SimpleCov.formatter = SimpleCov::Formatter::Codecov
13
- end
14
-
15
- require 'ruby_lokalise_api'
16
-
17
- # Support files
18
- Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].sort.each { |f| require f }
19
-
20
- RSpec.configure do |config|
21
- config.include TestClient
22
- end
@@ -1,15 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module TestClient
4
- def test_client(token = nil, params = {})
5
- RubyLokaliseApi.client(token || ENV['LOKALISE_API_TOKEN'], params)
6
- end
7
-
8
- def test_oauth2_client(token = nil, params = {})
9
- RubyLokaliseApi.oauth2_client(token || ENV['OAUTH2_TOKEN'], params)
10
- end
11
-
12
- def auth_client
13
- RubyLokaliseApi.auth_client(ENV['OAUTH2_CLIENT_ID'], ENV['OAUTH2_CLIENT_SECRET'])
14
- end
15
- end
data/spec/support/vcr.rb DELETED
@@ -1,15 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'vcr'
4
-
5
- VCR.configure do |c|
6
- c.ignore_hosts 'codeclimate.com'
7
- c.hook_into :faraday
8
- c.cassette_library_dir = File.join(File.dirname(__FILE__), '..', 'fixtures', 'vcr_cassettes')
9
- c.filter_sensitive_data('<LOKALISE_TOKEN>') { ENV.fetch('LOKALISE_API_TOKEN') }
10
- c.filter_sensitive_data('<OAUTH2_CLIENT_ID>') { ENV.fetch('OAUTH2_CLIENT_ID') }
11
- c.filter_sensitive_data('<OAUTH2_CLIENT_SECRET>') { ENV.fetch('OAUTH2_CLIENT_SECRET') }
12
- c.filter_sensitive_data('<OAUTH2_TOKEN>') { ENV.fetch('OAUTH2_TOKEN') }
13
- c.filter_sensitive_data('<OAUTH2_CODE>') { ENV.fetch('OAUTH2_CODE') }
14
- c.filter_sensitive_data('<OAUTH2_REFRESH_TOKEN>') { ENV.fetch('OAUTH2_REFRESH_TOKEN') }
15
- end