Skip to content

ChRomain/rubyTraining

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

rubyTraining

How to start it

git clone https://github.com/ChRomain/rubyTraining.git rubyTraining
cd rubyTraining
rails server

Open a browser and go in port 3000.

Routes endpoints

  • /articles: List all articles.
  • /articles/new: Create article form.
  • /articles/:id: Query a specific article.
  • /articles/:id/edit: Update a specific article.
  • /articles/:id/delete: Remove specific article.

Some routes endpoints for author also available.

Test definition

Due to time limitation test coverage is low. Just nominal case for Article geter.

  • Check title getter
  • Check body getter
  • Check author getter
  • Check published_at getter

TODO/Improvement:

  • Generate allure report
  • Add other test about corner case, exist or not, corrupted db, load testing with multiple // call...

GraphQl API

Once server is started open a browser and go in playground 3000/graphiql

TODO/Improvement

  • Block schema documentation for unauthenticated user - for secu purpose
  • Add pagination for query all items
  • Add some input validation
  • Add some server side batching
  • Take ruby naming convention (not yet known)
  • Check object imbrication - for now ok
  • Check for schema introspection blocking
  • Block auto completion
  • Tke care of alias attack ....

Authentication

You will have to be authenticated in order to play with some mutation/query. Steps:

  1. Execute logIn query:
mutation {
    signUp (
        input: {
        email: "email@email.com"
        password: "pwd"
        role: admin
        }
    ) { email role }
}
  1. LogIn with created user
mutation {
  logIn(
      input: {
        email: "email@email.com"
        password: "pwd"
      }
  ) {
    token
  }
}

If user exist a bearer will be prompt in output. Copy it and for next query/mutation add it in Headers section as follow: { "Authorization": "Bearer PREVIOUS_TOKEN" }

Query

Query all articles

query {
  articles {
    id
    title
    body
    author { name email }
    publishedAt
  }
}

Query all articles written by a specific author

query {
  articlesByAuthor (authorId: "{{authorId}}") {
    body
    id
    title
  }
}

Query a specific article

query {
  article(id: "{{articleId}}") {
    id
    title
    body
    author { name email }
    publishedAt
  }
}

Mutation

For now no input validation

Create a new article - Author must exist and be valid

mutation {
  createArticle (
    input: {
      title: "Article test",
      body: "Body test",
      authorId: "{{authorId}}",
      published_at: "2999-01-01T01:01:01Z"
    }
  ) {
    title
  }
}

Update a specific article - Article id must exist and be valid

mutation {
  updateArticle (
    input: {
      id: "{{articleId}}",
      title: "New name",
      body: "New body"
    }
  ) {
    title
  }
}

Delete a specific article by his id - Article id must exist and be valid

mutation {
  deleteArticle (
    input: {
      id: "{{articleId}}"
    }
  )
}

Subscription

None

Import script

A rake script is present under lib/tasks/. Aims of this script is to be able to register authors or articles throught csv file. Those files must be placed under lib/assets folder.

If the script fail to register one author or one article it will continue to loop over the csv and print a report with number of error at the end.

sudo bundle exec rake import:all

TODO/Improvement:

  • Take csv form external source.
  • Validate csv file: content, size for example.
  • Print a pretty report at the end to indicate which author/article encountered issue.

Links

About

Training for Ruby on Rails

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors