defmodule Microwaveprop.Pskr.FeatureBinTest do use Microwaveprop.DataCase, async: true alias Microwaveprop.Pskr.FeatureBin describe "changeset/2" do test "valid attrs produce a valid changeset" do attrs = %{ run_id: Ecto.UUID.generate(), band: "10000", feature: "pwat_mm", bin_label: "25-40", sample_count: 100 } changeset = FeatureBin.changeset(%FeatureBin{}, attrs) assert changeset.valid? end test "missing required fields makes changeset invalid" do changeset = FeatureBin.changeset(%FeatureBin{}, %{}) refute changeset.valid? assert "can't be blank" in errors_on(changeset).run_id assert "can't be blank" in errors_on(changeset).band assert "can't be blank" in errors_on(changeset).feature assert "can't be blank" in errors_on(changeset).bin_label end test "spot count fields are not required" do attrs = %{ run_id: Ecto.UUID.generate(), band: "10000", feature: "pwat_mm", bin_label: "<15", sample_count: 50 } changeset = FeatureBin.changeset(%FeatureBin{}, attrs) assert changeset.valid? end test "accepts optional float fields" do attrs = %{ run_id: Ecto.UUID.generate(), band: "144", feature: "hpbl_m", bin_label: "250-500", sample_count: 30, bin_min: 250.0, bin_max: 500.0, spot_count_avg: 3.5, spot_count_p50: 3.0, spot_count_p90: 8.0 } changeset = FeatureBin.changeset(%FeatureBin{}, attrs) assert changeset.valid? assert get_change(changeset, :bin_min) == 250.0 end end end