Coder Social home page Coder Social logo

herberthk / backend-developer-hiring-exercise Goto Github PK

View Code? Open in Web Editor NEW

This project forked from miohtama/backend-developer-hiring-exercise

0.0 1.0 0.0 365 KB

This is a software development exercise for a TypeScript / Node.js backend developer position.

JavaScript 2.63% TypeScript 97.37%

backend-developer-hiring-exercise's Introduction

Introduction

This is a software development exercise for a TypeScript / Node.js backend developer position.

Exercise

Your task

Your task is to

  • Add a new field phoneNumber for users

  • This field is required during the registration process

  • The field must save a normalised (i.e: no spaces or other separator characters) international phone number in the database. Technically, this is called MSISDN format. Please save the plus character prefix in the database. E.g. a valid column value would be +358401231234 (Finland).

  • Update e2e tests to cover different phone number input cases - the API must gracefully handle different valid and invalid inputs

  • Create necessary migrations to upgrade the production database

  • In the pull request describe the changes and the actions that your colleagues need to understand: API migration instructions for frontend developers, database migration instructions for a devop team

  • For the extra impression, you can add other recommendations in the pull request commenting section. However, any code and style changes, should go to its own separate pull request. The exercise pull request must consider only the task in the hand.

How to submit the exercise

  • Create a private copy of this Github repository
  • Complete the task above
  • Create a new pull request against your private repository
  • In the PR, write down number of hours you spent on this exercise (we do not use this to rank you, we use it to adjust the laborisity of future exercises)
  • Invite a Github user miohtama to your repository
  • Send email to [email protected] that you have completed the exercise

How you will be ranked

We will look

  • If the instructions were properly followed
  • If the task was correctly completed
  • Code quality
  • Code comment quality
  • Pull request commenting quality

Project description

This exercise is based on NestJS framework TypeScript starter project.

The local development flow is

The development environment is tested on OSX, but should work on Linux systems unmodified. We do not recommend trying to undertake the exercise on native Windows.

Prerequisites

  • You need to understand UNIX shell, TypeScript, Node.js, Docker, PostgreSQL

  • This exercise was developed on Node v11.0.0

Installation

Setting up PostgreSQL database

This is will make a new PostgreSQL running in the standard port 5432. Please shutdown any previous conflicting PostgreSQL instances before starting this.

docker-compose up -d

Check it is up

docker logs -f local_db

Check that you can log into a database with psql

docker exec -it local_db psql -U local_dev local_db

Setting up a local app

Then do the local app installation

npm install

Generata a dist folder (this will transpile .ts migrations to .js)

npm run build

Run initial migrations to set up initial database tables

npm run migration:run

Running the app

Development

npm run start

Then visit http://localhost:3000 to get the app landing page. There is nothing to see there.

Visit http://localhost:3000/api/ to get the Swagger generated REST API tool. which you can use against a hot reloading dev server.

Swagger example

To run the dev server in watch mode:

npm run start:dev

Manual usage using Swagger

  1. Post a registration request to /register

  2. Confirm your email using /users/confirm-email-admin

Testing

Please note that the server logger is not muted during these tests, so you get API errors logged in the console.

Create the testing database (needs to be done only once).

docker exec -it local_db psql -U local_dev -c "create database e2e_test" local_db  

Run jest:

npm run test:e2e

We have only integration tests. No unit tests are available, or asked, in this exercise.

Database and migrations

Automatically generating migrations

You can generate migration files

  1. After updating entity source code

  2. You have an up-to-date local development database

# Rebuild transpilation
npm run build  

# You need to start the dev server to generate dist/migrations 
# NestJS bug https://github.com/nrwl/nx/issues/1393
npm run start

# Create a file under migration/
npm run migration:generate -- -n CreateUsers

Run migrations against a local db

npm run migration:run

Check the result of migrations

docker exec -it local_db psql -U local_dev -c "\dt" local_db

Troubleshooting

Restart database from the scratch

Nuking the local development database:

docker-compose down -v

Display database content

See what lurks in the user table:

docker exec -it local_db psql -U local_dev -c "select * from site_user" local_db

And for the e2e DB:

docker exec -it local_db psql -U local_dev -c "select * from site_user" e2e_test

Debugging from Visual Studio Code

Visual Studio Code Auto [Attach feature] works.

You just need to run

npm run start:debug

... and Visual Studio Code will notice this and the debugger bar appears. All breakpoints are honoured.

Launching Jest from Visual Studio Code

Example launcher how to attach a debugger to Jest tests.

{
    "version": "0.2.0",
    "configurations": [
        
        {
            "type": "node",
            "request": "launch",
            "name": "Jest All",
            "program": "${workspaceFolder}/node_modules/.bin/jest",
            "args": [
                "--runInBand",
                "--config",
                "./test/jest-e2e.json"
            ],
            "console": "integratedTerminal",
            "internalConsoleOptions": "neverOpen",
            "disableOptimisticBPs": true,
            "windows": {
                "program": "${workspaceFolder}/node_modules/jest/bin/jest",
            },
            "env": {
                "PATH": "/Users/moo/.nvm/versions/node/v11.0.0/bin:${env:PATH}"
            },
        },
    ]    
}    

Further reading

NestJS and TypeORM in 30 minutes

Another NestJS and TypeORM tutorial

PostgreSQL on Dockerhub

class-validator

Cats NestJS + Swagger sample full example code

Testing database interaction with TypeORM and related source code

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.