Skip to content

Commit

Permalink
prepar setting data base test and testing for endpoint /users #17
Browse files Browse the repository at this point in the history
  • Loading branch information
mohammedsalah7 committed Oct 27, 2021
1 parent 44a0802 commit a359212
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 13 deletions.
11 changes: 6 additions & 5 deletions server/controllers/users/getAllUsers.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
/* eslint-disable no-console */
const { getAllUsersQuery } = require('../../database/quieres');

const getAllUsers = async (req, res) => {
const getAllUsers = async (req, res, next) => {
try {
const resalut = await getAllUsersQuery();
const { data } = resalut;
res.json(({ data: data.rows }));
const { rows } = await getAllUsersQuery();

res.json(({ data: rows, msg: 'You are get all users' }));
} catch (err) {
res.json({ err });
next(err);
}
};
module.exports = getAllUsers;
File renamed without changes.
7 changes: 5 additions & 2 deletions server/database/config/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ const connection = require('../connection');

const dbBuild = () => {
let sql = readFileSync(join(__dirname, 'build.sql')).toString();
sql += readFileSync(join(__dirname, 'fakeData.sql')).toString();
sql += readFileSync(join(__dirname, 'adminsFackData.sql')).toString();
sql += readFileSync(join(__dirname, 'agentsFackData.sql')).toString();
sql += readFileSync(join(__dirname, 'imagesFackData.sql')).toString();
sql += readFileSync(join(__dirname, 'imagesFackData.sql')).toString();
return connection.query(sql);
};
module.exports = dbBuild;
module.exports = { dbBuild };
File renamed without changes.
12 changes: 6 additions & 6 deletions server/database/config/realStateFackData.sql
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
insert into estates ( agent_id, title, price, description, type, category, street, city, region, bathrooms, bedrooms, rooms, space, approved, rate, available) values (1, 'suscipit ligula in', '$190483.22', 'tristique', 'Buy', 'House', '3152 Morningstar Park', 'Edinburgh of the Seven Seas', 'Saint Helena', 2, 1, 1, 194, false, 2, false);
insert into estates ( agent_id, title, price, description, type, category, street, city, region, bathrooms, bedrooms, rooms, space, approved, rate, available) values (2, 'ipsum primis in', '$242471.89', 'est quam pharetra magna ac consequat metus sapien ut nunc vestibulum ante', 'Buy', 'House', '100 Butternut Hill', 'Bern', 'Switzerland', 1, 2, 2, 226, true, 5, true);
insert into estates ( agent_id, title, price, description, type, category, street, city, region, bathrooms, bedrooms, rooms, space, approved, rate, available) values (3, 'rhoncus sed vestibulum', '$84726.00', 'massa volutpat convallis morbi odio odio elementum eu interdum eu tincidunt in', 'Buy', 'House', '0824 Mcguire Way', 'Kungshamn', 'Sweden', 1, 3, 3, 235, true, 5, false);
insert into estates ( agent_id, title, price, description, type, category, street, city, region, bathrooms, bedrooms, rooms, space, approved, rate, available) values (4, 'sociis natoque penatibus et', '$106226.71', 'quis odio consequat', 'Buy', 'House', '15918 Mcguire Point', 'Ranong', 'Thailand', 2, 4, 4, 244, true, 1, false);
insert into estates ( agent_id, title, price, description, type, category, street, city, region, bathrooms, bedrooms, rooms, space, approved, rate, available) values (5, 'in faucibus orci luctus', '$116162.27', 'parturient montes nascetur ridiculus mus vivamus vestibulum sagittis sapien cum', 'Buy', 'House', '898 Dixon Crossing', 'Gelap', 'Indonesia', 3, 2, 4, 150, false, 3, false);
insert into estates ( agent_id, title, price, description, type, category, street, city, region, bathrooms, bedrooms, rooms, space, approved, rate, available) values (6, 'vestibulum ante ipsum primis', '$194193.55', 'leo odio porttitor id consequat in consequat ut nulla sed', 'Buy', 'House', '0891 7th Park', 'Álimos', 'Greece', 1, 3, 2, 174, false, 1, false);
insert into estates ( agent_id, title, price, description, type, category, street, city, region, bathrooms, bedrooms, rooms, space, approved, rate, available) values (1, 'suscipit ligula in', '190483.22', 'tristique', 'Buy', 'House', '3152 Morningstar Park', 'Edinburgh of the Seven Seas', 'Saint Helena', 2, 1, 1, 194, false, 2, false);
insert into estates ( agent_id, title, price, description, type, category, street, city, region, bathrooms, bedrooms, rooms, space, approved, rate, available) values (2, 'ipsum primis in', '242471.89', 'est quam pharetra magna ac consequat metus sapien ut nunc vestibulum ante', 'Buy', 'House', '100 Butternut Hill', 'Bern', 'Switzerland', 1, 2, 2, 226, true, 5, true);
insert into estates ( agent_id, title, price, description, type, category, street, city, region, bathrooms, bedrooms, rooms, space, approved, rate, available) values (3, 'rhoncus sed vestibulum', '84726.00', 'massa volutpat convallis morbi odio odio elementum eu interdum eu tincidunt in', 'Buy', 'House', '0824 Mcguire Way', 'Kungshamn', 'Sweden', 1, 3, 3, 235, true, 5, false);
insert into estates ( agent_id, title, price, description, type, category, street, city, region, bathrooms, bedrooms, rooms, space, approved, rate, available) values (4, 'sociis natoque penatibus et', '106226.71', 'quis odio consequat', 'Buy', 'House', '15918 Mcguire Point', 'Ranong', 'Thailand', 2, 4, 4, 244, true, 1, false);
insert into estates ( agent_id, title, price, description, type, category, street, city, region, bathrooms, bedrooms, rooms, space, approved, rate, available) values (5, 'in faucibus orci luctus', '116162.27', 'parturient montes nascetur ridiculus mus vivamus vestibulum sagittis sapien cum', 'Buy', 'House', '898 Dixon Crossing', 'Gelap', 'Indonesia', 3, 2, 4, 150, false, 3, false);
insert into estates ( agent_id, title, price, description, type, category, street, city, region, bathrooms, bedrooms, rooms, space, approved, rate, available) values (6, 'vestibulum ante ipsum primis', '194193.55', 'leo odio porttitor id consequat in consequat ut nulla sed', 'Buy', 'House', '0891 7th Park', 'Álimos', 'Greece', 1, 3, 2, 174, false, 1, false);
26 changes: 26 additions & 0 deletions server/test/index.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/* eslint-disable no-undef */
const supertest = require('supertest');
const app = require('../app');
const { dbBuild } = require('../database/config/build');
const connection = require('../database/connection');

beforeEach(() => dbBuild());

describe('All users', () => {
test('get all users', (done) => {
supertest(app)
.get('/api/v1/users')
.expect(200)
.expect('Content-Type', /json/)
.end((err, res) => {
if (err) return done(err);
expect(res.body.msg).toBe('You are get all users');
return done();
});
});
test('adds 1 + 2 to equal 3', () => {
expect(1 + 2).toBe(3);
});
});

afterAll(() => connection.end());

0 comments on commit a359212

Please sign in to comment.