From e6c3a7f299abfde5980d18aa07be543f8e6706ac Mon Sep 17 00:00:00 2001 From: Jimpulse48 <107091480+Jimpulse48@users.noreply.github.com> Date: Tue, 16 May 2023 16:42:56 -0500 Subject: [PATCH 1/2] Installed supertest and added jest to our eslint --- .eslintrc.json | 5 +++-- package.json | 1 + 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index 48e35cb..8f2d3ac 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -3,7 +3,8 @@ "env": { "node": true, "browser": true, - "es2021": true + "es2021": true, + "jest": true }, "plugins": ["import", "react", "jsx-a11y", "css-modules"], "extends": [ @@ -39,4 +40,4 @@ } } } -} \ No newline at end of file +} diff --git a/package.json b/package.json index a287341..29c43fe 100644 --- a/package.json +++ b/package.json @@ -51,6 +51,7 @@ "nodemon": "^2.0.22", "sass-loader": "^13.2.2", "style-loader": "^3.3.2", + "supertest": "^6.3.3", "webpack": "^5.82.1", "webpack-cli": "^5.1.1", "webpack-dev-server": "^4.15.0" From 775f560714f1e7b9e08e9a8758a34158c4c600d9 Mon Sep 17 00:00:00 2001 From: Jimpulse48 <107091480+Jimpulse48@users.noreply.github.com> Date: Tue, 16 May 2023 16:53:57 -0500 Subject: [PATCH 2/2] Tests for GET request to snippets endpoint --- __tests__/routes.js | 65 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 __tests__/routes.js diff --git a/__tests__/routes.js b/__tests__/routes.js new file mode 100644 index 0000000..5abc219 --- /dev/null +++ b/__tests__/routes.js @@ -0,0 +1,65 @@ +const request = require('supertest'); + +const server = 'http://localhost:3000'; + +describe('Snippets route', () => { + describe('GET', () => { + xit('responds with 200 status and json', () => { + return request(server) + .get('/snippets') + .expect(200) + .expect('Content-Type', 'application/json') + .end((err, res) => { + if (err) throw err; + }); + }); + xit('responds with data that has keys: title, comments, storedCode, language', () => { + return request(server) + .get('/snippets') + .expect((res) => { + if (!res.body.hasOwnProperty('title')) { + throw new Error("Expected 'title' key!"); + } + if (!res.body.hasOwnProperty('comments')) { + throw new Error("Expected 'comments' key!"); + } + if (!res.body.hasOwnProperty('language')) { + throw new Error("Expected 'language' key!"); + } + if (!res.body.hasOwnProperty('storedCode')) { + throw new Error("Expected 'storedCode' key!"); + } + }) + .end((err, res) => { + if (err) throw err; + }); + }); + xit('responds with data that has key, tags, and value of an array', () => { + return request(server) + .get('/snippets') + .expect((res) => { + if (!res.body.hasOwnProperty('tags')) { + throw new Error("Expected 'tags' key!"); + } + if (!Array.isArray(res.body.tags)) { + throw new Error("Expected 'tags' to be an array!"); + } + }) + .end((err, res) => { + if (err) throw err; + }); + }); + }); + describe('POST', () => {}); + describe('PUT', () => {}); + describe('DELETE', () => {}); +}); + +describe('Authentication route', () => { + describe('GET', () => {}); + describe('POST', () => {}); +}); + +describe('Invalid route', () => { + describe('GET', () => {}); +});