# Bare auth test for react integration
This test uses devise_token_auth instead of the previous custom solution to handle user authentication.
Once you bundle install
you will still need to rails db:create
so PG can create a new DB.
To start the API and React server run rake start
. Note if you start the server with rails s
it will default to :3000
.
-
Start the Rails server with
rake start
-
Load Postman and
POST
a new user toapi.lvh.me:3001/auth
with the body parameters:
{
"email": "firstuser@example.com",
"password": "password",
"password_confirmation": "password",
"confirm_success_url": "nil"
}
The server will return a 500 error because there is not template, but the user is created.
- Open the console and confirm the user
>> u = User.first
>> u.update_attributes(confirmed_at: Time.now)
- With the user confirmed you can sign in with Postman by
POST
ing toapi.lvh.me:3001/auth/sign_in
with the username and password in the body. In the headers returned you will need to include the following five with each request:
access-token
client
expiry
token-type
uid
Note The access-token
and expiry
chnage with each request. The client
token will change with each successful sign_in
. The other tokens are stable.
- Test by changing the password.
PATCH
toapi.lvh.me:3001/auth/password
. Include the five items from above in the header and in the body include:
{
"password": "passwords",
"password_confirmation": "passwords"
}
- To continue testing update the headers with the newly returned values. You can see all the end points for users with
rake routes
To test the notes function use the user you created in the first step and the most recent tokens.
POST
toapi.lvh.me:3001/notes
with the updated token info and the following in the body:
{
"created_by": "1",
"title": "I'm another note",
"clients": {
"client1": {
"name": "name 1",
"role": "role 1"
},
"client 2": {
"name": "name 2",
"role": "role 2"
}
}
}
- To test the index
GET
fromapi.lvh.me:3001/notes
with the updated token
The rest of the endpoints can be seen with rake routes