From dc511f8619364098959b1b504e27c68f95aac3e4 Mon Sep 17 00:00:00 2001 From: MohammedAlghazali Date: Tue, 31 Mar 2020 14:47:23 +0300 Subject: [PATCH] make test for /project/:projectId route relates #32 --- .../routes/admin/project/editProject.js | 2 +- server/database/config/fakeData.sql | 16 ++++++++++ test/index.test.js | 31 ++++++++++++++++++- 3 files changed, 47 insertions(+), 2 deletions(-) diff --git a/server/controllers/routes/admin/project/editProject.js b/server/controllers/routes/admin/project/editProject.js index cdf6a90b..d60d48b2 100644 --- a/server/controllers/routes/admin/project/editProject.js +++ b/server/controllers/routes/admin/project/editProject.js @@ -24,7 +24,7 @@ const projectEdit = async (req, res, next) => { ); res.json({ StatusCode: 200, - data: { message: 'Cohort updated successfully' }, + data: { message: 'project updated successfully' }, }); } catch (err) { next(err); diff --git a/server/database/config/fakeData.sql b/server/database/config/fakeData.sql index 6114ab3d..9a4a8310 100644 --- a/server/database/config/fakeData.sql +++ b/server/database/config/fakeData.sql @@ -14,6 +14,22 @@ INSERT INTO project (name , description , img_url , github_link , website_link , 'https://lh3.googleusercontent.com/proxy/fp_bF_rbMIKyCfgdgWodyuM9LGt3HwGgM8AMnQ4qxjftKcvEdmhngdaeA8F6xFgRDHVzezPLT6YZarpBcqnMD5WtAvUhKJXcWS7qvS6Bn3CllitLttt_uA', 'https://github.com/GSG-G8/ca-wiki/tree/ed9f4cd9b5dc428f5420fe9a880a27e63f5f04d3', 'https://github.com/GSG-G8/ca-wiki/blob/ed9f4cd9b5dc428f5420fe9a880a27e63f5f04d3/%5Blink%5D','Internal project',1), +('ca-wiki', +'Ca-wiki is a web application which allows clients to view all cohorts that have been enrolled in Code Academy. Clients can view all students who graduated from the academy so that they can view every student and his/her projects he/she participated in, his/her github page', +'https://lh3.googleusercontent.com/proxy/fp_bF_rbMIKyCfgdgWodyuM9LGt3HwGgM8AMnQ4qxjftKcvEdmhngdaeA8F6xFgRDHVzezPLT6YZarpBcqnMD5WtAvUhKJXcWS7qvS6Bn3CllitLttt_uA', +'https://github.com/GSG-G8/ca-wiki/tree/ed9f4cd9b5dc428f5420fe9a880a27e63f5f04d3', +'https://github.com/GSG-G8/ca-wiki/blob/ed9f4cd9b5dc428f5420fe9a880a27e63f5f04d3/%5Blink%5D','Internal project',2), +('ca-wiki', +'Ca-wiki is a web application which allows clients to view all cohorts that have been enrolled in Code Academy. Clients can view all students who graduated from the academy so that they can view every student and his/her projects he/she participated in, his/her github page', +'https://lh3.googleusercontent.com/proxy/fp_bF_rbMIKyCfgdgWodyuM9LGt3HwGgM8AMnQ4qxjftKcvEdmhngdaeA8F6xFgRDHVzezPLT6YZarpBcqnMD5WtAvUhKJXcWS7qvS6Bn3CllitLttt_uA', +'https://github.com/GSG-G8/ca-wiki/tree/ed9f4cd9b5dc428f5420fe9a880a27e63f5f04d3', +'https://github.com/GSG-G8/ca-wiki/blob/ed9f4cd9b5dc428f5420fe9a880a27e63f5f04d3/%5Blink%5D','Internal project',1), +('ca-wiki', +'Ca-wiki is a web application which allows clients to view all cohorts that have been enrolled in Code Academy. Clients can view all students who graduated from the academy so that they can view every student and his/her projects he/she participated in, his/her github page', +'https://lh3.googleusercontent.com/proxy/fp_bF_rbMIKyCfgdgWodyuM9LGt3HwGgM8AMnQ4qxjftKcvEdmhngdaeA8F6xFgRDHVzezPLT6YZarpBcqnMD5WtAvUhKJXcWS7qvS6Bn3CllitLttt_uA', +'https://github.com/GSG-G8/ca-wiki/tree/ed9f4cd9b5dc428f5420fe9a880a27e63f5f04d3', +'https://github.com/GSG-G8/ca-wiki/blob/ed9f4cd9b5dc428f5420fe9a880a27e63f5f04d3/%5Blink%5D','Internal project',2), + ('events-booker', 'This app to help GSG organization in organizing the registration for the events that they do. So When they announced for an event, it will be known who would like to attend and they can ensure if this person attended or not. By this way, the GSG can have information about the people who attended and they can use it in the future as they want.', 'https://d2slcw3kip6qmk.cloudfront.net/marketing/blog/2017Q2/project-planning-header@2x.png', diff --git a/test/index.test.js b/test/index.test.js index f7dc6212..2b36be76 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -33,7 +33,7 @@ describe('Admin, Project', () => { const { data } = res.body; if (err) return done(err); const result = await connection.query( - 'SELECT * from project WHERE id = 3', + 'SELECT * from project WHERE id = 6', ); expect(result.rows[0].name).toBe('Mohmmedzw851@'); expect(data.message).toBe('Cohort Added successfully'); @@ -60,3 +60,32 @@ describe('Admin, (/cohorts/:cohortId)', () => { }); }); }); + +describe('Admin, (/projects/:projectId)', () => { + test('PUT Route /projects/1 status 200, json header, message:Cohort updated successfully', (done) => { + const testData = { + name: 'Mooooot', + description: 'project test', + imgUrl: 'https://github.com/GSG-G1', + githubLink: 'https://github.com/GSG-G1', + websiteLink: 'https://github.com/GSG-G1', + projectType: 'https://github.com/GSG-G1', + cohortId: '2', + }; + return request(app) + .put('/api/v1/projects/5') + .send(testData) + .expect(200) + .expect('Content-Type', /json/) + .end(async (err, res) => { + if (err) return done(err); + const { message } = res.body.data; + const { rows } = await connection.query( + 'SELECT * from project WHERE id = 5', + ); + expect(message).toBe('project updated successfully'); + expect(rows[0].name).toBe('Mooooot'); + done(); + }); + }); +});