quiz_api_client 4.2.1 → 4.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +0 -48
- data/Rakefile +0 -29
- data/lib/quiz_api_client/services/courses_service.rb +37 -0
- data/lib/quiz_api_client/services/quiz_clone_jobs_service.rb +11 -0
- data/lib/quiz_api_client/services/quiz_sync_job_service.rb +17 -0
- data/lib/quiz_api_client/services/quiz_sync_jobs_service.rb +16 -0
- data/lib/quiz_api_client/version.rb +1 -1
- data/lib/quiz_api_client.rb +15 -0
- data/spec/quiz_api_client_spec.rb +7 -0
- data/spec/services/courses_service_spec.rb +98 -0
- data/spec/services/quiz_clone_jobs_service_spec.rb +36 -0
- data/spec/services/quiz_sync_job_service_spec.rb +41 -0
- data/spec/services/quiz_sync_jobs_service_spec.rb +77 -0
- data/spec/spec_helper.rb +1 -25
- metadata +11 -76
- data/spec/contracts/interaction_types_service_spec.rb +0 -22
- data/spec/contracts/item_analyses_service_spec.rb +0 -59
- data/spec/contracts/items_service_spec.rb +0 -59
- data/spec/contracts/qti_imports_service_spec.rb +0 -34
- data/spec/contracts/quiz_clone_job_service_spec.rb +0 -20
- data/spec/contracts/quiz_clone_jobs_service_spec.rb +0 -21
- data/spec/contracts/quiz_entries_service_spec.rb +0 -125
- data/spec/contracts/quiz_service_spec.rb +0 -68
- data/spec/contracts/quiz_session_events_service_spec.rb +0 -30
- data/spec/contracts/quiz_session_result_service_spec.rb +0 -42
- data/spec/contracts/quiz_session_service_spec.rb +0 -56
- data/spec/contracts/quiz_sessions_service_spec.rb +0 -28
- data/spec/contracts/quizzes_service_spec.rb +0 -80
- data/spec/contracts/session_item_results_service_spec.rb +0 -60
- data/spec/contracts/session_items_service_spec.rb +0 -21
- data/spec/contracts/shared_banks_spec.rb +0 -366
- data/spec/contracts/shared_examples/http_delete_example.rb +0 -56
- data/spec/contracts/shared_examples/http_get_example.rb +0 -139
- data/spec/contracts/shared_examples/http_patch_example.rb +0 -60
- data/spec/contracts/shared_examples/http_post_example.rb +0 -60
- data/spec/contracts/shared_examples/http_put_example.rb +0 -60
- data/spec/support/pact_config.rb +0 -64
- data/spec/support/pact_helper.rb +0 -19
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 20c474d0431dbdf5c2cf34902592b90336b535e1d5d9197570fa727b5d6cbb00
|
4
|
+
data.tar.gz: c029697bd27fae184dd98e524cfe94fdc4525b3fea9fb8163ae0d06e4d8a719e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c333252cda2aac00b2704651253493fb2fc0e8a50c4a9687605b54ea8bd6fb8da1ebbbda039daa019fec9f5b726cab6b1566ced7e72e9970830950f697195577
|
7
|
+
data.tar.gz: 66c6aafb605ccc6c54fc8d7f7c3c3d3055d017984ac4dba6fb5c1be8f085abb72bdb3bf8e8b531da3a1cbc2a3db7aea3648b38e6f31644ba98bc0df4e5615c0f
|
data/README.md
CHANGED
@@ -187,51 +187,3 @@ Then, run `bundle exec rake spec` to run the tests.
|
|
187
187
|
You can also run `bundle exec rake console` for an interactive prompt that will allow you to experiment.
|
188
188
|
|
189
189
|
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
190
|
-
|
191
|
-
When you add or modify a service, be sure to add or modify contract tests!
|
192
|
-
|
193
|
-
## Contract Tests
|
194
|
-
|
195
|
-
We use [Pact](https://docs.pact.io/) for our contract testing. To generate
|
196
|
-
a Pact file, run `bin/contracts-generate`. The script will generate the Pact
|
197
|
-
file and place it in the pacts/ directory. It will also attempt to publish the
|
198
|
-
Pact file to a local Pact Broker.
|
199
|
-
|
200
|
-
### Development Workflow:
|
201
|
-
|
202
|
-
1. In the quiz_api repo, spin up the Quiz API service with `bin/dev-setup`
|
203
|
-
2. In the quiz_pact_broker repo, spin up a Pact Broker with `bin/dev-setup`
|
204
|
-
3. In the quiz_api repo, write Pact provider states in the
|
205
|
-
spec/service_consumers/api/quiz_api_client_ruby/ directory as needed
|
206
|
-
4. In this repo's spec/contracts/ directory, write or modify a contract test
|
207
|
-
5. In this repo, run `bin/contracts-generate` to generate a Pact file and
|
208
|
-
publish it to the Pact Broker
|
209
|
-
6. In the quiz_api repo, run `bin/contracts` to pull the new Pact file from
|
210
|
-
the Pact Broker and run the updated contract tests against the Quiz API service
|
211
|
-
|
212
|
-
Bonus: You can view your Pact file in the Pact Broker at http://pact-broker.docker
|
213
|
-
along with some cool goodies!
|
214
|
-
|
215
|
-
### Debugging Failures
|
216
|
-
|
217
|
-
Pact has some basic RSpec output for failed specs. It also keeps a log in
|
218
|
-
`log/pact.log` and offers general pointers for debugging.
|
219
|
-
|
220
|
-
Above all, learn the Pact [basics](https://docs.pact.io/documentation/matching.html).
|
221
|
-
|
222
|
-
### What should contract tests cover?
|
223
|
-
|
224
|
-
The aim of contract testing here is *not* to test all functional requirements
|
225
|
-
of the Quiz API service. Rather, the goal is to ensure changes to the Quiz API
|
226
|
-
service don't break its clients. We can best accomplish this with the
|
227
|
-
following contract test coverage:
|
228
|
-
|
229
|
-
- Basic happy path requests for all endpoints (POST, GET, PUT, DELETE)
|
230
|
-
- Basic error paths for all endpoints (verify the error messages and/or HTTP
|
231
|
-
response codes are accurate)
|
232
|
-
- Resource state management; for example, when a quiz attempt is submitted but
|
233
|
-
not yet graded
|
234
|
-
- Special edge case errors
|
235
|
-
|
236
|
-
Again, what *not* to test: the functional behavior of the service; for
|
237
|
-
example, a series of sequential API calls to test a full user scenario.
|
data/Rakefile
CHANGED
@@ -1,7 +1,5 @@
|
|
1
1
|
require 'bundler/gem_tasks'
|
2
|
-
require 'pact_broker/client/tasks'
|
3
2
|
require 'rspec/core/rake_task'
|
4
|
-
require_relative './spec/support/pact_config'
|
5
3
|
|
6
4
|
RSpec::Core::RakeTask.new(:spec)
|
7
5
|
|
@@ -19,30 +17,3 @@ task :console do
|
|
19
17
|
ARGV.clear
|
20
18
|
Pry.start
|
21
19
|
end
|
22
|
-
|
23
|
-
# see https://github.com/pact-foundation/pact_broker-client/blob/master/README.md
|
24
|
-
namespace :broker do
|
25
|
-
PactBroker::Client::PublicationTask.new(:local) do |task|
|
26
|
-
prepare_pact_files_for_publishing(task)
|
27
|
-
end
|
28
|
-
|
29
|
-
PactBroker::Client::PublicationTask.new(:jenkins_post_merge) do |task|
|
30
|
-
prepare_pact_files_for_publishing(task)
|
31
|
-
end
|
32
|
-
|
33
|
-
def prepare_pact_files_for_publishing(task)
|
34
|
-
task.pattern = 'pacts/*.json'
|
35
|
-
|
36
|
-
task.pact_broker_base_url = PactConfig.broker_host
|
37
|
-
task.pact_broker_basic_auth = {
|
38
|
-
username: PactConfig.broker_username,
|
39
|
-
password: PactConfig.broker_password
|
40
|
-
}
|
41
|
-
|
42
|
-
task.consumer_version = PactConfig.consumer_version
|
43
|
-
puts "Consumer version: #{task.consumer_version}"
|
44
|
-
|
45
|
-
task.tag = PactConfig.consumer_tag
|
46
|
-
puts "Pact file tagged with: #{task.tag}"
|
47
|
-
end
|
48
|
-
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module QuizApiClient::Services
|
2
|
+
class CoursesService < BaseApiService
|
3
|
+
def create(params:, token: nil)
|
4
|
+
post_to_quiz_api(params: params, token: token)
|
5
|
+
end
|
6
|
+
|
7
|
+
def update(params:, token: nil)
|
8
|
+
patch_to_quiz_api(params: params, token: token)
|
9
|
+
end
|
10
|
+
|
11
|
+
def destroy(params:, token: nil)
|
12
|
+
delete_from_quiz_api(params: params, token: token)
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def post_to_quiz_api(params:, token:)
|
18
|
+
client(token: token).post(
|
19
|
+
'/api/courses',
|
20
|
+
course: params
|
21
|
+
)
|
22
|
+
end
|
23
|
+
|
24
|
+
def patch_to_quiz_api(params:, token:)
|
25
|
+
client(token: token).patch(
|
26
|
+
"/api/courses/#{params[:canvas_id]}",
|
27
|
+
course: params.tap { |p| p.delete(:canvas_id) }
|
28
|
+
)
|
29
|
+
end
|
30
|
+
|
31
|
+
def delete_from_quiz_api(params:, token:)
|
32
|
+
client(token: token).delete(
|
33
|
+
"/api/courses/#{params[:canvas_id]}"
|
34
|
+
)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -4,6 +4,10 @@ module QuizApiClient::Services
|
|
4
4
|
post_to_quiz_api(params: params, token: token)
|
5
5
|
end
|
6
6
|
|
7
|
+
def create_batch(body:, token: nil)
|
8
|
+
batch_post_to_quiz_api(body: body, token: token)
|
9
|
+
end
|
10
|
+
|
7
11
|
private
|
8
12
|
|
9
13
|
def post_to_quiz_api(params:, token:)
|
@@ -11,5 +15,12 @@ module QuizApiClient::Services
|
|
11
15
|
"/api/quizzes/#{params.fetch(:quiz_id)}/quiz_clone_jobs"
|
12
16
|
)
|
13
17
|
end
|
18
|
+
|
19
|
+
def batch_post_to_quiz_api(body:, token:)
|
20
|
+
client(token: token).post(
|
21
|
+
'/api/quiz_clone_jobs/create_batch',
|
22
|
+
body
|
23
|
+
)
|
24
|
+
end
|
14
25
|
end
|
15
26
|
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module QuizApiClient::Services
|
2
|
+
class QuizSyncJobService < BaseApiService
|
3
|
+
def show(params:, token: nil)
|
4
|
+
raise 'Quiz Sync Job Id Required' unless params && params[:id]
|
5
|
+
|
6
|
+
get_from_quiz_api(params: params, token: token)
|
7
|
+
end
|
8
|
+
|
9
|
+
private
|
10
|
+
|
11
|
+
def get_from_quiz_api(params:, token:)
|
12
|
+
client(token: token).get(
|
13
|
+
"/api/quiz_sync_jobs/#{params.fetch(:id)}"
|
14
|
+
)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module QuizApiClient::Services
|
2
|
+
class QuizSyncJobsService < BaseApiService
|
3
|
+
def create_batch(body:, token: nil)
|
4
|
+
batch_post_to_quiz_api(body: body, token: token)
|
5
|
+
end
|
6
|
+
|
7
|
+
private
|
8
|
+
|
9
|
+
def batch_post_to_quiz_api(body:, token:)
|
10
|
+
client(token: token).post(
|
11
|
+
'/api/quiz_sync_jobs/create_batch',
|
12
|
+
body
|
13
|
+
)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
data/lib/quiz_api_client.rb
CHANGED
@@ -22,6 +22,10 @@ module QuizApiClient
|
|
22
22
|
@_config ||= QuizApiClient::Config.new
|
23
23
|
end
|
24
24
|
|
25
|
+
def courses_service
|
26
|
+
@_courses_service ||= Services::CoursesService.new(config)
|
27
|
+
end
|
28
|
+
|
25
29
|
def jwt_service
|
26
30
|
@_jwt_service ||= QuizApiClient::Services::JwtService.new(config)
|
27
31
|
end
|
@@ -50,6 +54,14 @@ module QuizApiClient
|
|
50
54
|
@_quiz_clone_jobs_service ||= Services::QuizCloneJobsService.new(config)
|
51
55
|
end
|
52
56
|
|
57
|
+
def quiz_sync_job_service
|
58
|
+
@_quiz_sync_job_service ||= Services::QuizSyncJobService.new(config)
|
59
|
+
end
|
60
|
+
|
61
|
+
def quiz_sync_jobs_service
|
62
|
+
@_quiz_sync_jobs_service ||= Services::QuizSyncJobsService.new(config)
|
63
|
+
end
|
64
|
+
|
53
65
|
def qti_imports_service
|
54
66
|
@_qti_imports_service ||= Services::QtiImportsService.new(config)
|
55
67
|
end
|
@@ -106,6 +118,7 @@ require 'quiz_api_client/http_request/metrics'
|
|
106
118
|
require 'quiz_api_client/services/jwt_service'
|
107
119
|
require 'quiz_api_client/services/base_api_service'
|
108
120
|
|
121
|
+
require 'quiz_api_client/services/courses_service'
|
109
122
|
require 'quiz_api_client/services/interaction_types_service'
|
110
123
|
require 'quiz_api_client/services/item_analyses_service'
|
111
124
|
require 'quiz_api_client/services/items_service'
|
@@ -120,6 +133,8 @@ require 'quiz_api_client/services/quizzes_service'
|
|
120
133
|
require 'quiz_api_client/services/quiz_session_result_service'
|
121
134
|
require 'quiz_api_client/services/quiz_clone_job_service'
|
122
135
|
require 'quiz_api_client/services/quiz_clone_jobs_service'
|
136
|
+
require 'quiz_api_client/services/quiz_sync_job_service'
|
137
|
+
require 'quiz_api_client/services/quiz_sync_jobs_service'
|
123
138
|
require 'quiz_api_client/services/session_items_service'
|
124
139
|
require 'quiz_api_client/services/session_item_results_service'
|
125
140
|
require 'quiz_api_client/services/shared_banks'
|
@@ -51,6 +51,13 @@ describe QuizApiClient do
|
|
51
51
|
end
|
52
52
|
end
|
53
53
|
|
54
|
+
describe '#courses_service' do
|
55
|
+
it 'creates the service' do
|
56
|
+
expect(QuizApiClient::Services::CoursesService).to receive(:new).with(subject.config)
|
57
|
+
subject.courses_service
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
54
61
|
describe '#quizzes_service' do
|
55
62
|
it 'should create the service' do
|
56
63
|
expect(QuizApiClient::Services::QuizzesService).to receive(:new).with(subject.config)
|
@@ -0,0 +1,98 @@
|
|
1
|
+
describe QuizApiClient::Services::CoursesService do
|
2
|
+
let(:host) { 'api.host' }
|
3
|
+
let(:config) { QuizApiClient::Config.new { |c| c.host = host } }
|
4
|
+
let(:subject) { described_class.new(config) }
|
5
|
+
|
6
|
+
describe '#create' do
|
7
|
+
let(:params) do
|
8
|
+
{
|
9
|
+
title: 'foo',
|
10
|
+
canvas_id: 2,
|
11
|
+
is_blueprint: true
|
12
|
+
}
|
13
|
+
end
|
14
|
+
|
15
|
+
let(:response) do
|
16
|
+
{
|
17
|
+
'id' => '4',
|
18
|
+
'title' => 'foo',
|
19
|
+
'canvas_id' => '2',
|
20
|
+
'is_blueprint' => true,
|
21
|
+
'created_at' => '2022-06-22T18:59:27.577Z',
|
22
|
+
'updated_at' => '2022-06-22T18:59:27.577Z'
|
23
|
+
}
|
24
|
+
end
|
25
|
+
|
26
|
+
let(:expected_url) { "https://#{host}/api/courses" }
|
27
|
+
|
28
|
+
before do
|
29
|
+
stub_request(:post, expected_url)
|
30
|
+
.with(body: { course: params }.to_json)
|
31
|
+
.to_return(
|
32
|
+
status: 201,
|
33
|
+
body: response.to_json,
|
34
|
+
headers: { 'Content-Type' => 'application/json' }
|
35
|
+
)
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'posts to the correct endpoint and returns the response' do
|
39
|
+
expect(
|
40
|
+
subject.create(params: params, token: 'token').parsed_response
|
41
|
+
).to eq(response)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
describe '#update' do
|
46
|
+
let(:params) do
|
47
|
+
{
|
48
|
+
canvas_id: 4,
|
49
|
+
title: 'foo',
|
50
|
+
is_blueprint: true
|
51
|
+
}
|
52
|
+
end
|
53
|
+
|
54
|
+
let(:response) do
|
55
|
+
{
|
56
|
+
'id' => '4',
|
57
|
+
'title' => 'foo',
|
58
|
+
'canvas_id' => '2',
|
59
|
+
'is_blueprint' => true,
|
60
|
+
'created_at' => '2022-06-22T18:59:27.577Z',
|
61
|
+
'updated_at' => '2022-06-22T18:59:27.577Z'
|
62
|
+
}
|
63
|
+
end
|
64
|
+
|
65
|
+
let(:expected_url) { "https://#{host}/api/courses/4" }
|
66
|
+
|
67
|
+
before do
|
68
|
+
stub_request(:patch, expected_url)
|
69
|
+
.with(body: { course: params.slice(:title, :is_blueprint) }.to_json)
|
70
|
+
.to_return(
|
71
|
+
status: 200,
|
72
|
+
body: response.to_json,
|
73
|
+
headers: { 'Content-Type' => 'application/json' }
|
74
|
+
)
|
75
|
+
end
|
76
|
+
|
77
|
+
it 'pathces to the correct endpoint and returns the response' do
|
78
|
+
expect(
|
79
|
+
subject.update(params: params, token: 'token').parsed_response
|
80
|
+
).to eq(response)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
describe '#destroy' do
|
85
|
+
let(:params) { { canvas_id: 1 } }
|
86
|
+
let(:expected_url) { "https://#{host}/api/courses/1" }
|
87
|
+
|
88
|
+
before do
|
89
|
+
stub_request(:delete, expected_url).to_return(status: 204)
|
90
|
+
end
|
91
|
+
|
92
|
+
it 'deletes to the correct endpoint and returns the response' do
|
93
|
+
response = subject.destroy(params: params, token: 'token')
|
94
|
+
expect(response.code).to eq 204
|
95
|
+
expect(response.body).to be_nil
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
@@ -38,4 +38,40 @@ describe QuizApiClient::Services::QuizCloneJobsService do
|
|
38
38
|
end
|
39
39
|
end
|
40
40
|
end
|
41
|
+
|
42
|
+
describe '#create_batch' do
|
43
|
+
let(:expected_url) { "https://#{host}/api/quiz_clone_jobs/create_batch" }
|
44
|
+
let(:body) { { quiz_ids: [1, 2] } }
|
45
|
+
let(:stubbed_response) { { 'id' => '1' } }
|
46
|
+
|
47
|
+
context 'on success' do
|
48
|
+
before do
|
49
|
+
stub_request(:post, expected_url)
|
50
|
+
.to_return(
|
51
|
+
status: 200,
|
52
|
+
body: stubbed_response.to_json,
|
53
|
+
headers: { 'Content-Type' => 'application/json' }
|
54
|
+
)
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'posts to /api/quiz_clone_jobs/create_batch' do
|
58
|
+
result = subject.create_batch(body: body, token: 'token')
|
59
|
+
expect(result.parsed_response).to eql(stubbed_response)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
context 'on failure' do
|
64
|
+
let(:status_code) { 401 }
|
65
|
+
|
66
|
+
before do
|
67
|
+
stub_request(:post, expected_url)
|
68
|
+
.to_return(status: status_code)
|
69
|
+
end
|
70
|
+
|
71
|
+
it 'returns a response with the correct code' do
|
72
|
+
response = subject.create_batch(body: body, token: 'token')
|
73
|
+
expect(response.code).to eq(status_code)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
41
77
|
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
describe QuizApiClient::Services::QuizSyncJobService do
|
2
|
+
let(:host) { 'api.host' }
|
3
|
+
let(:config) { QuizApiClient::Config.new { |c| c.host = host } }
|
4
|
+
let(:subject) { described_class.new(config) }
|
5
|
+
|
6
|
+
describe '#show' do
|
7
|
+
let(:expected_url) { "https://#{host}/api/quiz_sync_jobs/#{params[:id]}" }
|
8
|
+
let(:params) { { id: 1 } }
|
9
|
+
let(:stubbed_response) { { 'id' => 1, 'original_quiz_id' => 666, 'status' => 'completed' } }
|
10
|
+
|
11
|
+
context 'on success' do
|
12
|
+
before do
|
13
|
+
stub_request(:get, expected_url)
|
14
|
+
.to_return(
|
15
|
+
status: 200,
|
16
|
+
body: stubbed_response.to_json,
|
17
|
+
headers: { 'Content-Type' => 'application/json' }
|
18
|
+
)
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'gets from /api/quiz_sync_jobs/:id' do
|
22
|
+
result = subject.show(params: params, token: 'token')
|
23
|
+
expect(result.parsed_response).to eql(stubbed_response)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
context 'on failure' do
|
28
|
+
let(:status_code) { 401 }
|
29
|
+
|
30
|
+
before do
|
31
|
+
stub_request(:get, expected_url)
|
32
|
+
.to_return(status: status_code)
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'returns a response with the correct code' do
|
36
|
+
response = subject.show(params: params, token: 'token')
|
37
|
+
expect(response.code).to eq(status_code)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
describe QuizApiClient::Services::QuizCloneJobsService do
|
2
|
+
let(:host) { 'api.host' }
|
3
|
+
let(:config) { QuizApiClient::Config.new { |c| c.host = host } }
|
4
|
+
let(:subject) { described_class.new(config) }
|
5
|
+
|
6
|
+
describe '#create' do
|
7
|
+
let(:expected_url) { "https://#{host}/api/quizzes/#{params[:quiz_id]}/quiz_clone_jobs" }
|
8
|
+
let(:params) { { quiz_id: 1 } }
|
9
|
+
let(:stubbed_response) { { 'id' => '1' } }
|
10
|
+
|
11
|
+
context 'on success' do
|
12
|
+
before do
|
13
|
+
stub_request(:post, expected_url)
|
14
|
+
.to_return(
|
15
|
+
status: 200,
|
16
|
+
body: stubbed_response.to_json,
|
17
|
+
headers: { 'Content-Type' => 'application/json' }
|
18
|
+
)
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'posts to /api/quizzes/:quiz_id/quiz_clone_job' do
|
22
|
+
result = subject.create(params: params, token: 'token')
|
23
|
+
expect(result.parsed_response).to eql(stubbed_response)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
context 'on failure' do
|
28
|
+
let(:status_code) { 401 }
|
29
|
+
|
30
|
+
before do
|
31
|
+
stub_request(:post, expected_url)
|
32
|
+
.to_return(status: status_code)
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'returns a response with the correct code' do
|
36
|
+
response = subject.create(params: params, token: 'token')
|
37
|
+
expect(response.code).to eq(status_code)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe '#create_batch' do
|
43
|
+
let(:expected_url) { "https://#{host}/api/quiz_clone_jobs/create_batch" }
|
44
|
+
let(:body) { { quiz_ids: [1, 2] } }
|
45
|
+
let(:stubbed_response) { { 'id' => '1' } }
|
46
|
+
|
47
|
+
context 'on success' do
|
48
|
+
before do
|
49
|
+
stub_request(:post, expected_url)
|
50
|
+
.to_return(
|
51
|
+
status: 200,
|
52
|
+
body: stubbed_response.to_json,
|
53
|
+
headers: { 'Content-Type' => 'application/json' }
|
54
|
+
)
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'posts to /api/quiz_clone_jobs/create_batch' do
|
58
|
+
result = subject.create_batch(body: body, token: 'token')
|
59
|
+
expect(result.parsed_response).to eql(stubbed_response)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
context 'on failure' do
|
64
|
+
let(:status_code) { 401 }
|
65
|
+
|
66
|
+
before do
|
67
|
+
stub_request(:post, expected_url)
|
68
|
+
.to_return(status: status_code)
|
69
|
+
end
|
70
|
+
|
71
|
+
it 'returns a response with the correct code' do
|
72
|
+
response = subject.create_batch(body: body, token: 'token')
|
73
|
+
expect(response.code).to eq(status_code)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
require 'pact/consumer/rspec'
|
2
1
|
require 'pry'
|
3
2
|
require 'simplecov'
|
4
3
|
require 'webmock/rspec'
|
@@ -10,33 +9,10 @@ end
|
|
10
9
|
$LOAD_PATH.unshift File.expand_path('../lib', __dir__)
|
11
10
|
require 'quiz_api_client'
|
12
11
|
|
13
|
-
Dir[File.dirname(__FILE__) + '/support/*.rb'].each { |f| require f }
|
14
|
-
Dir[File.dirname(__FILE__) + '/contracts/shared_examples/*.rb'].each { |f| require f }
|
15
|
-
|
16
12
|
WebMock.disable_net_connect!(
|
17
|
-
allow_localhost: true
|
18
|
-
allow: [PactConfig.broker_host]
|
13
|
+
allow_localhost: true
|
19
14
|
)
|
20
15
|
|
21
|
-
# see https://github.com/realestate-com-au/pact/blob/master/documentation/configuration.md
|
22
|
-
Pact.configure do |config|
|
23
|
-
config.diff_formatter = :list
|
24
|
-
config.logger.level = Logger::DEBUG
|
25
|
-
config.pact_dir = 'pacts'
|
26
|
-
config.pactfile_write_mode = :overwrite
|
27
|
-
config.pactfile_write_order = :chronological
|
28
|
-
end
|
29
|
-
|
30
|
-
Pact.service_consumer PactConfig::QUIZ_API_CLIENT_RUBY do
|
31
|
-
has_pact_with PactConfig::Providers::QUIZ_API do
|
32
|
-
mock_service :quiz_api do
|
33
|
-
port 1234
|
34
|
-
pact_specification_version '2.0.0'
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
16
|
RSpec.configure do |config|
|
40
|
-
config.filter_run_excluding :pact
|
41
17
|
config.before { allow_any_instance_of(::Logger).to receive(:info) }
|
42
18
|
end
|