-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Other status shouldn't be processed. Added more test cases.
- Loading branch information
Showing
8 changed files
with
887 additions
and
33 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
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 |
---|---|---|
|
@@ -28,9 +28,9 @@ def request(payload, secret: nil) | |
post "/webhook", payload | ||
end | ||
|
||
def test_valid_webhook_request | ||
def test_valid_webhook_request_cocagne | ||
ENV["COCAGNE_API_TOKEN"] = "api-token-cocagne" | ||
payload = File.read('test/fixtures/order_created.json') | ||
payload = File.read('test/fixtures/order_completed_cocagne.json') | ||
stub_request(:any, "https://admin.cocagne.test/api/v1/members") | ||
.to_return(status: 201) | ||
|
||
|
@@ -39,26 +39,106 @@ def test_valid_webhook_request | |
assert_equal 204, last_response.status | ||
assert_empty last_response.body | ||
|
||
# assert_requested :post, "https://admin.cocagne.test/api/v1/members", | ||
# times: 1, | ||
# headers: { | ||
# "Content-Type" => "application/json", | ||
# "Authorization" => "Token token=api-token-cocagne" | ||
# }, | ||
# body: { | ||
# name: "Doe John", | ||
# emails: "[email protected]", | ||
# phones: "079 123 45 67", | ||
# address: "Chemin de la Mairie, 1", | ||
# city: "Troinex", | ||
# zip: "1256", | ||
# country_code: "CH", | ||
# waiting_basket_size_id: 1, | ||
# waiting_depot_id: 22, | ||
# members_basket_complements_attributes: [ | ||
# { basket_complement_id:10, quantity:1 } | ||
# ] | ||
# }.to_json | ||
assert_requested :post, "https://admin.cocagne.test/api/v1/members", | ||
times: 1, | ||
headers: { | ||
"Content-Type" => "application/json", | ||
"Authorization" => "Token token=api-token-cocagne" | ||
}, | ||
body: { | ||
name: "Doe John", | ||
emails: "[email protected]", | ||
phones: "079 123 45 67", | ||
address: "Chemin de la Mairie, 1", | ||
city: "Troinex", | ||
zip: "1256", | ||
country_code: "CH", | ||
note: "Commande locali-ge.ch #35255", | ||
waiting_basket_size_id: 1, | ||
waiting_depot_id: 7, | ||
members_basket_complements_attributes: [ | ||
{ basket_complement_id:10, quantity:1 } | ||
] | ||
}.to_json | ||
end | ||
|
||
def test_valid_webhook_request_locali | ||
ENV["LOCALI_API_TOKEN"] = "api-token-locali" | ||
payload = File.read('test/fixtures/order_completed_locali.json') | ||
stub_request(:any, "https://admin.panier-locali.test/api/v1/members") | ||
.to_return(status: 201) | ||
|
||
request(payload) | ||
|
||
assert_equal 204, last_response.status | ||
assert_empty last_response.body | ||
|
||
assert_requested :post, "https://admin.panier-locali.test/api/v1/members", | ||
times: 1, | ||
headers: { | ||
"Content-Type" => "application/json", | ||
"Authorization" => "Token token=api-token-locali" | ||
}, | ||
body: { | ||
name: "Doe John", | ||
emails: "[email protected]", | ||
phones: "0791234567", | ||
address: "Chemin de la Mairie 1", | ||
city: "Genève", | ||
zip: "1205", | ||
country_code: "CH", | ||
note: "Commande locali-ge.ch #35717", | ||
waiting_basket_size_id: 1, | ||
waiting_depot_id: 3, | ||
members_basket_complements_attributes: [] | ||
}.to_json | ||
end | ||
|
||
def test_valid_webhook_request_touviere | ||
ENV["TOUVIERE_API_TOKEN"] = "api-token-touviere" | ||
payload = File.read('test/fixtures/order_completed_touviere.json') | ||
stub_request(:any, "https://admin.touviere.test/api/v1/members") | ||
.to_return(status: 201) | ||
|
||
request(payload) | ||
|
||
assert_equal 204, last_response.status | ||
assert_empty last_response.body | ||
|
||
assert_requested :post, "https://admin.touviere.test/api/v1/members", | ||
times: 1, | ||
headers: { | ||
"Content-Type" => "application/json", | ||
"Authorization" => "Token token=api-token-touviere" | ||
}, | ||
body: { | ||
name: "Doe John", | ||
emails: "[email protected]", | ||
phones: "0791234567", | ||
address: "Chemin de la Mairie 1", | ||
city: "Genève", | ||
zip: "1205", | ||
country_code: "CH", | ||
note: "Commande locali-ge.ch #35715", | ||
waiting_basket_size_id: 1, | ||
waiting_depot_id: 3, | ||
members_basket_complements_attributes: [ | ||
{ basket_complement_id: 2, quantity: 1 }, | ||
{ basket_complement_id: 1, quantity: 1 } | ||
] | ||
}.to_json | ||
end | ||
|
||
def test_valid_webhook_request_but_not_completed | ||
ENV["COCAGNE_API_TOKEN"] = "api-token-cocagne" | ||
payload = File.read('test/fixtures/order_processing_cocagne.json') | ||
|
||
request(payload) | ||
|
||
assert_equal 204, last_response.status | ||
assert_empty last_response.body | ||
|
||
assert_not_requested :post, "https://admin.cocagne.test/api/v1/members" | ||
end | ||
|
||
def test_unknown_store | ||
|
2 changes: 1 addition & 1 deletion
2
test/fixtures/order_created.json → test/fixtures/order_completed_cocagne.json
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
Oops, something went wrong.