From 1b6d41b7deff86c25ee5f961befe5601de1a9435 Mon Sep 17 00:00:00 2001 From: Ben Silverman Date: Tue, 28 Jul 2020 14:58:36 -0400 Subject: [PATCH] #17 write document tests --- package-lock.json | 63 ++++++++++++++++++++++++++++++ package.json | 3 +- src/__tests__/api/document.test.js | 23 +++++++++++ 3 files changed, 88 insertions(+), 1 deletion(-) create mode 100644 src/__tests__/api/document.test.js diff --git a/package-lock.json b/package-lock.json index 266790ad..d952f4b8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -4238,6 +4238,12 @@ "safe-buffer": "~5.1.1" } }, + "cookiejar": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/cookiejar/-/cookiejar-2.1.2.tgz", + "integrity": "sha512-Mw+adcfzPxcPeI+0WlvRrr/3lGVO0bD75SxX6811cxSh1Wbxx7xZBGK1eVtDf6si8rg2lhnUjsVLMFMfbRIuwA==", + "dev": true + }, "copy-concurrently": { "version": "1.0.5", "resolved": "https://registry.npmjs.org/copy-concurrently/-/copy-concurrently-1.0.5.tgz", @@ -6066,6 +6072,12 @@ "mime-types": "^2.1.12" } }, + "formidable": { + "version": "1.2.2", + "resolved": "https://registry.npmjs.org/formidable/-/formidable-1.2.2.tgz", + "integrity": "sha512-V8gLm+41I/8kguQ4/o1D3RIHRmhYFG4pnNyonvua+40rqcEmT4+V71yaZ3B457xbbgCsCfjSPi65u/W6vK1U5Q==", + "dev": true + }, "formik": { "version": "2.1.4", "resolved": "https://registry.npmjs.org/formik/-/formik-2.1.4.tgz", @@ -8925,6 +8937,12 @@ "resolved": "https://registry.npmjs.org/merge-stream/-/merge-stream-2.0.0.tgz", "integrity": "sha512-abv/qOcuPfk3URPfDzmZU1LKmuw8kT+0nIHvKrKgFrwifol/doWcdA4ZqsWQ8ENrFKkd67Mfpo/LovbIUsbt3w==" }, + "methods": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/methods/-/methods-1.1.2.tgz", + "integrity": "sha1-VSmk1nZUE07cxSZmVoNbD4Ua/O4=", + "dev": true + }, "microevent.ts": { "version": "0.1.1", "resolved": "https://registry.npmjs.org/microevent.ts/-/microevent.ts-0.1.1.tgz", @@ -8966,6 +8984,12 @@ } } }, + "mime": { + "version": "1.6.0", + "resolved": "https://registry.npmjs.org/mime/-/mime-1.6.0.tgz", + "integrity": "sha512-x0Vn8spI+wuJ1O6S7gnbaQg8Pxh4NNHb7KSINmEWKiPE4RKOplvijn+NkmYmmRgP68mc70j2EbeTFRsrswaQeg==", + "dev": true + }, "mime-db": { "version": "1.44.0", "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.44.0.tgz", @@ -12342,6 +12366,45 @@ "resolved": "https://registry.npmjs.org/stylis-rule-sheet/-/stylis-rule-sheet-0.0.10.tgz", "integrity": "sha512-nTbZoaqoBnmK+ptANthb10ZRZOGC+EmTLLUxeYIuHNkEKcmKgXX1XWKkUBT2Ac4es3NybooPe0SmvKdhKJZAuw==" }, + "superagent": { + "version": "3.8.3", + "resolved": "https://registry.npmjs.org/superagent/-/superagent-3.8.3.tgz", + "integrity": "sha512-GLQtLMCoEIK4eDv6OGtkOoSMt3D+oq0y3dsxMuYuDvaNUvuT8eFBuLmfR0iYYzHC1e8hpzC6ZsxbuP6DIalMFA==", + "dev": true, + "requires": { + "component-emitter": "^1.2.0", + "cookiejar": "^2.1.0", + "debug": "^3.1.0", + "extend": "^3.0.0", + "form-data": "^2.3.1", + "formidable": "^1.2.0", + "methods": "^1.1.1", + "mime": "^1.4.1", + "qs": "^6.5.1", + "readable-stream": "^2.3.5" + }, + "dependencies": { + "debug": { + "version": "3.2.6", + "resolved": "https://registry.npmjs.org/debug/-/debug-3.2.6.tgz", + "integrity": "sha512-mel+jf7nrtEl5Pn1Qx46zARXKDpBbvzezse7p7LqINmdoIk8PYP5SySaxEmYv6TZ0JyEKA1hsCId6DIhgITtWQ==", + "dev": true, + "requires": { + "ms": "^2.1.1" + } + } + } + }, + "supertest": { + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/supertest/-/supertest-4.0.2.tgz", + "integrity": "sha512-1BAbvrOZsGA3YTCWqbmh14L0YEq0EGICX/nBnfkfVJn7SrxQV1I3pMYjSzG9y/7ZU2V9dWqyqk2POwxlb09duQ==", + "dev": true, + "requires": { + "methods": "^1.1.2", + "superagent": "^3.8.3" + } + }, "supports-color": { "version": "6.1.0", "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-6.1.0.tgz", diff --git a/package.json b/package.json index f20e6b57..4639512c 100644 --- a/package.json +++ b/package.json @@ -62,6 +62,7 @@ "identity-obj-proxy": "^3.0.0", "jest": "^25.1.0", "jest-fetch-mock": "^3.0.3", - "react-test-renderer": "^16.12.0" + "react-test-renderer": "^16.12.0", + "supertest": "^4.0.2" } } diff --git a/src/__tests__/api/document.test.js b/src/__tests__/api/document.test.js new file mode 100644 index 00000000..95845096 --- /dev/null +++ b/src/__tests__/api/document.test.js @@ -0,0 +1,23 @@ +const { createServer } = require('http'); +const request = require('supertest'); +const nc = require('next-connect'); +const postDocument = require('../../utils/dbUtil'); + +describe('document POST endpoint', () => { + const url = '/'; + const handler = nc().post(url, postDocument); + + it('results in 404 on get', async () => { + const app = createServer(handler); + const result = await request(app).get(url); + expect(result.status).toBe(404); + }); + + it('results in 200 on post', async () => { + const app = createServer(handler); + const result = await request(app).post(url).send({ + text: 'test', + }); + expect(result.status).toBe(200); + }); +});