Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #29 from nozzlegear/master
Merging nozzlegear/master
- Loading branch information
Showing
28 changed files
with
1,243 additions
and
18 deletions.
There are no files selected for viewing
102 changes: 102 additions & 0 deletions
102
ShopifySharp.Experimental.Tests/ApplicationCreditTest.fs
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,102 @@ | ||
module ApplicationCreditTests | ||
|
||
open System.Threading.Tasks | ||
open Xunit | ||
open ShopifySharp.Experimental | ||
open ShopifySharp.Experimental.ApplicationCredits | ||
|
||
let private service = Service.NewService "https://example.myshopify.com" "test token" | ||
|
||
type CreateFunction = ApplicationCreditProperties -> Task<ShopifySharp.ApplicationCredit> | ||
|
||
[<Fact>] | ||
let ``Function signatures match what they are expected to be`` () = | ||
// The test itself does nothing but pass. The compiler should throw errors if the signatures ever change. | ||
let _: CreateFunction = service.CreateAsync | ||
|
||
Assert.True true | ||
|
||
[<Fact>] | ||
let ``Serializes application credit properties to a dictionary`` () = | ||
let dictionary = | ||
ApplicationCredits.newApplicationCredit | ||
|> ApplicationCredits.description "My Test Refund" | ||
|> ApplicationCredits.test false | ||
|> ApplicationCredits.amount 1.17M | ||
|> ApplicationCredits.toRawPropertyNames | ||
let expected = Map [ | ||
"description" => "My Test Refund" | ||
"test" => false | ||
"amount" => 1.17M | ||
] | ||
|
||
Assert.Equal(expected, JsonValue.MapPropertyValuesToObjects dictionary) | ||
|
||
[<Fact>] | ||
let ``Serializes application credit properties to a dictionary with explicit null values`` () = | ||
let dictionary = | ||
ApplicationCredits.newApplicationCredit | ||
|> ApplicationCredits.description "My Test Refund" | ||
|> ApplicationCredits.test false | ||
|> ApplicationCredits.amount 1.17M | ||
|> ApplicationCredits.makePropertyNull ApplicationCredits.Amount | ||
|> ApplicationCredits.toRawPropertyNames | ||
let expected = Map [ | ||
"description" => "My Test Refund" | ||
"test" => false | ||
"amount" => null | ||
] | ||
|
||
Assert.Equal(expected, JsonValue.MapPropertyValuesToObjects dictionary) | ||
|
||
[<Fact>] | ||
let ``Removes properties from the dictionary`` () = | ||
let dictionary = | ||
ApplicationCredits.newApplicationCredit | ||
|> ApplicationCredits.description "My Test Refund" | ||
|> ApplicationCredits.test false | ||
|> ApplicationCredits.amount 1.17M | ||
|> ApplicationCredits.makePropertyNull ApplicationCredits.Amount | ||
|> ApplicationCredits.removeProperty ApplicationCredits.Amount | ||
|> ApplicationCredits.toRawPropertyNames | ||
let expected = Map [ | ||
"description" => "My Test Refund" | ||
"test" => false | ||
] | ||
|
||
Assert.Equal(expected, JsonValue.MapPropertyValuesToObjects dictionary) | ||
Assert.False(Map.containsKey "amount" dictionary) | ||
|
||
[<Fact>] | ||
let ``Does not add unused properties`` () = | ||
let dictionary = | ||
ApplicationCredits.newApplicationCredit | ||
|> ApplicationCredits.description "My Test Refund" | ||
|> ApplicationCredits.test false | ||
|> ApplicationCredits.toRawPropertyNames | ||
let expected = Map [ | ||
"description" => "My Test Refund" | ||
"test" => false | ||
] | ||
|
||
Assert.Equal(expected, JsonValue.MapPropertyValuesToObjects dictionary) | ||
Assert.False(Map.containsKey "amount" dictionary) | ||
|
||
[<Fact>] | ||
let ``Replaces properties if they already exist`` () = | ||
let dictionary = | ||
ApplicationCredits.newApplicationCredit | ||
|> ApplicationCredits.description "My Test Refund" | ||
|> ApplicationCredits.test false | ||
|> ApplicationCredits.amount 1.17M | ||
|> ApplicationCredits.amount 5.25M | ||
|> ApplicationCredits.toRawPropertyNames | ||
let expected = Map [ | ||
"description" => "My Test Refund" | ||
"test" => false | ||
"amount" => 5.25M | ||
] | ||
|
||
Assert.Equal(expected, JsonValue.MapPropertyValuesToObjects dictionary) | ||
|
||
|
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,107 @@ | ||
module ChargeTests | ||
|
||
open System.Threading.Tasks | ||
open Xunit | ||
open ShopifySharp.Experimental | ||
open ShopifySharp.Experimental.Charges | ||
|
||
let private service = Charges.Service.NewService "https://example.myshopify.com" "test token" | ||
|
||
type CreateFunction = ChargeProperties -> Task<ShopifySharp.Charge> | ||
|
||
[<Fact>] | ||
let ``Function signatures match what they are expected to be`` () = | ||
// The test itself does nothing but pass. The compiler should throw errors if the signatures ever change. | ||
let _: CreateFunction = service.CreateAsync | ||
|
||
Assert.True true | ||
|
||
[<Fact>] | ||
let ``Serializes charge properties to a dictionary`` () = | ||
let dictionary = | ||
Charges.newCharge | ||
|> Charges.name "My Charge" | ||
|> Charges.price 1.17M | ||
|> Charges.returnUrl "https://example.com/activate-charge" | ||
|> Charges.test false | ||
|> Charges.toRawPropertyNames | ||
let expected = Map [ | ||
"name" => "My Charge" | ||
"price" => 1.17M | ||
"return_url" => "https://example.com/activate-charge" | ||
"test" => false | ||
] | ||
|
||
Assert.Equal(expected, JsonValue.MapPropertyValuesToObjects dictionary) | ||
|
||
[<Fact>] | ||
let ``Serializes charge properties to a dictionary with explicit null values`` () = | ||
let dictionary = | ||
Charges.newCharge | ||
|> Charges.name "My Charge" | ||
|> Charges.price 1.17M | ||
|> Charges.returnUrl "https://example.com/activate-charge" | ||
|> Charges.test false | ||
|> Charges.makePropertyNull Charges.Test | ||
|> Charges.toRawPropertyNames | ||
let expected = Map [ | ||
"name" => "My Charge" | ||
"price" => 1.17M | ||
"return_url" => "https://example.com/activate-charge" | ||
"test" => null | ||
] | ||
|
||
Assert.Equal(expected, JsonValue.MapPropertyValuesToObjects dictionary) | ||
|
||
[<Fact>] | ||
let ``Removes properties from the dictionary`` () = | ||
let dictionary = | ||
Charges.newCharge | ||
|> Charges.name "My Charge" | ||
|> Charges.price 1.17M | ||
|> Charges.returnUrl "https://example.com/activate-charge" | ||
|> Charges.test false | ||
|> Charges.makePropertyNull Charges.Test | ||
|> Charges.removeProperty Charges.Test | ||
|> Charges.toRawPropertyNames | ||
let expected = Map [ | ||
"name" => "My Charge" | ||
"price" => 1.17M | ||
"return_url" => "https://example.com/activate-charge" | ||
] | ||
|
||
Assert.Equal(expected, JsonValue.MapPropertyValuesToObjects dictionary) | ||
Assert.False(Map.containsKey "test" dictionary) | ||
|
||
|
||
[<Fact>] | ||
let ``Does not add unused properties`` () = | ||
let dictionary = | ||
Charges.newCharge | ||
|> Charges.name "My Charge" | ||
|> Charges.price 1.17M | ||
|> Charges.returnUrl "https://example.com/activate-charge" | ||
|> Charges.toRawPropertyNames | ||
let expected = Map [ | ||
"name" => "My Charge" | ||
"price" => 1.17M | ||
"return_url" => "https://example.com/activate-charge" | ||
] | ||
|
||
Assert.Equal(expected, JsonValue.MapPropertyValuesToObjects dictionary) | ||
Assert.False(Map.containsKey "test" dictionary) | ||
|
||
[<Fact>] | ||
let ``Replaces properties if they already exist`` () = | ||
let dictionary = | ||
Charges.newCharge | ||
|> Charges.name "My Charge" | ||
|> Charges.returnUrl "https://example.com/activate-charge" | ||
|> Charges.returnUrl "hello world" | ||
|> Charges.toRawPropertyNames | ||
let expected = Map [ | ||
"name" => "My Charge" | ||
"return_url" => "hello world" | ||
] | ||
|
||
Assert.Equal(expected, JsonValue.MapPropertyValuesToObjects dictionary) |
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,138 @@ | ||
module RecurringChargeTests | ||
|
||
open System.Threading.Tasks | ||
open Xunit | ||
open ShopifySharp.Experimental | ||
open ShopifySharp.Experimental.RecurringCharges | ||
|
||
let private service = RecurringCharges.Service.NewService "https://example.myshopify.com" "test token" | ||
|
||
type CreateFunction = RecurringChargeProperties -> Task<ShopifySharp.RecurringCharge> | ||
|
||
[<Fact>] | ||
let ``Function signatures match what they are expected to be`` () = | ||
// The test itself does nothing but pass. The compiler should throw errors if the signatures ever change. | ||
let _: CreateFunction = service.CreateAsync | ||
|
||
Assert.True true | ||
|
||
[<Fact>] | ||
let ``Serializes recurring charge properties to a dictionary`` () = | ||
let dictionary = | ||
RecurringCharges.newRecurringCharge | ||
|> RecurringCharges.cappedAmount 5.0M | ||
|> RecurringCharges.name "My Charge" | ||
|> RecurringCharges.price 1.17M | ||
|> RecurringCharges.returnUrl "https://example.com/activate-charge" | ||
|> RecurringCharges.terms "These are the charge terms" | ||
|> RecurringCharges.test false | ||
|> RecurringCharges.trialDays 14 | ||
|> RecurringCharges.toRawPropertyNames | ||
let expected = Map [ | ||
"capped_amount" => 5.0M | ||
"name" => "My Charge" | ||
"price" => 1.17M | ||
"return_url" => "https://example.com/activate-charge" | ||
"terms" => "These are the charge terms" | ||
"test" => false | ||
"trial_days" => 14 | ||
] | ||
|
||
Assert.Equal(expected, JsonValue.MapPropertyValuesToObjects dictionary) | ||
|
||
[<Fact>] | ||
let ``Serializes recurring charge properties to a dictionary with explicit null values`` () = | ||
let dictionary = | ||
RecurringCharges.newRecurringCharge | ||
|> RecurringCharges.cappedAmount 5.0M | ||
|> RecurringCharges.name "My Charge" | ||
|> RecurringCharges.price 1.17M | ||
|> RecurringCharges.returnUrl "https://example.com/activate-charge" | ||
|> RecurringCharges.terms "These are the charge terms" | ||
|> RecurringCharges.test false | ||
|> RecurringCharges.trialDays 14 | ||
|> RecurringCharges.makePropertyNull RecurringCharges.TrialDays | ||
|> RecurringCharges.toRawPropertyNames | ||
let expected = Map [ | ||
"capped_amount" => 5.0M | ||
"name" => "My Charge" | ||
"price" => 1.17M | ||
"return_url" => "https://example.com/activate-charge" | ||
"terms" => "These are the charge terms" | ||
"test" => false | ||
"trial_days" => null | ||
] | ||
|
||
Assert.Equal(expected, JsonValue.MapPropertyValuesToObjects dictionary) | ||
|
||
[<Fact>] | ||
let ``Removes properties from the dictionary`` () = | ||
let dictionary = | ||
RecurringCharges.newRecurringCharge | ||
|> RecurringCharges.cappedAmount 5.0M | ||
|> RecurringCharges.name "My Charge" | ||
|> RecurringCharges.price 1.17M | ||
|> RecurringCharges.returnUrl "https://example.com/activate-charge" | ||
|> RecurringCharges.terms "These are the charge terms" | ||
|> RecurringCharges.test false | ||
|> RecurringCharges.trialDays 14 | ||
|> RecurringCharges.makePropertyNull RecurringCharges.TrialDays | ||
|> RecurringCharges.removeProperty RecurringCharges.TrialDays | ||
|> RecurringCharges.toRawPropertyNames | ||
let expected = Map [ | ||
"capped_amount" => 5.0M | ||
"name" => "My Charge" | ||
"price" => 1.17M | ||
"return_url" => "https://example.com/activate-charge" | ||
"terms" => "These are the charge terms" | ||
"test" => false | ||
] | ||
|
||
Assert.Equal(expected, JsonValue.MapPropertyValuesToObjects dictionary) | ||
Assert.False(Map.containsKey "trial_days" dictionary) | ||
|
||
[<Fact>] | ||
let ``Does not add unused properties`` () = | ||
let dictionary = | ||
RecurringCharges.newRecurringCharge | ||
|> RecurringCharges.cappedAmount 5.0M | ||
|> RecurringCharges.name "My Charge" | ||
|> RecurringCharges.price 1.17M | ||
|> RecurringCharges.returnUrl "https://example.com/activate-charge" | ||
|> RecurringCharges.terms "These are the charge terms" | ||
|> RecurringCharges.test false | ||
|> RecurringCharges.toRawPropertyNames | ||
let expected = Map [ | ||
"capped_amount" => 5.0M | ||
"name" => "My Charge" | ||
"price" => 1.17M | ||
"return_url" => "https://example.com/activate-charge" | ||
"terms" => "These are the charge terms" | ||
"test" => false | ||
] | ||
|
||
Assert.Equal(expected, JsonValue.MapPropertyValuesToObjects dictionary) | ||
Assert.False(Map.containsKey "trial_days" dictionary) | ||
|
||
[<Fact>] | ||
let ``Replaces properties if they already exist`` () = | ||
let dictionary = | ||
RecurringCharges.newRecurringCharge | ||
|> RecurringCharges.cappedAmount 5.0M | ||
|> RecurringCharges.name "My Charge" | ||
|> RecurringCharges.price 1.17M | ||
|> RecurringCharges.returnUrl "https://example.com/activate-charge" | ||
|> RecurringCharges.terms "These are the charge terms" | ||
|> RecurringCharges.test false | ||
|> RecurringCharges.test true | ||
|> RecurringCharges.toRawPropertyNames | ||
let expected = Map [ | ||
"capped_amount" => 5.0M | ||
"name" => "My Charge" | ||
"price" => 1.17M | ||
"return_url" => "https://example.com/activate-charge" | ||
"terms" => "These are the charge terms" | ||
"test" => true | ||
] | ||
|
||
Assert.Equal(expected, JsonValue.MapPropertyValuesToObjects dictionary) |
Oops, something went wrong.