From 7dbac7f65e59f1bae42c77a981a64e5b82ba963b Mon Sep 17 00:00:00 2001 From: rehabas Date: Tue, 31 Mar 2020 17:29:51 +0300 Subject: [PATCH] get projects testing relates #12 --- .eslintrc.json | 4 +++- .../controllers/routes/user/project/index.js | 4 ++-- .../database/queries/project/getProjects.js | 2 +- test/index.test.js | 23 +++++++++++++++++-- 4 files changed, 27 insertions(+), 6 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index c3bb1f31..538da47c 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -34,6 +34,8 @@ "jest/no-focused-tests": "error", "jest/no-identical-title": "error", "jest/prefer-to-have-length": "warn", - "jest/valid-expect": "error" + "jest/valid-expect": "error", + "consistent-return":"off", + "jest/no-test-callback":"off" } } diff --git a/server/controllers/routes/user/project/index.js b/server/controllers/routes/user/project/index.js index 665dd638..6c2647bb 100644 --- a/server/controllers/routes/user/project/index.js +++ b/server/controllers/routes/user/project/index.js @@ -1,5 +1,5 @@ -const { getProjectData } = require('./getProjectsData'); +const { getProjectsData } = require('./getProjectsData'); module.exports = { - getProjectData, + getProjectsData, }; diff --git a/server/database/queries/project/getProjects.js b/server/database/queries/project/getProjects.js index 15757e08..172b3bd7 100644 --- a/server/database/queries/project/getProjects.js +++ b/server/database/queries/project/getProjects.js @@ -1,3 +1,3 @@ const connection = require('../../config/connection'); -exports.getCohort = () => connection.query('SELECT * FROM project'); +exports.getProjects = () => connection.query('SELECT * FROM project'); diff --git a/test/index.test.js b/test/index.test.js index 1c71181d..637ae897 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -1,3 +1,22 @@ -test('Initial test', () => { - expect(1).toBe(1); +const request = require('supertest'); +const connection = require('../server/database/config/connection'); +const dbBuild = require('../server/database/config/build'); + +const app = require('../server/app'); + +beforeAll(() => dbBuild()); + +afterAll(() => connection.end()); + +test('Get projects route', (done) => { + request(app) + .get('/api/v1/projects') + .expect(200) + .expect('Content-Type', /json/) + .end(async (err, res) => { + const { data } = res.body; + if (err) return done(err); + expect(data).toHaveLength(2); + done(); + }); });