From 3c4ec92ed9a0f209c6cb2c0574876e1a378eb499 Mon Sep 17 00:00:00 2001 From: ElhamFadel Date: Sun, 31 Oct 2021 18:12:36 +0300 Subject: [PATCH] edit agint #10 --- server/database/config/connection.js | 2 +- server/routes/estate.js | 6 ++-- server/test/index.test.js | 47 ++++++++++++++++++++++++++++ 3 files changed, 50 insertions(+), 5 deletions(-) diff --git a/server/database/config/connection.js b/server/database/config/connection.js index f1ed1f7..4a402a1 100644 --- a/server/database/config/connection.js +++ b/server/database/config/connection.js @@ -23,6 +23,6 @@ switch (NODE_ENV) { const options = { connectionString: dbUrl, - ssl: false, + ssl: { rejectUnauthorized: false }, }; module.exports = new Pool(options); diff --git a/server/routes/estate.js b/server/routes/estate.js index da4cc19..d618318 100644 --- a/server/routes/estate.js +++ b/server/routes/estate.js @@ -1,10 +1,8 @@ const router = require('express').Router(); - -// router.delete('/:estateId', isAuth, isAdmin, deleteEstate); -// const { isAuth, isAdmin } = require('../middleware'); +const { isAuth, isAdmin } = require('../middleware'); const { editEstate, deleteEstate } = require('../controllers'); router.put('/:estateId', editEstate); - +router.delete('/:estateId', isAuth, isAdmin, deleteEstate); router.delete('/:estateId', deleteEstate); module.exports = router; diff --git a/server/test/index.test.js b/server/test/index.test.js index 56106ec..c4e56bc 100644 --- a/server/test/index.test.js +++ b/server/test/index.test.js @@ -181,6 +181,7 @@ describe('Delete Specific Estate By Using Id', () => { }); }); }); + describe('test signup endpoint with all cases ', () => { test('test sign up endpoint when success', async () => { const res = await supertest(app) @@ -250,3 +251,49 @@ describe('test signup endpoint with all cases ', () => { }); }); }); + +describe('test Edit Agent data /users/:iduser ', () => { + test('test 200', async () => { + const res = await supertest(app) + .put('/api/v1/users/1') + .send({ + username: 'test', + email: 'kallport0@patch.com', + phone: '059985555555', + }) + .expect(200) + .expect('Content-Type', /json/); + return expect(res.body).toEqual({ + message: 'Agent\'s data updated successfully', + }); + }); + + test('test 400', async () => { + const res = await supertest(app) + .put('/api/v1/users/1') + .send({ + username: 'test', + email: 'kallport0@patch.com', + phone: '0599', + }) + .expect(400) + .expect('Content-Type', /json/); + return expect(res.body).toEqual({ + message: '"phone" length must be at least 9 characters long', + }); + }); + test('test 404', async () => { + const res = await supertest(app) + .put('/api/v1/users/400') + .send({ + username: 'test', + email: 'kallport0@patch.com', + phone: '059915587555', + }) + .expect(404) + .expect('Content-Type', /json/); + return expect(res.body).toEqual({ + message: 'There\'s no Agent, put correct id', + }); + }); +});