mardi 19 mars 2019

what will be a better approach to StreamData when one has 2 maps?

The following property test is working fine, however, I think there should be a better and more efficient way of implementing this.

params in the following property will be something like this:

%{
  "project_id" => "%&!XX!hLCfsS-dO_<fy?kpi4y=AEumQ$Xn:#.7Fl TnH~k>ZLB[q",
  "task_id" => [
    %{"asset_id" => 10, "tasks" => []},
    %{"asset_id" => 10, "tasks" => []}
  ]
}


Property Testing:

   property "bad project value" do
      [user, project] = prepare()
      user_gen = constant(%{id: user.id})

      project_gen =  constant("project_id")
                     |> map_of(Factory.my_terms, length: 1)

      tasks = constant(%{"asset_id" => 10, "tasks" => []})
             |> list_of(length: 2)
      tasks_gen = constant("task_id")
                  |> map_of(tasks, length: 1)

      check all project <- project_gen, task <- tasks_gen , user <- user_gen do
        params = Map.merge(project, task)
        res = ProjectTask.Save.save(params, user)
        assert res == {:error, :not_found}
      end


Factory.my_terms is the following:

  def my_terms() do
    one_of([string(:alphanumeric), string(:ascii), atom(:alphanumeric), integer(), binary()])
  end

Aucun commentaire:

Enregistrer un commentaire