ballast-0.1.0.0: tests/tests.hs
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
module Main where
import Ballast.Client
import Ballast.Types
import Data.Maybe (fromJust)
import Data.Monoid ((<>))
import qualified Data.Text as T
import Data.Time (Day(..), secondsToDiffTime)
import Data.Time.Clock (UTCTime(..), getCurrentTime, utctDayTime)
import Test.Hspec
import Test.Hspec.Expectations.Contrib (isRight)
mkGetRate :: RateOptions -> RateOrder -> GetRate
mkGetRate ropts rord = GetRate ropts rord
exampleItems :: SKU -> Items
exampleItems productSku = [ItemInfo ((productSku), Quantity 5)]
exampleShipTo :: ShipTo
exampleShipTo =
ShipTo
(AddressLine "6501 Railroad Avenue SE")
(AddressLine "Room 315")
(AddressLine "")
(City "Snoqualmie")
(PostalCode "85283")
(Region "WA")
(Country "US")
Commercial
NotPoBox
exampleCreateReceiving :: SKU -> CreateReceiving
exampleCreateReceiving productSku =
CreateReceiving
Nothing
Nothing
(Just $ ExpectedDate $ UTCTime (ModifiedJulianDay 155000) (secondsToDiffTime 10))
(ReceivingOptions Nothing Nothing $ Just $ WarehouseRegion "TEST 1")
(ReceivingArrangement
ArrangementTypeNone
Nothing
Nothing)
(ReceivingShipments
[ReceivingShipment Nothing Nothing Nothing Nothing $ Type "box"])
Nothing
Nothing
(ReceivingItems [ReceivingItem (productSku) (Quantity 5)])
(ReceivingShipFrom
Nothing
(Name "Stephen Alexander")
(AddressLine "11 Prsilla St")
Nothing
(City "New York")
(State "NY")
(PostalCode "12345")
(Country "USA")
(Phone "12346"))
Nothing
exampleBadCreateReceiving :: CreateReceiving
exampleBadCreateReceiving =
CreateReceiving
Nothing
Nothing
(Just $ ExpectedDate $ UTCTime (ModifiedJulianDay 100000) (secondsToDiffTime 10))
(ReceivingOptions Nothing Nothing $ Just $ WarehouseRegion "TEST 1")
(ReceivingArrangement
ArrangementTypeNone
Nothing
Nothing)
(ReceivingShipments
[ReceivingShipment Nothing Nothing Nothing Nothing $ Type "box"])
Nothing
Nothing
(ReceivingItems [ReceivingItem (SKU "HspecTest8") (Quantity 0)])
(ReceivingShipFrom
Nothing
(Name "Stephen Alexander")
(AddressLine "11 Prsilla St")
Nothing
(City "New York")
(State "NY")
(PostalCode "12345")
(Country "TestCountry")
(Phone "12346"))
Nothing
exampleModifiedReceiving :: ModifyReceiving
exampleModifiedReceiving =
CreateReceiving
Nothing
Nothing
(Just $ ExpectedDate $ UTCTime (ModifiedJulianDay 100000) (secondsToDiffTime 10))
(ReceivingOptions Nothing Nothing $ Just $ WarehouseRegion "TEST 1")
(ReceivingArrangement
ArrangementTypeNone
Nothing
Nothing)
(ReceivingShipments
[ReceivingShipment Nothing Nothing Nothing Nothing $ Type "box"])
Nothing
Nothing
(ReceivingItems [ReceivingItem (SKU "HspecTest8") (Quantity 5)])
(ReceivingShipFrom
Nothing
(Name "Stephen Alexander")
(AddressLine "11 Prsilla St")
Nothing
(City "New York")
(State "NY")
(PostalCode "12345")
(Country "Modified Country")
(Phone "12346"))
Nothing
-- | Takes a product id as an integer and inserts it in the right spot.
exampleCreateProduct :: ProductId -> [CreateProductsWrapper]
exampleCreateProduct productId =
[CpwVirtualKit $ VirtualKit
Nothing
(SKU "HspecTestVKit")
(VirtualKitClassification)
(Description "This is a virtual kit test")
(VirtualKitContent
[(VirtualKitContentObject
(Just $ productId)
Nothing
(Quantity 5)
)
]
),
CpwKit $ Kit
Nothing
(SKU "HspecTestKit")
Nothing
(KitClassification)
(Description "This is a kit test")
(HasLooseBatteryConfiguration)
(Just $ HsCode "010612")
(Just $ CountryOfOrigin "US")
(KitValues
(CostValue 1)
(WholesaleValue 2)
(RetailValue 4)
(Just $ CostCurrency "USD")
(Just $ WholesaleCurrency "USD")
(Just $ RetailCurrency "USD")
)
(Just $ KitAlternateNames [KitAlternateName (Name "HspecTestAlt")])
-- KitContentObject needs to include ids of other products
-- included in this kit. We use a helper function to create a
-- product and get back that product's id.
(KitContent
[KitContentObject
(Just $ productId)
Nothing
(Quantity 5)
]
)
(KitDimensions
(KitLength 2)
(KitWidth 2)
(KitHeight 2)
(KitWeight 2)
)
(Just $ KitTechnicalData
(KitTechnicalDataBattery
(BatteryType "ALKALINE")
(Just $ BatteryWeight 3)
(Just $ NumberOfBatteries 5)
(Just $ Capacity 6)
(Just $ NumberOfCells 7)
(Just $ CapacityUnit "WATTHOUR")
)
)
(Nothing)
(Nothing)
(Nothing)
(Nothing),
CpwMarketingInsert $ MarketingInsert
Nothing
(SKU "HspecTestInsert3")
Nothing
(MarketingInsertClassification)
(Description "Hspec test marketing insert2")
(InclusionRuleType "CUSTOM")
(Just $ MarketingInsertAlternateNames [MarketingInsertAlternateName (Name "HspecMI3")])
(MarketingInsertDimensions
(MarketingInsertLength 0.1)
(MarketingInsertWidth 0.1)
(MarketingInsertHeight 0.1)
(MarketingInsertWeight 0.2)
)
(Nothing)
(Just $ MarketingInsertInclusionRules
(Just $ InsertAfterDate $ UTCTime (ModifiedJulianDay 160000) (secondsToDiffTime 10))
(Just $ InsertBeforeDate $ UTCTime (ModifiedJulianDay 160000) (secondsToDiffTime 10))
(Just $ InsertWhenWorthValue 5)
(Just $ InsertWhenQuantity 5)
(Just $ InsertWhenWorthCurrency "USD")
)
(MarketingInsertMasterCase
(IndividualItemsPerCase 10)
(SKU "HspecTestMIMCSKU")
Nothing
(Description "Hspec test marketing insert master case2")
(MarketingInsertMasterCaseDimensions
(MarketingInsertMasterCaseDimensionsLength 8)
(MarketingInsertMasterCaseDimensionsWidth 8)
(MarketingInsertMasterCaseDimensionsHeight 8)
(MarketingInsertMasterCaseDimensionsWeight 8)
)
),
CpwBaseProduct $ BaseProduct
Nothing
(SKU "HspecTest9")
Nothing
(BaseProductClassification)
(Description "Hspec test product2")
(Nothing)
(Nothing)
(Category "TOYS_SPORTS_HOBBIES")
(NoBatteryConfiguration)
(Values
(CostValue 1)
(Nothing)
(RetailValue 4)
(Just $ CostCurrency "USD")
(Just $ WholesaleCurrency "USD")
(Just $ RetailCurrency "USD")
)
(Nothing)
(BaseProductDimensions
(BaseProductLength 10)
(BaseProductWidth 10)
(BaseProductHeight 10)
(BaseProductWeight 10)
)
(Nothing)
(Nothing)
(Nothing)
(Nothing)
(Nothing)
]
exampleModifyProducts :: Id -> SKU -> [CreateProductsWrapper]
exampleModifyProducts i sku =
[ CpwBaseProduct $
BaseProduct
(Just i)
(sku)
(Nothing)
(BaseProductClassification)
(Description "Modified description")
(Nothing)
(Nothing)
(Category "TOYS_SPORTS_HOBBIES")
(NoBatteryConfiguration)
(Values
(CostValue 1)
(Nothing)
(RetailValue 4)
(Just $ CostCurrency "USD")
(Just $ WholesaleCurrency "USD")
(Just $ RetailCurrency "USD"))
(Nothing)
(BaseProductDimensions
(BaseProductLength 10)
(BaseProductWidth 10)
(BaseProductHeight 10)
(BaseProductWeight 10))
(Nothing)
(Nothing)
(Nothing)
(Nothing)
(Nothing)
]
exampleModifyProduct :: Id -> SKU -> CreateProductsWrapper
exampleModifyProduct prId prSku =
CpwBaseProduct $
BaseProduct
(Just prId)
(prSku)
(Nothing)
(BaseProductClassification)
(Description "Modified description")
(Nothing)
(Nothing)
(Category "TOYS_SPORTS_HOBBIES")
(NoBatteryConfiguration)
(Values
(CostValue 1)
(Nothing)
(RetailValue 4)
(Just $ CostCurrency "USD")
(Just $ WholesaleCurrency "USD")
(Just $ RetailCurrency "USD"))
(Nothing)
(BaseProductDimensions
(BaseProductLength 10)
(BaseProductWidth 10)
(BaseProductHeight 10)
(BaseProductWeight 10))
(Nothing)
(Nothing)
(Nothing)
(Nothing)
(Nothing)
exampleCreateBaseProduct :: T.Text -> [CreateProductsWrapper]
exampleCreateBaseProduct randomSecond =
[ CpwBaseProduct $
BaseProduct
Nothing
(SKU $ "HspecTest" <> randomSecond)
(Just $ ExternalId $ "hspectest" <> randomSecond)
(BaseProductClassification)
(Description "Hspec test product5")
(Just $ HsCode "010612")
(Just $ CountryOfOrigin "US")
(Category "TOYS_SPORTS_HOBBIES")
(NoBatteryConfiguration)
(Values
(CostValue 1)
(Nothing)
(RetailValue 4)
(Just $ CostCurrency "USD")
(Just $ WholesaleCurrency "USD")
(Just $ RetailCurrency "USD"))
(Nothing)
(BaseProductDimensions
(BaseProductLength 10)
(BaseProductWidth 10)
(BaseProductHeight 10)
(BaseProductWeight 10))
(Nothing)
(Just $ BaseProductFlags
(PackagedReadyToShip)
(NotFragile)
(NotDangerous)
(NotPerishable)
(NotMedia)
(NotAdult)
(NotLiquid)
(NoInnerPack)
(NoMasterCase)
(NoPallet))
(Nothing)
(Nothing)
(Nothing)
]
exampleCreateMarketingInsert :: [CreateProductsWrapper]
exampleCreateMarketingInsert = [CpwMarketingInsert $ MarketingInsert
Nothing
(SKU "HspecTestInsert3")
Nothing
(MarketingInsertClassification)
(Description "Hspec test marketing insert3")
(InclusionRuleType "CUSTOM")
(Just $ MarketingInsertAlternateNames [MarketingInsertAlternateName (Name "HspecMI33")])
(MarketingInsertDimensions
(MarketingInsertLength 0.1)
(MarketingInsertWidth 0.1)
(MarketingInsertHeight 0.1)
(MarketingInsertWeight 0.2)
)
(Nothing)
(Just $ MarketingInsertInclusionRules
(Just $ InsertAfterDate $ UTCTime (ModifiedJulianDay 150000) (secondsToDiffTime 10))
(Just $ InsertBeforeDate $ UTCTime (ModifiedJulianDay 150000) (secondsToDiffTime 10))
(Just $ InsertWhenWorthValue 5)
(Just $ InsertWhenQuantity 5)
(Just $ InsertWhenWorthCurrency "USD")
)
(MarketingInsertMasterCase
(IndividualItemsPerCase 10)
(SKU "HspecTestMIMCSKU")
Nothing
(Description "Hspec test marketing insert master case2")
(MarketingInsertMasterCaseDimensions
(MarketingInsertMasterCaseDimensionsLength 8)
(MarketingInsertMasterCaseDimensionsWidth 8)
(MarketingInsertMasterCaseDimensionsHeight 8)
(MarketingInsertMasterCaseDimensionsWeight 8)
)
)
]
exampleOrder :: T.Text -> SKU -> CreateOrder
exampleOrder randomPart productSku =
CreateOrder
Nothing
(Just $ OrderNo (T.concat ["testorder", randomPart]))
Nothing
Nothing
(Just $ CreateOrderOptions
(Just $ WarehouseId 10281)
(Nothing)
(Nothing)
(Nothing)
(DomesticOneDay)
(Nothing)
(NotSameDay)
(Just $ DontForceDuplicate)
(Just $ DontForceAddress)
(Nothing)
(Nothing)
(Nothing)
(USD)
(Nothing)
(Nothing)
(Nothing)
(Nothing)
(Nothing)
(Nothing)
)
Nothing
(OrderShipTo
(Just $ Email "test@example.com")
(Name "Test Person")
(Just $ Company "Best Company")
(AddressLine "First line")
(Just $ AddressLine "Second line 25")
(Just $ AddressLine "")
(City "Best city")
(State "WA")
(Just $ PostalCode "100100")
(Country "US")
(Phone "6315613729")
(NotCommercial)
(Just $ NotPoBox)
)
Nothing
Nothing
(OrderItems [OrderItem (Just $ CommercialInvoiceValue 4.5) (Just $ CommercialInvoiceValueCurrency "USD") (Quantity 5) (productSku)])
exampleAddress :: AddressToValidate
exampleAddress = OrderShipTo
(Just $ Email "test@example.com")
(Name "Test Person")
(Just $ Company "My Company")
(AddressLine "3351 Michelson Dr STE 100")
(Nothing)
(Nothing)
(City "Irvine")
(State "CA")
(Just $ PostalCode "92612-0697")
(Country "US")
(Phone "8885551212")
(Commercial)
(Nothing)
createReceivingHelper :: ShipwireConfig -> CreateReceiving -> IO (Either ShipwireError (ShipwireReturn CreateReceivingRequest), ReceivingId)
createReceivingHelper conf cr = do
receiving <- shipwire conf $ createReceiving cr
let Right ReceivingsResponse {..} = receiving
ReceivingsResource {..} = receivingsResponseResource
ReceivingsItems {..} = receivingsResponseItems
ReceivingsItem {..} = last unReceivingsItems
ReceivingsItemResource {..} = receivingsItemResource
receivingId = T.pack $ show $ unId rirId
return (receiving, ReceivingId receivingId)
createBaseProductHelper :: ShipwireConfig -> [CreateProductsWrapper] -> IO (Either ShipwireError (ShipwireReturn CreateProductsRequest), Id, SKU)
createBaseProductHelper conf cp = do
baseProduct <- shipwire conf $ createProduct cp
let Right GetProductsResponse {..} = baseProduct
GetProductsResponseResource {..} = gprResource
GetProductsResponseResourceItems {..} = gprrItems
GetProductsResponseResourceItem {..} = last gprriItems
pwBaseProduct@(PwBaseProduct _) = gprriResource
productId = bprId $ unwrapBaseProduct pwBaseProduct
productSku = bprSku $ unwrapBaseProduct pwBaseProduct
return (baseProduct, productId, productSku)
createMarketingInsertHelper :: ShipwireConfig -> [CreateProductsWrapper] -> IO (Either ShipwireError (ShipwireReturn CreateProductsRequest), Id)
createMarketingInsertHelper conf cp = do
marketingInsert <- shipwire conf $ createProduct cp
let Right GetProductsResponse {..} = marketingInsert
GetProductsResponseResource {..} = gprResource
GetProductsResponseResourceItems {..} = gprrItems
GetProductsResponseResourceItem {..} = last gprriItems
pwMarketingInsert@(PwMarketingInsert _) = gprriResource
productId = mirId $ unwrapMarketingInsert pwMarketingInsert
return (marketingInsert, productId)
createOrderHelper :: ShipwireConfig -> CreateOrder -> IO (Either ShipwireError (ShipwireReturn CreateOrderRequest), Id)
createOrderHelper conf co = do
order <- shipwire conf $ createOrder co
exampleOrd <- shipwire conf $ getOrders -&- (OrderNoParam $ getOrderNo co)
let Right GetOrdersResponse {..} = exampleOrd
GetOrdersResponseResource {..} = gorResource
GetOrdersResponseResourceItems {..} = gorrItems
GetOrdersResponseResourceItem {..} = head $ gorriItems
GetOrdersResponseResourceItemResource {..} = gorriResource
proId = gorrirId
return (order, proId)
getOrderNo :: CreateOrder -> [T.Text]
getOrderNo co = (unOrderNo $ fromJust $ coOrderNo co) : []
getTimestamp :: IO T.Text
getTimestamp = do
x <- getCurrentTime
let prec = show $ utctDayTime x
result = T.pack $ takeWhile (/= '.') . reverse $ prec
return result
-- | This function unwraps the wrappers for each type of product and gets all of those products' ids
-- It helps retire the products to clean up after the tests.
getProductIds :: GetProductsResponse -> IO [Integer]
getProductIds products = do
let getProductsResponseResource = gprResource products
getProductsResponseResourceItems = gprrItems getProductsResponseResource
responseResourceItems = gprriItems getProductsResponseResourceItems
productWrappers = map gprriResource responseResourceItems
unwrappedBaseProducts = unwrapPwBaseProduct productWrappers
unwrappedMarketingInserts = unwrapPwMarketingInsert productWrappers
unwrappedKits = unwrapPwKit productWrappers
unwrappedVirtualKits = unwrapPwVirtualKit productWrappers
baseProductIds = map (unId . bprId) unwrappedBaseProducts
marketingInsertIds = map (unId . mirId) unwrappedMarketingInserts
kitIds = map (unId . krId) unwrappedKits
virtualKitIds = map (unId . vkrId) unwrappedVirtualKits
allIds = baseProductIds <> marketingInsertIds <> kitIds <> virtualKitIds
return allIds
getModifiedProductsIds :: ModifyProductsResponse -> IO [Integer]
getModifiedProductsIds products = do
let getProductsResponseResource = mprResource products
getProductsResponseResourceItems = gprrItems getProductsResponseResource
responseResourceItems = gprriItems getProductsResponseResourceItems
productWrappers = map gprriResource responseResourceItems
unwrappedBaseProducts = unwrapPwBaseProduct productWrappers
unwrappedMarketingInserts = unwrapPwMarketingInsert productWrappers
unwrappedKits = unwrapPwKit productWrappers
unwrappedVirtualKits = unwrapPwVirtualKit productWrappers
baseProductIds = map (unId . bprId) unwrappedBaseProducts
marketingInsertIds = map (unId . mirId) unwrappedMarketingInserts
kitIds = map (unId . krId) unwrappedKits
virtualKitIds = map (unId . vkrId) unwrappedVirtualKits
allIds = baseProductIds <> marketingInsertIds <> kitIds <> virtualKitIds
return allIds
getAllReceivingsIds :: ReceivingsResponse -> IO [Integer]
getAllReceivingsIds rr = do
let receivingsResource = receivingsResponseResource rr
receivingsItems = receivingsResponseItems receivingsResource
ids = map (unId . rirId . receivingsItemResource) $ unReceivingsItems receivingsItems
return ids
-- dumpStuff = do
-- t <- getCurrentTimeInSeconds
-- let result = encode $ exampleOrder t
-- return result
-- tryStuff = do
-- let t = "123" :: T.Text
-- config <- sandboxEnvConfig
-- randomPart <- getTimestamp
-- (_, productId) <- createBaseProductHelper config exampleCreateBaseProduct
-- (result, productId, _) <- createBaseProductHelper config $ exampleCreateBaseProduct randomPart
-- return result
-- seeStuff = do
-- config <- sandboxEnvConfig
-- (_, productId) <- createBaseProductHelper config exampleCreateBaseProduct
-- randomPart <- getCurrentTimeInSeconds
-- (_, orderId) <- createOrderHelper config $ exampleOrder randomPart
-- result <- shipwire config $ getOrderTrackings $ WrappedId $ Id orderId
-- return result
unwrapBaseProduct :: ProductsWrapper -> BaseProductResponseResource
unwrapBaseProduct (PwBaseProduct x) = x
unwrapBaseProduct _ = error "Bad input"
unwrapMarketingInsert :: ProductsWrapper -> MarketingInsertResponseResource
unwrapMarketingInsert (PwMarketingInsert x) = x
unwrapMarketingInsert _ = error "Bad input"
unwrapPwBaseProduct :: [ProductsWrapper] -> [BaseProductResponseResource]
unwrapPwBaseProduct [] = []
unwrapPwBaseProduct ((PwBaseProduct x):xs) = x : unwrapPwBaseProduct xs
unwrapPwBaseProduct (_:xs) = unwrapPwBaseProduct xs
unwrapPwMarketingInsert :: [ProductsWrapper] -> [MarketingInsertResponseResource]
unwrapPwMarketingInsert [] = []
unwrapPwMarketingInsert ((PwMarketingInsert x):xs) = x : unwrapPwMarketingInsert xs
unwrapPwMarketingInsert (_:xs) = unwrapPwMarketingInsert xs
unwrapPwKit :: [ProductsWrapper] -> [KitResponseResource]
unwrapPwKit [] = []
unwrapPwKit ((PwKit x):xs) = x : unwrapPwKit xs
unwrapPwKit (_:xs) = unwrapPwKit xs
unwrapPwVirtualKit :: [ProductsWrapper] -> [VirtualKitResponseResource]
unwrapPwVirtualKit [] = []
unwrapPwVirtualKit ((PwVirtualKit x):xs) = x : unwrapPwVirtualKit xs
unwrapPwVirtualKit (_:xs) = unwrapPwVirtualKit xs
main :: IO ()
main = do
config <- sandboxEnvConfig
hspec $ do
describe "get rates" $ do
it "gets the correct rates" $ do
randomPart <- getTimestamp
(_, productId, productSku) <- createBaseProductHelper config $ exampleCreateBaseProduct randomPart
let getRt = mkGetRate (RateOptions USD GroupByAll Nothing Nothing Nothing (Just IgnoreUnknownSkus) CanSplit (WarehouseArea "US") Nothing Nothing Nothing) (RateOrder exampleShipTo (exampleItems productSku))
result <- shipwire config $ createRateRequest getRt
result `shouldSatisfy` isRight
_ <- shipwire config $ retireProducts $ ProductsToRetire [productId]
let Right RateResponse {..} = result
rateResponseWarnings `shouldBe` Nothing
rateResponseErrors `shouldBe` Nothing
describe "get stock info" $ do
it "gets stock info with optional args" $ do
randomPart <- getTimestamp
(_, productId, _) <- createBaseProductHelper config $ exampleCreateBaseProduct randomPart
result <- shipwire config $ getStockInfo -&- (SKU "HspecTest5")
_ <- shipwire config $ retireProducts $ ProductsToRetire [productId]
result `shouldSatisfy` isRight
let Right StockResponse {..} = result
stockResponseWarnings `shouldBe` Nothing
stockResponseErrors `shouldBe` Nothing
describe "get receivings" $ do
it "gets an itemized list of receivings with optional args" $ do
randomPart <- getTimestamp
(_, productId, productSku) <- createBaseProductHelper config $ exampleCreateBaseProduct randomPart
(_, receivingId) <- createReceivingHelper config $ exampleCreateReceiving productSku
result <- shipwire config $ getReceivings -&- (ExpandReceivingsParam [ExpandAll])
-&- (ReceivingStatusParams [StatusCanceled])
-&- (WarehouseIdParam ["TEST 1"])
-&- (UpdatedAfter $ (UTCTime (ModifiedJulianDay 88000) (secondsToDiffTime 10)))
_ <- shipwire config $ cancelReceiving receivingId
_ <- shipwire config $ retireProducts $ ProductsToRetire [productId]
result `shouldSatisfy` isRight
describe "create a new receiving" $ do
it "creates a new receiving with optional args" $ do
randomPart <- getTimestamp
(_, productId, productSku) <- createBaseProductHelper config $ exampleCreateBaseProduct randomPart
(receiving, receivingId) <- createReceivingHelper config $ exampleCreateReceiving productSku
receiving `shouldSatisfy` isRight
_ <- shipwire config $ cancelReceiving receivingId
_ <- shipwire config $ retireProducts $ ProductsToRetire [productId]
let Right ReceivingsResponse {..} = receiving
receivingsResponseErrors `shouldBe` Nothing
receivingsResponseWarnings `shouldBe` Nothing
it "doesn't create a receiving with bad JSON" $ do
randomPart <- getTimestamp
(_, productId, _) <- createBaseProductHelper config $ exampleCreateBaseProduct randomPart
result <- shipwire config $ createReceiving exampleBadCreateReceiving
_ <- shipwire config $ retireProducts $ ProductsToRetire [productId]
let Right ReceivingsResponse {..} = result
receivingsResponseErrors `shouldBe`
Just
(ResponseErrors
[ Error
(ErrorCodeText "orderSubmitFailed")
(ErrorMessage
"Item quantity too low, please insert a quantity greater than 2.")
ErrorError
])
describe "get information about a receiving" $ do
it "gets info about a receiving" $ do
randomPart <- getTimestamp
(_, productId, productSku) <- createBaseProductHelper config $ exampleCreateBaseProduct randomPart
(_, receivingId) <- createReceivingHelper config $ exampleCreateReceiving productSku
result <- shipwire config $ getReceiving receivingId -&- (ExpandReceivingsParam [ExpandHolds, ExpandItems])
result `shouldSatisfy` isRight
_ <- shipwire config $ cancelReceiving receivingId
_ <- shipwire config $ retireProducts $ ProductsToRetire [productId]
let Right ReceivingResponse {..} = result
receivingResponseErrors `shouldBe` Nothing
receivingResponseWarnings `shouldBe` Nothing
describe "modify information about a receiving" $ do
it "modifies info about a receiving" $ do
randomPart <- getTimestamp
(_, productId, productSku) <- createBaseProductHelper config $ exampleCreateBaseProduct randomPart
(_, receivingId) <- createReceivingHelper config $ exampleCreateReceiving productSku
result <- shipwire config $ modifyReceiving receivingId exampleModifiedReceiving
result `shouldSatisfy` isRight
let Right ReceivingsResponse {..} = result
receivingsResponseErrors `shouldBe` Nothing
receivingsResponseWarnings `shouldBe` Nothing
modifiedReceiving <- shipwire config $ getReceiving receivingId
_ <- shipwire config $ cancelReceiving receivingId
_ <- shipwire config $ retireProducts $ ProductsToRetire [productId]
let Right ReceivingResponse {..} = modifiedReceiving
ReceivingsItemResource {..} = receivingResponseResource
ItemResourceShipFrom {..} = rirShipFrom
ItemResourceShipFromResource {..} = irsfResource
irsfrCountry `shouldBe` Just (Country "Modified Country")
describe "cancel a receiving" $ do
it "cancels a receiving" $ do
randomPart <- getTimestamp
(_, productId, productSku) <- createBaseProductHelper config $ exampleCreateBaseProduct randomPart
(_, receivingId) <- createReceivingHelper config $ exampleCreateReceiving productSku
result <- shipwire config $ cancelReceiving receivingId
result `shouldSatisfy` isRight
_ <- shipwire config $ cancelReceiving receivingId
_ <- shipwire config $ retireProducts $ ProductsToRetire [productId]
let Right SimpleResponse {..} = result
message `shouldBe` (ResponseMessage "Receiving was cancelled")
describe "cancel shipping labels" $ do
it "cancels shipping labels on a receiving" $ do
randomPart <- getTimestamp
(_, productId, productSku) <- createBaseProductHelper config $ exampleCreateBaseProduct randomPart
(_, receivingId) <- createReceivingHelper config $ exampleCreateReceiving productSku
result <- shipwire config $ cancelReceivingLabels receivingId
result `shouldSatisfy` isRight
_ <- shipwire config $ cancelReceiving receivingId
_ <- shipwire config $ retireProducts $ ProductsToRetire [productId]
let Right SimpleResponse {..} = result
message `shouldBe` (ResponseMessage "Labels cancelled")
describe "get list of holds for a receiving" $ do
it "gets a list of holds for a receiving" $ do
randomPart <- getTimestamp
(_, productId, productSku) <- createBaseProductHelper config $ exampleCreateBaseProduct randomPart
(_, receivingId) <- createReceivingHelper config $ exampleCreateReceiving productSku
result <- shipwire config $ getReceivingHolds receivingId -&- IncludeCleared
result `shouldSatisfy` isRight
_ <- shipwire config $ cancelReceiving receivingId
_ <- shipwire config $ retireProducts $ ProductsToRetire [productId]
let Right GetReceivingHoldsResponse {..} = result
grhrWarnings `shouldBe` Nothing
grhrErrors `shouldBe` Nothing
describe "get email recipients and instructions for a receiving" $ do
it "gets email recipients and instructions for a receiving" $ do
randomPart <- getTimestamp
(_, productId, productSku) <- createBaseProductHelper config $ exampleCreateBaseProduct randomPart
(_, receivingId) <- createReceivingHelper config $ exampleCreateReceiving productSku
result <- shipwire config $ getReceivingInstructionsRecipients receivingId
result `shouldSatisfy` isRight
_ <- shipwire config $ cancelReceiving receivingId
_ <- shipwire config $ retireProducts $ ProductsToRetire [productId]
let Right GetReceivingInstructionsRecipientsResponse {..} = result
grirrWarnings `shouldBe` Nothing
grirrErrors `shouldBe` Nothing
describe "get contents of a receiving" $ do
it "gets contents of a receiving" $ do
randomPart <- getTimestamp
(_, productId, productSku) <- createBaseProductHelper config $ exampleCreateBaseProduct randomPart
(_, receivingId) <- createReceivingHelper config $ exampleCreateReceiving productSku
result <- shipwire config $ getReceivingItems receivingId
result `shouldSatisfy` isRight
_ <- shipwire config $ cancelReceiving receivingId
_ <- shipwire config $ retireProducts $ ProductsToRetire [productId]
let Right GetReceivingItemsResponse {..} = result
grirWarnings `shouldBe` Nothing
grirErrors `shouldBe` Nothing
describe "get shipping dimension and container information" $ do
it "gets shipping dimension and container infromation" $ do
randomPart <- getTimestamp
(_, productId, productSku) <- createBaseProductHelper config $ exampleCreateBaseProduct randomPart
(_, receivingId) <- createReceivingHelper config $ exampleCreateReceiving productSku
result <- shipwire config $ getReceivingShipments receivingId
result `shouldSatisfy` isRight
_ <- shipwire config $ cancelReceiving receivingId
_ <- shipwire config $ retireProducts $ ProductsToRetire [productId]
let Right GetReceivingShipmentsResponse {..} = result
grsrWarnings `shouldBe` Nothing
grsrErrors `shouldBe` Nothing
describe "get tracking information for a receiving" $ do
it "gets tracking information for a receiving" $ do
randomPart <- getTimestamp
(_, productId, productSku) <- createBaseProductHelper config $ exampleCreateBaseProduct randomPart
(_, receivingId) <- createReceivingHelper config $ exampleCreateReceiving productSku
result <- shipwire config $ getReceivingTrackings receivingId
result `shouldSatisfy` isRight
_ <- shipwire config $ cancelReceiving receivingId
_ <- shipwire config $ retireProducts $ ProductsToRetire [productId]
let Right GetReceivingTrackingsResponse {..} = result
grtrWarnings `shouldBe` Nothing
grtrErrors `shouldBe` Nothing
describe "get labels information for a receiving" $ do
it "gets labels information for a receiving" $ do
randomPart <- getTimestamp
(_, productId, productSku) <- createBaseProductHelper config $ exampleCreateBaseProduct randomPart
(_, receivingId) <- createReceivingHelper config $ exampleCreateReceiving productSku
result <- shipwire config $ getReceivingLabels receivingId
result `shouldSatisfy` isRight
_ <- shipwire config $ cancelReceiving receivingId
_ <- shipwire config $ retireProducts $ ProductsToRetire [productId]
let Right GetReceivingLabelsResponse {..} = result
grlrWarnings `shouldBe` Nothing
grlrErrors `shouldBe` Nothing
describe "get an itemized list of products" $ do
it "gets an itemized list of products" $ do
randomPart <- getTimestamp
(_, productId, _) <- createBaseProductHelper config $ exampleCreateBaseProduct randomPart
result <- shipwire config $ getProducts -&- (ExpandProductsParam [ExpandEnqueuedDimensions])
result `shouldSatisfy` isRight
_ <- shipwire config $ retireProducts $ ProductsToRetire [productId]
let Right GetProductsResponse {..} = result
gprWarnings `shouldBe` Nothing
gprErrors `shouldBe` Nothing
describe "create a product" $ do
it "creates all possible product classifications" $ do
randomPart <- getTimestamp
(prd, productId, _) <- createBaseProductHelper config $ exampleCreateBaseProduct randomPart
prd `shouldSatisfy` isRight
let Right GetProductsResponse {..} = prd
_ <- shipwire config $ retireProducts $ ProductsToRetire [productId]
gprWarnings `shouldBe` Nothing
gprErrors `shouldBe` Nothing
describe "modify products" $ do
it "modifies several previously created products" $ do
randomPart <- getTimestamp
(_, productId, productSku) <- createBaseProductHelper config $ exampleCreateBaseProduct randomPart
result <- shipwire config $ modifyProducts $ exampleModifyProducts productId productSku
result `shouldSatisfy` isRight
let Right ModifyProductsResponse {..} = result
_ <- shipwire config $ retireProducts $ ProductsToRetire [productId]
mprWarnings `shouldBe` Nothing
mprErrors `shouldBe` Nothing
describe "modify a product" $ do
it "modifies a single product" $ do
randomPart <- getTimestamp
(_, productId, productSku) <- createBaseProductHelper config $ exampleCreateBaseProduct randomPart
result <- shipwire config $ modifyProduct (exampleModifyProduct productId productSku) productId
result `shouldSatisfy` isRight
let Right ModifyProductsResponse {..} = result
_ <- shipwire config $ retireProducts $ ProductsToRetire [productId]
mprWarnings `shouldBe` Nothing
mprErrors `shouldBe` Nothing
describe "get a product" $ do
it "gets information about a single product" $ do
randomPart <- getTimestamp
(_, productId, _) <- createBaseProductHelper config $ exampleCreateBaseProduct randomPart
result <- shipwire config $ getProduct productId
result `shouldSatisfy` isRight
_ <- shipwire config $ retireProducts $ ProductsToRetire [productId]
let Right GetProductResponse {..} = result
gpreStatus `shouldNotBe` (ResponseStatus 404)
gpreWarnings `shouldBe` Nothing
gpreErrors `shouldBe` Nothing
describe "retire a product" $ do
it "retires a product" $ do
(_, anotherProductId) <- createMarketingInsertHelper config exampleCreateMarketingInsert
result <- shipwire config $ retireProducts $ ProductsToRetire [anotherProductId]
let Right RetireProductsResponse {..} = result
MoreInfo {..} = fromJust $ rprMoreInfo
MoreInfoItems {..} = last miItems
MoreInfoItem {..} = last miiItems
status@Status {..} = miiStatus
result `shouldSatisfy` isRight
status `shouldBe` Status "deprecated"
describe "create an order" $ do
it "creates an order" $ do
randomPart <- getTimestamp
(_, productId, productSku) <- createBaseProductHelper config $ exampleCreateBaseProduct randomPart
(result, orderId) <- createOrderHelper config $ exampleOrder randomPart productSku
_ <- shipwire config $ cancelOrder $ WrappedId $ orderId
_ <- shipwire config $ retireProducts $ ProductsToRetire [productId]
result `shouldSatisfy` isRight
let Right GetOrdersResponse {..} = result
gorWarnings `shouldBe` Nothing
gorErrors `shouldBe` Nothing
describe "get orders" $ do
it "gets all the orders" $ do
randomPart <- getTimestamp
(_, productId, productSku) <- createBaseProductHelper config $ exampleCreateBaseProduct randomPart
(_, orderId) <- createOrderHelper config $ exampleOrder randomPart productSku
result <- shipwire config $ getOrders
_ <- shipwire config $ cancelOrder $ WrappedId $ orderId
_ <- shipwire config $ retireProducts $ ProductsToRetire [productId]
result `shouldSatisfy` isRight
let Right GetOrdersResponse {..} = result
gorWarnings `shouldBe` Nothing
gorErrors `shouldBe` Nothing
describe "get an order" $ do
it "gets an information about an order" $ do
randomPart <- getTimestamp
(_, productId, productSku) <- createBaseProductHelper config $ exampleCreateBaseProduct randomPart
(_, orderId) <- createOrderHelper config $ exampleOrder randomPart productSku
result <- shipwire config $ getOrder $ WrappedId $ orderId
_ <- shipwire config $ cancelOrder $ WrappedId $ orderId
_ <- shipwire config $ retireProducts $ ProductsToRetire [productId]
result `shouldSatisfy` isRight
let Right GetOrderResponse {..} = result
goreWarnings `shouldBe` Nothing
goreErrors `shouldBe` Nothing
describe "cancel an order" $ do
it "cancels an order" $ do
randomPart <- getTimestamp
(_, productId, productSku) <- createBaseProductHelper config $ exampleCreateBaseProduct randomPart
(_, orderId) <- createOrderHelper config $ exampleOrder randomPart productSku
result <- shipwire config $ cancelOrder $ WrappedId $ orderId
_ <- shipwire config $ retireProducts $ ProductsToRetire [productId]
result `shouldSatisfy` isRight
let Right SimpleResponse {..} = result
warnings `shouldBe` Nothing
errors `shouldBe` Nothing
message `shouldBe` (ResponseMessage "Order cancelled")
describe "get tracking information for this order" $ do
it "gets tracking information for this order" $ do
randomPart <- getTimestamp
(_, productId, productSku) <- createBaseProductHelper config $ exampleCreateBaseProduct randomPart
(_, orderId) <- createOrderHelper config $ exampleOrder randomPart productSku
result <- shipwire config $ getOrderTrackings $ WrappedId $ orderId
_ <- shipwire config $ cancelOrder $ WrappedId $ orderId
_ <- shipwire config $ retireProducts $ ProductsToRetire [productId]
result `shouldSatisfy` isRight
let Right GetOrderTrackingsResponse {..} = result
gotrWarnings `shouldBe` Nothing
gotrErrors `shouldBe` Nothing
describe "validate address" $ do
it "validates an address" $ do
result <- shipwire config $ validateAddress exampleAddress
result `shouldSatisfy` isRight
let Right ValidateAddressResponse {..} = result
varMessage `shouldBe` (ResponseMessage "The address provided is valid")
varWarnings `shouldBe` Nothing
varErrors `shouldBe` Nothing