unlogic
I have a Phoenix application that is provides a standard REST API. I currently have two models and am looking at unit-testing. One of my controller’s unit tests is passing fine, but the other is showing some off behaviour in the update and create tests.
- Update with valid data isn’t updating the data and returns
{"errors":{"comment":["can't be blank"],"control":["can't be blank"],"value":["can't be blank"]}} - Update with invalid data isn’t erroring and returning the entry
- Create with valid data is doing what the invalid case should do and returning 422 with
{"errors":{"comment":["can't be blank"],"control":["can't be blank"],"value":["can't be blank"]}}
These are generated tests, as are those for the other controller which are working fine. I’d be OK with this if the controller wasn’t working as expected, but when running the queries manually from a REST client, the application behaves as expected in all three cases.
Here’s the
- unit test https://www.paste.in/aIwZpZ
- Controller https://www.paste.in/LFb2CW
- Model https://www.paste.in/XFpqij
Note that I have dropped the ["data"] part of the response. This is the case for the other controller too, where the tests are passing fine.
Trending in Questions
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
Hello!
Could someone please give me a help/sample code, how to delete a file from s3 using waffle/waffle_ecto from Phoenix app.
I creat...
New
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
So my question is quite simple and i have found no conclusive answer on forum, google or AI.
Should we use :erlang.float for Integer to ...
New
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New
apply_graft/2 doesn’t rewrite an add_many sub-workflow’s deps on an add step. Grafted jobs cancel with “upstream job was deleted”
Version...
New
Other Trending Topics
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
Hobbes is a low-level distributed database for the Elixir programming language.
Hobbes provides a simple, safe, and scalable storage lay...
New
Hi there! We created Gust: A task orchestrator inspired by Airflow.
For those who have never heard about Aiflow, it’s a Python-based wor...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve.
They are GUI (Emerge) and State management (S...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixirconf-us
- #blog-post
- #ai
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming










Showing Posts 1 to 5- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
al2o3cr
Can you post the controller code? The link labeled “Controller” above is actually a schema module.
I have zero evidence to support this, but my suspicion is that the controller doesn’t agree with the test about what key to use in the params.
unlogic
Sorry, that was the wrong paste
So if I understand your comment correctly, it’s not using the correct primary key? I’m just very confused about why these three test cases aren’t working as expected, but they are the same as the other model/controller I have set up.
thanks for the help so far though
al2o3cr
Try dumping out what you’re getting in
job_control_paramshere when you run the tests. Does it match whatJobControls.create_job_control/1expects?I don’t believe it will:
create_job_controlis called fromfixture(:job_control)with parameters shaped likebut in the tests this code:
will pass (unless
use FarmqWeb, :controlleris doing something nonstandard) parameters shaped like:castwill ignore parameters it doesn’t understand, so it will filter out ALL the input here.A typical idiom in controller actions looks like:
unlogic
I forgot to mention that I updated the original comment with the controller code. The controller code is the same for this controller as well as the other one. I also think that I didn’t edit the create function either.
So I think that the update function is as expected. I printed the contents of
job_control_paramsand it’s what I’d expect it to beI’d be less confused if my other controller/tests didn’t pass and if using the API via a client wasn’t working as expected
unlogic
Found the issue. You were absolutely correct in your assumption about the controller being odd. For whatever reason, in the erroring controller I had
def update(conn, job_control_params) doinstead of
def update(conn, %{"job_control" => job_control_params}) doSame for the create function. Not sure why it was like this but I’ve fixed it now and the tests pass.
Thanks for the help!