Last active
June 20, 2019 16:30
-
-
Save jouderianjr/1a04accf83814f1a0840d15d17c72645 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
---------------------------------------------------------------------- | |
-- Type | |
type alias Package = | |
{ id : String | |
, deliverySlot : DeliverySlot | |
, deliveryAddress : Address | |
, pickupAddress : Address | |
, status : String | |
, tenantId : String | |
, actorId : String | |
, barcode : Maybe String | |
, currentLocationId : Maybe String | |
, description : Maybe String | |
, driverId : Maybe String | |
, height : Maybe Float | |
, length : Maybe Float | |
, reference : Maybe String | |
, sku : Maybe String | |
, url : Maybe String | |
, units : Maybe Int | |
, volume : Maybe Float | |
, weight : Maybe Float | |
, width : Maybe Float | |
, createdAt : Posix | |
, updatedAt : Posix | |
} | |
decoder : Decoder Package | |
decoder = | |
succeed Package | |
|> required "id" string | |
|> required "delivery_slot" deliverySlotDecoder | |
|> required "delivery_address" Address.decoder | |
|> required "pickup_address" Address.decoder | |
|> required "status" string | |
|> required "tenant_id" string | |
|> required "actor_id" string | |
|> optional "barcode" (nullable string) Nothing | |
|> optional "current_location_id" (nullable string) Nothing | |
|> optional "description" (nullable string) Nothing | |
|> optional "driver_id" (nullable string) Nothing | |
|> optional "height" (nullable float) Nothing | |
|> optional "length" (nullable float) Nothing | |
|> optional "reference" (nullable string) Nothing | |
|> optional "sku" (nullable string) Nothing | |
|> optional "url" (nullable string) Nothing | |
|> optional "units" (nullable int) Nothing | |
|> optional "volume" (nullable float) Nothing | |
|> optional "weight" (nullable float) Nothing | |
|> optional "width" (nullable float) Nothing | |
|> required "created_at" Iso8601.decoder | |
|> required "updated_at" Iso8601.decoder | |
---------------------------------------------------------------------- | |
---------------------------------------------------------------------- | |
-- Test example | |
baseJson : List ( String, Value ) | |
baseJson = | |
let | |
dateObject = | |
Encode.string "2019-04-16T14:26:05.215056Z" | |
in | |
[ ( "id", Encode.string "dummyId" ) | |
, ( "status", Encode.string "dummyId" ) | |
, ( "actor_id", Encode.string "dummyActorId" ) | |
, ( "tenant_id", Encode.string "dummyTenantId" ) | |
, ( "pickup_address", Encode.object FixturesAddress.baseJson ) | |
, ( "delivery_address", Encode.object FixturesAddress.baseJson ) | |
, ( "created_at", dateObject ) | |
, ( "updated_at", dateObject ) | |
, ( "delivery_slot" | |
, Encode.object | |
[ ( "start", dateObject ) | |
, ( "end", dateObject ) | |
] | |
) | |
] | |
tests : Test | |
tests = | |
describe "Package" | |
[ describe "decode" | |
[ test "with the minimum data" <| | |
\_ -> | |
Decode.decodeString decoder (Json.toJson baseJson) | |
|> Expect.ok | |
, Json.fromJson "Package fields" baseJson decoder | |
|> Json.required "id" | |
|> Json.requiredObject "delivery_slot" | |
|> Json.required "delivery_address" | |
|> Json.required "pickup_address" | |
|> Json.required "status" | |
|> Json.required "tenant_id" | |
|> Json.required "actor_id" | |
|> Json.required "created_at" | |
|> Json.required "updated_at" | |
|> Json.optionalString "barcode" | |
|> Json.optionalString "current_location_id" | |
|> Json.optionalString "description" | |
|> Json.optionalString "driver_id" | |
|> Json.optionalFloat "height" | |
|> Json.optionalFloat "length" | |
|> Json.optionalString "reference" | |
|> Json.optionalString "sku" | |
|> Json.optionalString "url" | |
|> Json.optionalInt "units" | |
|> Json.optionalFloat "volume" | |
|> Json.optionalFloat "weight" | |
|> Json.optionalFloat "width" | |
|> Json.tests | |
] | |
] | |
-- End Test Example | |
--------------------------------------- |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment