Code Monkey home page Code Monkey logo

edx-nodejs-lab04's Introduction

I try to write the code using TDD, but this, of course, is something that is hardly visible after!

Anywa,y I first wrote the test in test/accounts_test, according to lab 4 requirements, and then I implemented the API.

Here is the repository

https://github.com/lucabradipus/edx-nodejs-lab04.git

Testing with mocha and Testing with curl

after npm install you can run either

npm test  

or

./node_modules/.bin/mocha  --exit

to run the test scripts based on mocha and chai.

Or

node server.js; test/test.sh

to run the shell script that will run a set of curl

test.sh use a small awk command to retrieve the ID of the just created account.

ID=curl -H "Content-Type: application/json" -X POST -d '{"balance": "1000", "name": "savings"}' "http://localhost:3000/accounts" | awk -F "[:/}]" '/_id/ {gsub(/"/, "", $5);print $5 }'

I tested on OS X 10.13.2 and I expect that it will work on (almost) all *NIX

Environment

For this assignment I defined a test environment that is set in account_test.js file. The file _config.js contains the configuration variables that are set when the process.env.NODE_ENV = 'test' or when it is left to the default value development

In this way I do not mess with the development or production db and I can drop my collections at every test run. Also, I change the port for the test server to allow a development app to run without clash with the test env

Validation

I used mongoose schema to perform validation and I wrote a couple of test about it

Model

model is defined in models/accounts.js.

outes

routes are in routes/account.js, according to the pattern we have already used in lab 2

dependencies

* body-parser
* express
* morgan
* errorhandler  

development dependencies

* chai
* chai-http
* mocha
* node-dev

edx-nodejs-lab04's People

Contributors

luca-terza avatar lucabradipus avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

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.