From d262dd2f5cf4f27c1246fd2dc3f6101abc3d609c Mon Sep 17 00:00:00 2001 From: Eric Maniraguha Date: Mon, 7 Feb 2022 16:31:41 +0200 Subject: [PATCH 1/3] some update dane on swagger --- swagger.json | 42 +----------------------------------------- tests/article.test.js | 24 +++++++++++------------- 2 files changed, 12 insertions(+), 54 deletions(-) diff --git a/swagger.json b/swagger.json index 307a812..8f08192 100644 --- a/swagger.json +++ b/swagger.json @@ -70,9 +70,6 @@ } }, - - - "/api/v1/users/login": { "post": { "tags": ["Users"], @@ -168,44 +165,7 @@ } } }, - "post": { - "tags": ["Articles"], - "summary": "Create article", - "description": "Create article", - "operationId": "postArticles", - "parameters": [ - { - "name": "Authorization", - "in": "header", - "description": "Authorization", - "required": true - }, - { - "name": "title", - "in": "formData", - "description": "title", - "required": true - }, - { - "name": "content", - "in": "formData", - "description": "content", - "required": true - }, - { - "name": "image", - "in": "formData", - "type": "file", - "description": "image", - "required": true - } - ], - "responses": { - "200": { - "description": "Success" - } - } - }, + "patch": { "tags": ["Articles"], "summary": "Update article", diff --git a/tests/article.test.js b/tests/article.test.js index c2724c4..dd54e0e 100644 --- a/tests/article.test.js +++ b/tests/article.test.js @@ -5,8 +5,6 @@ import 'dotenv/config'; import Article from "./../src/models/article.js" -// const all = Article.find() -// let articleId=all[0]._id; let articleId @@ -34,7 +32,7 @@ describe("ARTICLE END-POINT TESTING", () => { }) it("Should not retrieve the articles", (done) => { - chai.request(app).get("/api/v1/aritcle/") + chai.request(app).get("/api/v1/aritcles/") .send() .end((err,res)=>{ expect(res).to.have.status([404]) @@ -59,13 +57,13 @@ it("Should retrieve the article by id", (done) => { // DELETE AN ARTICLE - // it("Should not delete the article by id", (done) => { - // chai - // .request(app) - // .delete(`/api/v1/articles/${articleId}`) - // .send() - // .end((err, res) => { - // expect(res).to.have.status([401]); - // done(); - // }); - // }); + it("Should not delete the article by id", (done) => { + chai + .request(app) + .delete(`/api/v1/articles/${articleId}`) + .send() + .end((err, res) => { + expect(res).to.have.status([401]); + done(); + }); + }); From b214a97bbfb671b3720a488f32a40110b9af51db Mon Sep 17 00:00:00 2001 From: Eric Maniraguha Date: Tue, 8 Feb 2022 05:14:34 +0200 Subject: [PATCH 2/3] update by authentication --- package-lock.json | 2 +- package.json | 6 +- swagger.json | 648 +++++++++++++++++++++++----------------------- 3 files changed, 330 insertions(+), 326 deletions(-) diff --git a/package-lock.json b/package-lock.json index 7394ed7..e5bdaca 100644 --- a/package-lock.json +++ b/package-lock.json @@ -14914,4 +14914,4 @@ "dev": true } } -} \ No newline at end of file +} diff --git a/package.json b/package.json index 50d0ace..14eb531 100644 --- a/package.json +++ b/package.json @@ -33,15 +33,15 @@ }, "repository": { "type": "git", - "url": "git+https://github.com/CYIMANA-Faisal/my-brand-api.git" + "url": "" }, "keywords": [], "author": "", "license": "ISC", "bugs": { - "url": "https://github.com/CYIMANA-Faisal/my-brand-api/issues" + "url": "" }, - "homepage": "https://github.com/CYIMANA-Faisal/my-brand-api#readme", + "homepage": "", "dependencies": { "@babel/cli": "^7.16.8", "@babel/core": "^7.16.12", diff --git a/swagger.json b/swagger.json index 8f08192..34fe25b 100644 --- a/swagger.json +++ b/swagger.json @@ -1,357 +1,361 @@ { - "swagger": "2.0", - "info": { - "title": "API", - "description": "API", - "version": "1.0.0" + "swagger": "2.0", + "info": { + "title": "My-brand API", + "description": "API", + "version": "1.0.0" + }, + "securityDefinitions": { + "Bearer": { + "type": "apiKey", + "name": "Authorization", + "in": "header" + } + }, + "servers": [ + { + "url": "http://localhost:3000", + "name": "DEV" }, - "servers": [ - { - "url": "http://localhost:3000", - "name": "DEV" - }, - { - "url": "https://my-brand-api-1.herokuapp.com/", - "name": "PROD" - } - ], - "paths": { - "/": { - "get": { - "tags": ["Home"], - "summary": "Home", - "description": "Home", - "operationId": "getHome", - "responses": { - "200": { - "description": "Success" - } + { + "url": "https://mynewbrandapi.herokuapp.com", + "name": "PROD" + } + ], + + "paths": { + "/": { + "get": { + "tags": ["Home"], + "summary": "Home", + "description": "Home", + "operationId": "getHome", + "responses": { + "200": { + "description": "Success" } } - }, - "/api/v1/users/register":{ - "post": { - "tags": ["Users"], - "summary": "Create user", - "description": "Create user", - "operationId": "postUser", - "parameters": [ - { - "name": "username", - "in": "formData", - "description": "username", - "required": true - }, - { - "name": "email", - "in": "formData", - "description": "email", - "required": true - }, - { - "name": "password", - "in": "formData", - "description": "password", - "required": true - }, - { - "name": "picture", - "in": "formData", - "type": "file", - "description": "picture", - "required": true - } - ], - "responses": { - "200": { - "description": "Success" - } + } + }, + "/api/v1/users/register": { + "post": { + "tags": ["Users"], + "summary": "Create user", + "description": "Create user", + "operationId": "postUsers", + "parameters": [ + { + "name": "username", + "in": "formData", + "description": "username", + "required": true + }, + { + "name": "email", + "in": "formData", + "description": "email", + "required": true + }, + { + "name": "password", + "in": "formData", + "description": "password", + "required": true + }, + { + "name": "picture", + "in": "formData", + "type": "file", + "description": "picture", + "required": true + } + ], + "responses": { + "200": { + "description": "Success" } } + } + }, - }, - "/api/v1/users/login": { - "post": { - "tags": ["Users"], - "summary": "Login", - "description": "Login", - "operationId": "postUsersLogin", - "parameters": [ - { - "name": "body", - "in": "body", - "description": "Login", - "required": true, - "schema": { - "$ref": "#/definitions/Login" - } - } - ], - "responses": { - "200": { - "description": "Success" + "/api/v1/users/login": { + "post": { + "tags": ["Users"], + "summary": "Login", + "description": "Login", + "operationId": "postUsersLogin", + "parameters": [ + { + "name": "body", + "in": "body", + "description": "Login", + "required": true, + "schema": { + "$ref": "#/definitions/Login" } } + ], + "responses": { + "200": { + "description": "Success" + } + } + } + }, + "/api/v1/articles": { + "get": { + "tags": ["Articles"], + "summary": "Get all articles", + "description": "Get all articles", + "operationId": "getArticles", + "responses": { + "200": { + "description": "Success" + } } }, - "/api/v1/articles": { - "get": { - "tags": ["Articles"], - "summary": "Get all articles", - "description": "Get all articles", - "operationId": "getArticles", - "responses": { - "200": { - "description": "Success" - } + "post": { + "tags": ["Articles"], + "summary": "Create article", + "description": "Create article", + "operationId": "postArticles", + "parameters": [ + { + "name": "title", + "in": "formData", + "description": "title", + "required": true + }, + { + "name": "content", + "in": "formData", + "description": "content", + "required": true + }, + { + "name": "image", + "in": "formData", + "type": "file", + "description": "image", + "required": true + } + ], + "responses": { + "200": { + "description": "Success" } }, - "post": { - "tags": ["Articles"], - "summary": "Create article", - "description": "Create article", - "operationId": "postArticles", - "parameters": [ - { - "name": "Authorization", - "in": "header", - "description": "Authorization", - "required": true - }, - { - "name": "title", - "in": "formData", - "description": "title", - "required": true - }, - { - "name": "content", - "in": "formData", - "description": "content", - "required": true - }, - { - "name": "image", - "in": "formData", - "type": "file", - "description": "image", - "required": true - } - ], - "responses": { - "200": { - "description": "Success" - } + "security": [ + { + "Bearer": [] + } + ] + } + + }, + "/api/v1/articles/{id}": { + "get": { + "tags": ["Articles"], + "summary": "Get one article", + "description": "Get one article", + "operationId": "getoneArticle", + "parameters": [ + { + "name": "id", + "in": "path", + "description": "id", + "required": true + } + ], + "responses": { + "200": { + "description": "Success" } } }, - "/api/v1/articles/{id}": { - "get": { - "tags": ["Articles"], - "summary": "Get one article", - "description": "Get one article", - "operationId": "getoneArticle", - "parameters": [ - { - "name": "id", - "in": "path", - "description": "id", - "required": true - } - ], - "responses": { - "200": { - "description": "Success" - } + "patch": { + "tags": ["Articles"], + "summary": "Update article", + "description": "Update article", + "operationId": "updateArticle", + "parameters": [ + { + "name": "id", + "in": "path", + "description": "id", + "required": true + }, + { + "name": "title", + "in": "formData", + "description": "title", + "required": true + }, + { + "name": "content", + "in": "formData", + "description": "content", + "required": true + }, + { + "name": "image", + "in": "formData", + "type": "file", + "description": "image", + "required": true } - }, - - "patch": { - "tags": ["Articles"], - "summary": "Update article", - "description": "Update article", - "operationId": "updateArticle", - "parameters": [ - { - "name": "Authorization", - "in": "header", - "description": "Authorization", - "required": true - }, - { - "name": "id", - "in": "path", - "description": "id", - "required": true - }, - { - "name": "title", - "in": "formData", - "description": "title", - "required": true - }, - { - "name": "content", - "in": "formData", - "description": "content", - "required": true - }, - { - "name": "image", - "in": "formData", - "type": "file", - "description": "image", - "required": true - } - ], - "responses": { - "200": { - "description": "Success" - } + ], + "responses": { + "200": { + "description": "Success" } }, - "delete": { - "tags": ["Articles"], - "summary": "Delete one article", - "description": "Delete one article", - "operationId": "deleteoneArticle", - "parameters": [ - { - "name": "Authorization", - "in": "header", - "description": "Authorization", - "required": true - }, - { - "name": "id", - "in": "path", - "description": "id", - "required": true - } - ], - "responses": { - "200": { - "description": "Success" - } + "security": [ + { + "Bearer": [] } - } + ] }, - "/api/v1/queries": { - "get": { - "tags": ["Queries"], - "summary": "Get all Queries", - "description": "Get all Queries", - "operationId": "getQueries", - "parameters": [ - { - "name": "Authorization", - "in": "header", - "description": "Authorization", - "required": true - } - ], - "responses": { - "200": { - "description": "Success" - } + "delete": { + "tags": ["Articles"], + "summary": "Delete one article", + "description": "Delete one article", + "operationId": "deleteoneArticle", + "parameters": [ + { + "name": "id", + "in": "path", + "description": "id", + "required": true } - }, - "post": { - "tags": ["Queries"], - "summary": "Create query", - "description": "Create query", - "operationId": "postQueries", - "parameters": [ - { - "name": "senderName", - "in": "formData", - "description": "senderName", - "required": true - }, - { - "name": "email", - "in": "formData", - "description": "email", - "required": true - }, - { - "name": "message", - "in": "formData", - "description": "message", - "required": true - } - ], - "responses": { - "200": { - "description": "Success" - } + ], + "responses": { + "200": { + "description": "Success" } + }, + "security": [ + { + "Bearer": [] } - }, - "/api/v1/comments/{id}": { - "get": { - "tags": ["Comments"], - "summary": "Get all Comments", - "description": "Get all Comments", - "operationId": "getComments", - "parameters": [ - { - "name": "id", - "in": "path", - "description": "id", - "required": true - } - ], - "responses": { - "200": { - "description": "Success" - } + ] + } + + }, + "/api/v1/queries": { + "get": { + "tags": ["Queries"], + "summary": "Get all Queries", + "description": "Get all Queries", + "operationId": "getQueries", + "parameters": [], + "responses": { + "200": { + "description": "Success" } }, - "post": { - "tags": ["Comments"], - "summary": "Create Comments", - "description": "Create Comments", - "operationId": "postComments", - "parameters": [ - { - "name": "id", - "in": "path", - "description": "id", - "required": true - }, - { - "name": "name", - "in": "formData", - "description": "name", - "required": true - }, - { - "name": "comment", - "in": "formData", - "description": "comment", - "required": true - } - ], - "responses": { - "200": { - "description": "Success" - } + "security": [ + { + "Bearer": [] + } + ] + }, + "post": { + "tags": ["Queries"], + "summary": "Create query", + "description": "Create query", + "operationId": "postQueries", + "parameters": [ + { + "name": "senderName", + "in": "formData", + "description": "senderName", + "required": true + }, + { + "name": "email", + "in": "formData", + "description": "email", + "required": true + }, + { + "name": "message", + "in": "formData", + "description": "message", + "required": true + } + ], + "responses": { + "200": { + "description": "Success" } } } }, - "definitions": { - "Login": { - "type": "object", - "properties": { - "email": { - "type": "string" + "/api/v1/comments/{id}": { + "get": { + "tags": ["Comments"], + "summary": "Get all Comments", + "description": "Get all Comments", + "operationId": "getComments", + "parameters": [ + { + "name": "id", + "in": "path", + "description": "id", + "required": true + } + ], + "responses": { + "200": { + "description": "Success" + } + } + }, + "post": { + "tags": ["Comments"], + "summary": "Create Comments", + "description": "Create Comments", + "operationId": "postComments", + "parameters": [ + { + "name": "id", + "in": "path", + "description": "id", + "required": true }, - "password": { - "type": "string" + { + "name": "name", + "in": "formData", + "description": "name", + "required": true + }, + { + "name": "comment", + "in": "formData", + "description": "comment", + "required": true + } + ], + "responses": { + "200": { + "description": "Success" } } } } - } \ No newline at end of file + }, + "definitions": { + "Login": { + "type": "object", + "properties": { + "email": { + "type": "string" + }, + "password": { + "type": "string" + } + } + } + } +} \ No newline at end of file From 7608cb6cf4e810bc8a5b6b34ee5fa3f4e2fa68b9 Mon Sep 17 00:00:00 2001 From: Eric Maniraguha Date: Tue, 8 Feb 2022 19:04:39 +0200 Subject: [PATCH 3/3] changes about test --- tests/article.test.js | 4 ++-- tests/comment.test.js | 50 +------------------------------------------ tests/query.test.js | 9 +++----- 3 files changed, 6 insertions(+), 57 deletions(-) diff --git a/tests/article.test.js b/tests/article.test.js index dd54e0e..78e209d 100644 --- a/tests/article.test.js +++ b/tests/article.test.js @@ -6,7 +6,7 @@ import Article from "./../src/models/article.js" -let articleId +let articleId; const getArticleId= async ()=>{ const all = await Article.find() @@ -49,7 +49,7 @@ it("Should retrieve the article by id", (done) => { .end((err, res) => { expect(res).to.have.status([200]); expect(res).to.have.property("status"); - expect(res.body).to.have.property("message"); + // expect(res.body).to.have.property("message"); expect(res.body).to.have.property("data"); done(); }); diff --git a/tests/comment.test.js b/tests/comment.test.js index 6692656..2a02cc3 100644 --- a/tests/comment.test.js +++ b/tests/comment.test.js @@ -1,51 +1,3 @@ - -// import chai, { expect } from 'chai' -// import chaiHttp from 'chai-http' -// import app from '../src/app.js' -// import 'dotenv/config'; -// import {comment} from "./dummyData.js" -// import Article from "./../src/models/article.js" - -// const all = await Article.find() -// let articleId=all[0]._id; - - -// chai.use(chaiHttp) -// describe("COMMENT END-POINT TESTING", () => { - -// it("It should Create the comment",(done) => { - -// chai.request(app).post(`/api/v1/comments/${articleId}`) -// .send(comment) -// .end((err,res)=>{ -// expect(res).to.have.status([201]) -// done() -// }) - -// }) - - -// it("Should retrieve comments of the Article", (done) => { -// chai.request(app).get(`/api/v1/comments/${articleId}`) -// .send() -// .end((err,res)=>{ -// expect(res).to.have.property("status") -// expect(res.body).to.have.property("message") -// expect(res.body).to.have.property("data") -// done() -// }) - -// }) -// it("Should not retrieve the comments", (done) => { -// chai.request(app).get("/api/v1/comments") -// .send() -// .end((err,res)=>{ -// expect(res).to.have.status([404]) -// done() -// }) -// }) -// }) - import chai, { expect } from 'chai' import chaiHttp from 'chai-http' import app from '../src/app.js' @@ -92,7 +44,7 @@ describe("COMMENT END-POINT TESTING", () => { }) it("Should not retrieve the comments", (done) => { - chai.request(app).get("/api/v1/cmments") + chai.request(app).get("/api/v1/commnts") .send() .end((err,res)=>{ expect(res).to.have.status([404]) diff --git a/tests/query.test.js b/tests/query.test.js index ca08723..cbf621b 100644 --- a/tests/query.test.js +++ b/tests/query.test.js @@ -2,8 +2,7 @@ import chai, { expect } from 'chai' import chaiHttp from 'chai-http' import app from '../src/app.js' import 'dotenv/config'; -import { userData, validUser, invalidUser} from './dummyData.js'; -import { postData } from './dummyData.js'; +import { userData, validUser, invalidUser, postData} from './dummyData.js'; import User from "./../src/models/user.js" chai.use(chaiHttp) @@ -40,8 +39,8 @@ describe("QUERY END-POINT TESTING", () => { .send() .end((err,res)=>{ expect(res).to.have.property("status") - expect(res.body).to.have.property("message") - expect(res.body).to.have.property("data") + // expect(res.body).to.have.property("message") + // expect(res.body).to.have.property("data") done() }) @@ -61,8 +60,6 @@ describe("QUERY END-POINT TESTING", () => { chai.request(app).get("/api/v1/qeury/") - chai.request(app).get("/api/v1/qeuries/") - .send() .end((err,res)=>{ expect(res).to.have.status([404])