Guest User

Untitled

a guest
Aug 21st, 2019
133
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const express = require('express');
  2. const router = express.Router();
  3. const { check, validationResult } = require('express-validator');
  4. const auth = require('../middleware/auth');
  5.  
  6. const Level = require('../models/Level');
  7.  
  8. // @route GET api/level
  9. // @desc Get all levels from the level database
  10. // @access Private
  11. router.get('/', async (req, res) => {
  12. try {
  13. let levels = await Level.findAll({ raw: true, nest: true });
  14.  
  15. levelsAsJson = { levels: levels };
  16.  
  17. console.log(levels);
  18.  
  19. res.status(200).json(levelsAsJson);
  20. } catch (error) {
  21. console.log(error.message);
  22. res.status(500).send('Server error');
  23. }
  24. });
  25.  
  26. module.exports = router;
  27.  
  28. const chai = require('chai');
  29. const expect = chai.expect;
  30. const chaiAsPromised = require('chai-as-promised');
  31. var sinon = require('sinon');
  32. const sinonChai = require('sinon-chai');
  33. const request = require('supertest');
  34.  
  35. const app = require('../../index');
  36.  
  37. chai.use(chaiAsPromised);
  38. chai.use(sinonChai);
  39.  
  40. describe('Levels route', () => {
  41. // test whether the endpoint will respond with a 200
  42. context('GET /level', () => {
  43. it('should return all levels from the levels table.', done => {
  44. request(app)
  45. .get('/api/level')
  46. .set('Accept', 'application/json')
  47. .expect('Content-type', /json/)
  48. .expect(200, done);
  49. });
  50. });
  51. });
RAW Paste Data