Testing Update Operation
Learn how to test Update operation in Elixir.
We'll cover the following...
We'll cover the following...
Testing update is a combination of the testing for the create and read functions.
The Update function
Let’s first look at the function we’re going to test:
Like create/1, we can see that this function is a very lightweight wrapper around calls to the schema’s changeset function (update_changeset/2 in this case) and then to Repo.update/1.
Tests
Testing the update function will be similar, but we’ll need to insert an existing user to be updated by the code.
Let’s write our success test first:
Let’s take a look at this test:
- The test uses the factory to insert a user in line 6.
- In the instruction starting from line 8, the test is creating a parameter map to pass in. It’s using the