Skip to content

Latest commit

 

History

History
108 lines (88 loc) · 4.58 KB

README.md

File metadata and controls

108 lines (88 loc) · 4.58 KB
  • CircleCI
  • Maintainability
  • Test Coverage

README

messing around with the newer versions of things, this may end up functionally identical to node express api but with sessions.

get this puppy up and running:

  • Fork, Clone, and yarn install
  • Copy .env.example to .env and update any necessary envs
  • Create databases: $ createdb practice_exp_app_test AND $ createdb practice_exp_app_development
  • Run tests: $ yarn test
  • Run linter: $ yarn lint
  • Run coverage tools:
    • see in terminal: $ yarn coverage
    • see interactive version in browser:
      1. $ yarn report
      2. copy the full path of practice-exp-app/coverage/lcov-report/index.html and dump it into the "url" of a browser
  • Stand it up: $ yarn start

curl

  • No cookies: $ curl http://localhost:3000/
  • Sign up and store a cookie to reuse: $ curl -c ./tmp/curlCookies -X POST -H "Content-Type: application/json" -d '{"email":"[email protected]", "password": "password", "firstName": "Elowyn", "lastName": "Platzer Bartel", "birthYear": "2015", "student": "true"}' http://localhost:3000/users
  • use a stored cookie: $ curl -b ./tmp/curlCookies http://localhost:3000/users/me

references

how did this get started?

  1. barebones structure
    • $ npx express-generator --no-view --git practice-exp-app, cd into directory, and open in text editor

    • $ yarn add --dev mocha

    • $ yarn add --dev chai

    • add a dummy test under test/setup_test.js to ensure setup is correct:

      const expect = require('chai').expect
      
      describe('Basic test', function() {
        it('should equate true to true', function() {
          expect(true).to.equal(false);
        });
      });
      
    • add test script to package.json: "test": "mocha"

    • run test, change code, run test from here on out...

    • change test to expect true to equal true

  2. get rid of view cruft
    • $ yarn add --dev supertest

    • Add tests: first under /test/routes/index_test.js, second under test/routes/users_test.js

      const request = require('supertest');
      const { expect } = require('chai');
      
      const app = require('../../app.js');
      
      describe('Root path', async () => {
        it('returns greeting', async () => {
          const res = await request(app)
            .get('/')
            .expect(200);
      
          expect(res.err).to.be.undefined; // eslint-disable-line no-unused-expressions
          expect(res.text).to.equal('oh hai!');
        });
      });
      const request = require('supertest');
      const { expect } = require('chai');
      
      const app = require('../../app.js');
      
      describe('User', async () => {
        it('root path returns reminder to update route', async () => {
          const res = await request(app)
            .get('/users')
            .expect(200);
      
          expect(res.err).to.be.undefined; // eslint-disable-line no-unused-expressions
          expect(res.text).to.equal('respond with a reeeeeesource');
        });
      });
    • Update index route to get the test passing, then update user test to pass.

    • Remove cruft:

      • view directory and references
      • public directory and references
  3. Add a linter
    • $ yarn add eslint --dev
    • add lint script to package.json: "lint": "eslint --init" and run to create basic setup
    • update script to run linter: "lint": "eslint --ignore-path .gitignore .",
    • continuously run linter after any code changes
    • add mocha: true to the exports.env section
    • review errors and update repository