Skip to content

Developer Guide

Manuel edited this page Jan 22, 2024 · 17 revisions

App Tech-stack

Front-end:

  • JavaScript/TypeScript
  • React
  • FontAwesome
  • Chart.js
  • ESlint

Back-end:

  • JavaScript/TypeScript
  • Express
  • Sqlite3

Tests:

  • JavaScript/TypeScript
  • Cypress
  • Cypress Image Snapshot

Coding Naming Conventions

Front-end:

Components:

  • Components that are intended to be used as reusable components should be named as <Custom[ComponentName]> so a reusable Alert component should be named CustomAlert.
  • We name component files the same as the components they represent with an .jsx extension so CustomAlert.jsx.

CSS:

  • We name CSS files the same as the component they belong to so the CSS file for the Todo.jsx component would be Todo.css.
  • We name CSS classes using the BEM naming convention in the following manner:
    • .Componenent__inner-element: So that for the Todo.css the rule styling the delete button would be written as .Todo__delete-button.

API class:

  • We name functions belonging to the API class (used to make requests to the backend API) <[action][modelName]> so:
    • getTodo
    • getTodos
    • addTodo
    • editTodo
    • deleteTodo

Back-end:

Database:

  • We name our database tables with singular and uppercase names:
    • Todo
    • Daily
    • Learning
  • We name our database table fields camelcased: date, title, locationName, imageUrl, etc.

Routers:

  • We create folders for different routes and give them model names:

    • /users
    • /todos
    • /events
  • We name our routers <[CRUD action of the router][modelName]Router> when importing them on server/app.js. A router to add a new user todo would be named createTodoRouter.

  • We names router files <[CRUD action of the router][modelName]>.js so:

    • readTodo.js
    • readTodos.js
    • createTodo.js
    • updateTodo.js
    • deleteTodo.js

Endpoints:

  • We name endpoints /api/[modelNameInPlural]/[:id] (in case id required) so for Learning models CRUD actions endpoints /api/learnings/:id would be used.

Automated Tests:

  • These tests include: api, end-to-end, functional, smoke, responsiveness, etc

UI Tests:

  • For UI tests we name test files <[(functionality|component)to test].cy.js> so a test for Login functionality test file would be login.cy.js and a test for Post functionality would be post.cy.js.
  • For UI test cases are named using the "should do X when input Y" naming convention. So "should login user when entering valid credentials" for example.

API Tests:

  • For API tests we separate tests into CRUD actions. A test for Todo API endpoints would be:

    • create-todo.cy.js.
    • read-todo.cy.js.
    • update-todo.cy.js.
    • delete-todo.cy.js.
  • For API tests cases are named "<HTTP method> /api/<modelNameInPlural>/:id - should <CRUD action> a <modelName>". For Todo API test cases:

    • "POST - /api/todos/:id - should create a todo when requesting with valid data"
    • "GET - /api/todos/ - should retrieve all existing todos"
    • "GET - /api/todos/:id - should retrieve a specific todo"
    • "PATCH - /api/todos/:id - should update a specific todo"
    • "DELETE - /api/todos/:id - should delete a specific todo"

Best Practices

Automated Tests

  • On functional tests do operations like login programmatically and stub and mock as many requests as possible in order to improve test performance.
  • When all tests are implemented we should have the following folders for tests:
    • API
    • E2E
    • Functional
    • Responsiveness
    • Smoke
  • Integrate visual tests along the flow of responsiveness and smoke tests. Functional or component tests are too numerous and integrating visual tests there could hinder performance.
  • Divide tests cases in Positive and Negative contexts.
  • Really implements lots of component tests cases so the amount of functional e2e and smoke test cases is lower.
  • When mentioning(in requirements/test cases) that a form allows a user to login or register or in general submit with valid data then whatever valid data is should be defined somewhere:
    • Valid username: (min 4 alphanumeric chars/max 20 alphanumeric chars).
  • Do not use any hardcoded data in tests. Use fixtures.
  • Add component tests inside the front-end folder.
  • When testing on an input check that input value cannot:
    • Be empty.
    • Be shorter than expected(if alpha chars expected).
    • Be longer than expected(if alpha chars expected).
    • Be minus(if numeric chars expected)
    • Be 0(in case this makes sense like when choosing a product quantity).
    • Be higher than expected(in case this makes sense like choosing product amount then 9.999.999 should not be a possibility).

Clone this wiki locally