Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test that only decodes. #7

Open
scott-fleischman opened this issue Dec 17, 2019 · 1 comment
Open

Test that only decodes. #7

scott-fleischman opened this issue Dec 17, 2019 · 1 comment

Comments

@scott-fleischman
Copy link

scott-fleischman commented Dec 17, 2019

It may be useful for backward-compatibility or forward-compatibility to just test whether you can successfully decode JSON, without trying to test the matching encoding.

Example:

  AesonSpec_Jest.test ("alarmState missing person: ") (fun () ->
    let json = Js.Json.parseExn (Node.Fs.readFileAsUtf8Sync "alarm-golden/AlarmState_MissingPerson.json") in
    let _ = Aeson.Decode.list (fun a -> Aeson.Decode.unwrapResult (OnpingFrontendTypes.decodeAlarmState a)) json
    in AesonSpec_Jest.Ok
  )

This example assumes there is a list of inner decoders we really want to test. But it might be worth considering only making the function test the exact decoding shape and if you call it you can wrap i t in Aeson.Decode.list yourself. We could also provide a couple common decoding functions, one as a list and one as a sample (much like the current functions, but those aren't framed as a test).

@scott-fleischman
Copy link
Author

Something like

testDecode
testDecodeList
testDecodeSample

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant