Skip to content

Commit

Permalink
Merge pull request #29 from nozzlegear/master
Browse files Browse the repository at this point in the history
Merging nozzlegear/master
  • Loading branch information
clement911 committed Jan 7, 2020
2 parents a7d818a + 14e56bc commit c1c6c1e
Show file tree
Hide file tree
Showing 28 changed files with 1,243 additions and 18 deletions.
102 changes: 102 additions & 0 deletions ShopifySharp.Experimental.Tests/ApplicationCreditTest.fs
@@ -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)


107 changes: 107 additions & 0 deletions ShopifySharp.Experimental.Tests/ChargeTest.fs
@@ -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)
3 changes: 0 additions & 3 deletions ShopifySharp.Experimental.Tests/JsonValueTests.fs
@@ -1,11 +1,8 @@
module JsonValueTests

open System.Collections.Generic
open Xunit
open ShopifySharp.Experimental

let inline private (=>) a b = a, box b

[<Fact>]
let ``Serializes raw integer value`` () =
let value = JsonValue.Int 5
Expand Down
1 change: 0 additions & 1 deletion ShopifySharp.Experimental.Tests/OrderTest.fs
Expand Up @@ -5,7 +5,6 @@ open System.Threading.Tasks
open Xunit
open ShopifySharp.Experimental

let inline private (=>) a b = a, box b
let private service = Orders.Service.NewService "https://example.myshopify.com" "test token"

type UpdateFunction = (int64 * Orders.OrderProperties) -> Task<ShopifySharp.Order>
Expand Down
138 changes: 138 additions & 0 deletions ShopifySharp.Experimental.Tests/RecurringChargeTest.fs
@@ -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)

0 comments on commit c1c6c1e

Please sign in to comment.