-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added tests for jobs, refactored jobs
- Loading branch information
1 parent
ca9b37c
commit f57dc1d
Showing
7 changed files
with
224 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
one: | ||
order_id: 1 | ||
suborder_id: 1 | ||
domain_name: example1.ee | ||
state: 2 | ||
registration_code: 1234567890 | ||
create_date: <%= Time.zone.parse('2010-07-05').to_s(:db) %> | ||
created_at: <%= Time.zone.parse('2010-07-05').to_s(:db) %> | ||
updated_at: <%= Time.zone.parse('2010-07-05').to_s(:db) %> | ||
two: | ||
order_id: 2 | ||
suborder_id: 2 | ||
domain_name: example2.ee | ||
state: 2 | ||
registration_code: 0987654321 | ||
create_date: <%= Time.zone.parse('2010-07-05').to_s(:db) %> | ||
created_at: <%= Time.zone.parse('2010-07-05').to_s(:db) %> | ||
updated_at: <%= Time.zone.parse('2010-07-05').to_s(:db) %> |
134 changes: 134 additions & 0 deletions
134
test/jobs/fetch_godaddy_bsa_block_order_list_job_test.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
require 'test_helper' | ||
|
||
RESPONSE_BLOCK_VIEW_SERVICE_FOR_JOB = { | ||
"list": [ | ||
{ | ||
"blockSubOrderId": 690_680_666_563_633, | ||
"rspAccountId": 1005, | ||
"blockOrder": { | ||
"blockOrderId": 3_363_656_660_861 | ||
}, | ||
"blockOrderStatus": { | ||
"blockOrderStatusId": 2, | ||
"name": 'QueuedForActivation', | ||
"displayName": 'Queued for Activation', | ||
"description": 'Queued for Activation' | ||
}, | ||
"productType": 'Standard', | ||
"tld": { | ||
"tldId": 22, | ||
"name": 'TEST-ONE', | ||
"displayName": '.test-one' | ||
}, | ||
"label": 'testandvalidate', | ||
"createdDt": '2023-04-05T03:49:19.000+0000' | ||
}, | ||
{ | ||
"blockSubOrderId": 790_681_879_713_707, | ||
"rspAccountId": 1005, | ||
"blockOrder": { | ||
"blockOrderId": 7_073_179_781_861 | ||
}, | ||
"blockOrderStatus": { | ||
"blockOrderStatusId": 2, | ||
"name": 'QueuedForActivation', | ||
"displayName": 'Queued for Activation', | ||
"description": 'Queued for Activation' | ||
}, | ||
"productType": 'Plus', | ||
"tld": { | ||
"tldId": 21, | ||
"name": 'TEST-TWO', | ||
"displayName": '.test-two' | ||
}, | ||
"label": ' testandvalidate', | ||
"createdDt": '2023-04-19T04:48:29.000+0000' | ||
} | ||
], | ||
"offset": 0, | ||
"limit": 100, | ||
"count": 2, | ||
"total": 2, | ||
"sortBy": [ | ||
'createdDt' | ||
], | ||
"order": 'asc' | ||
}.freeze | ||
|
||
EMPTY_RESPONSE_BLOCK_VIEW_SERVICE_FOR_JOB = { | ||
"list": [], | ||
"offset": 0, | ||
"limit": 100, | ||
"count": 0, | ||
"total": 0, | ||
"sortBy": [ | ||
'createdDt' | ||
], | ||
"order": 'asc' | ||
} | ||
|
||
INVALID_RESPONSE = { | ||
"message": 'Unsupported Media Type', | ||
"description": 'The server is refusing to service the request because the entity of the request is in a format' \ | ||
' not supported by the requested resource for the requested method' | ||
}.freeze | ||
|
||
class FetchGodaddyBsaBlockOrderListJobTest < ActiveSupport::TestCase | ||
setup do | ||
token = generate_test_bsa_token(Time.zone.now + 20.minute) | ||
stub_succesfull_auth_request(token) | ||
end | ||
|
||
def test_succesfull_fetch_block_order_list_and_added_to_db | ||
stub_request(:get, 'https://api-ote.bsagateway.co/bsa/api/blockrsporder?limit=20&offset=0&q=blockOrderStatus.name=QueuedForActivation') | ||
.to_return( | ||
status: 200, | ||
body: RESPONSE_BLOCK_VIEW_SERVICE_FOR_JOB.to_json, | ||
headers: { 'Content-Type' => 'application/json' } | ||
) | ||
|
||
assert_difference 'BsaProtectedDomain.count', 2 do | ||
FetchGodaddyBsaBlockOrderListJob.perform_now | ||
end | ||
end | ||
|
||
def test_should_show_message_if_list_is_empty | ||
stub_request(:get, 'https://api-ote.bsagateway.co/bsa/api/blockrsporder?limit=20&offset=0&q=blockOrderStatus.name=QueuedForActivation') | ||
.to_return( | ||
status: 200, | ||
body: EMPTY_RESPONSE_BLOCK_VIEW_SERVICE_FOR_JOB.to_json, | ||
headers: { 'Content-Type' => 'application/json' } | ||
) | ||
|
||
result = FetchGodaddyBsaBlockOrderListJob.perform_now | ||
|
||
assert_equal result, 'Limit reached. No more block orders to fetch' | ||
end | ||
|
||
def test_should_show_message_if_error_occur | ||
stub_request(:get, 'https://api-ote.bsagateway.co/bsa/api/blockrsporder?limit=20&offset=0&q=blockOrderStatus.name=QueuedForActivation') | ||
.to_return( | ||
status: 415, | ||
body: INVALID_RESPONSE.to_json, | ||
headers: { 'Content-Type' => 'application/json' } | ||
) | ||
|
||
result = FetchGodaddyBsaBlockOrderListJob.perform_now | ||
|
||
assert_equal result[:message], 'Unsupported Media Type' | ||
assert_equal result[:description], 'The server is refusing to service the request because the entity of the' \ | ||
' request is in a format not supported by the requested resource for the' \ | ||
' requested method' | ||
end | ||
|
||
private | ||
|
||
def stub_succesfull_auth_request(token) | ||
stub_request(:post, 'https://api-ote.bsagateway.co/iam/api/authenticate/apiKey') | ||
.to_return( | ||
status: 200, | ||
body: { id_token: token }.to_json, | ||
headers: { 'Content-Type' => 'application/json' } | ||
) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
require 'test_helper' | ||
|
||
class UpdateGodaddyDomainsStatusJobTest < ActiveSupport::TestCase | ||
BODY_ORDER_STATUS_SETTING_JOB = [ | ||
{ blockSubOrderId: 1, status: 'ActivationInProgress' }, | ||
{ blockSubOrderId: 2, status: 'ActivationInProgress' }, | ||
] | ||
|
||
RESPONSE_ORDER_STATUS_SETTING_JOB = { | ||
message: 'ok' | ||
} | ||
|
||
INVALID_RESPONSE = { | ||
"message": 'Unsupported Media Type', | ||
"description": 'The server is refusing to service the request because the entity of the request is in a format' \ | ||
' not supported by the requested resource for the requested method' | ||
} | ||
|
||
setup do | ||
token = generate_test_bsa_token(Time.zone.now + 20.minute) | ||
stub_succesfull_auth_request(token) | ||
end | ||
|
||
def test_should_update_statuses | ||
stub_request(:post, 'https://api-ote.bsagateway.co/bsa/api/blockrsporder/status') | ||
.to_return( | ||
status: 200, | ||
body: BODY_ORDER_STATUS_SETTING_JOB.to_json, | ||
headers: { 'Content-Type' => 'application/json' } | ||
) | ||
|
||
assert BsaProtectedDomain.all.all? { |domain| domain.state == 'QueuedForActivation' } | ||
|
||
UpdateGodaddyDomainsStatusJob.perform_now('QueuedForActivation', 'ActivationInProgress') | ||
|
||
assert BsaProtectedDomain.all.all? { |domain| domain.state == 'ActivationInProgress' } | ||
end | ||
|
||
def test_should_return_reason_of_error_and_not_update_statuses | ||
stub_request(:post, 'https://api-ote.bsagateway.co/bsa/api/blockrsporder/status') | ||
.to_return( | ||
status: 415, | ||
body: INVALID_RESPONSE.to_json, | ||
headers: { 'Content-Type' => 'application/json' } | ||
) | ||
|
||
assert BsaProtectedDomain.all.all? { |domain| domain.state == 'QueuedForActivation' } | ||
result = UpdateGodaddyDomainsStatusJob.perform_now('QueuedForActivation', 'ActivationInProgress') | ||
|
||
assert BsaProtectedDomain.all.all? { |domain| domain.state == 'QueuedForActivation' } | ||
end | ||
|
||
private | ||
|
||
def stub_succesfull_auth_request(token) | ||
stub_request(:post, 'https://api-ote.bsagateway.co/iam/api/authenticate/apiKey') | ||
.to_return( | ||
status: 200, | ||
body: { id_token: token }.to_json, | ||
headers: { 'Content-Type' => 'application/json' } | ||
) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters