Skip to content

Offspend/public-hiring-test

Repository files navigation

How to use

Stack: NestJs + TypeORM + Postgres

Requirements

  • Docker / Docker Compose
  • Node.js 18

Installation

$ yarn

Running the app

First you need to start, migrate and seed the db :

$ yarn init-project

you can then start the server:

# development
$ yarn start

# watch mode
$ yarn start:dev

Test

To run unit tests:

# unit tests
$ yarn test

# e2e tests
$ yarn test:e2e

# test coverage
$ yarn test:cov

Database Migration

When the data schema is updated, the database needs to be synchronised with the code. This is done by creating a migration with Typeorm using the following command:

migrationName=<name> yarn migration:generate

Hiring Test

When working on the following exercise, in addition to answering the product need, to give particular attention to the following points:

  • Readability
  • Maintainability
  • Unit testing
  • Handling of corner cases
  • Error-handling

We want to compute the Agrybalise carbonfootprint of a foodproduct (e.g.: a hamCheesePizza) that we characterize by its ingredients as shown below

const hamCheesePizza = {
  ingredients: [
    { name: "ham", quantity: 0.1, unit: "kg" },
    { name: "cheese", quantity: 0.15, unit: "kg" },
    { name: "tomato", quantity: 0.4, unit: "kg" },
    { name: "floor", quantity: 0.7, unit: "kg" },
    { name: "oliveOil", quantity: 0.3, unit: "kg" },
  ],
};

The calculation of the Agrybalise carbon footprint can be described as below:

  • The Agrybalise carbon footprint of one ingredient is obtained by multiplying the quantity of the ingredient by the emission of a matching emission factor (same name and same unit).
  • The carbon footprint of the food product is then obtained by summing the carbon footprint of all ingredients.
  • If the carbon footprint of one ingredient cannot be calculated, then the carbon footprint of the whole product is set to null.

The tasks of this exercice are as follows: 1/ Implement the carbon footprint calculation of a product and persist the results in database. 2/ Implement a GET endpoint to retrieve the result. 3/ Implement a POST endpoint to trigger the calculation and the saving in the database.

About

Technical tests for hiring software engineering @greenly

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published