From 5a1dfaa17ef188714bb07751b08b93da1cb15661 Mon Sep 17 00:00:00 2001 From: Mitch Date: Tue, 13 Feb 2024 23:40:54 -0500 Subject: [PATCH 1/3] add status code --- quirknotes/backend/tests/status200.test.js | 45 ++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/quirknotes/backend/tests/status200.test.js b/quirknotes/backend/tests/status200.test.js index 4b0eada..bd65f55 100644 --- a/quirknotes/backend/tests/status200.test.js +++ b/quirknotes/backend/tests/status200.test.js @@ -24,4 +24,49 @@ test("/postNote - Post a note", async () => { expect(postNoteRes.status).toBe(200); expect(postNoteBody.response).toBe("Note added succesfully."); +}); + +test("/getAllNotes - Return list of zero notes for getAllNotes", async () => { + // Code here + expect(false).toBe(true); +}); + +test("/getAllNotes - Return list of two notes for getAllNotes", async () => { + // Code here + expect(false).toBe(true); +}); + +test("/deleteNote - Delete a note", async () => { + // Code here + expect(false).toBe(true); +}); + +test("/patchNote - Patch with content and title", async () => { + // Code here + expect(false).toBe(true); +}); + +test("/patchNote - Patch with just title", async () => { + // Code here + expect(false).toBe(true); +}); + +test("/patchNote - Patch with just content", async () => { + // Code here + expect(false).toBe(true); +}); + +test("/deleteAllNotes - Delete one note", async () => { + // Code here + expect(false).toBe(true); +}); + +test("/deleteAllNotes - Delete three notes", async () => { + // Code here + expect(false).toBe(true); +}); + +test("/updateNoteColor - Update color of a note to red (#FF0000)", async () => { + // Code here + expect(false).toBe(true); }); \ No newline at end of file From 977a7d01681afe39763e2a0e731e0f22031de293 Mon Sep 17 00:00:00 2001 From: Mitch Date: Wed, 14 Feb 2024 03:54:34 -0500 Subject: [PATCH 2/3] created additional tests --- quirknotes/backend/tests/status200.test.js | 322 ++++++++++++++++++++- 1 file changed, 307 insertions(+), 15 deletions(-) diff --git a/quirknotes/backend/tests/status200.test.js b/quirknotes/backend/tests/status200.test.js index bd65f55..7ba936a 100644 --- a/quirknotes/backend/tests/status200.test.js +++ b/quirknotes/backend/tests/status200.test.js @@ -1,9 +1,4 @@ -test("1+2=3, empty array is empty", () => { - expect(1 + 2).toBe(3); - expect([].length).toBe(0); - }); - - const SERVER_URL = "http://localhost:4000"; +const SERVER_URL = "http://localhost:4000"; test("/postNote - Post a note", async () => { const title = "NoteTitleTest"; @@ -28,45 +23,342 @@ test("/postNote - Post a note", async () => { test("/getAllNotes - Return list of zero notes for getAllNotes", async () => { // Code here - expect(false).toBe(true); + const allNotes = await fetch(`${SERVER_URL}/getAllNotes`, { + method: "GET", + headers: { + "Content-Type": "application/json", + } + }) + const noteContent = await allNotes.json(); + + expect(allNotes.status).toBe(200); + expect(noteContent.response.length).toBe(0); }); test("/getAllNotes - Return list of two notes for getAllNotes", async () => { // Code here - expect(false).toBe(true); + const firstTitle = "NoteTitleTest"; + const firstContent = "NoteTitleContent"; + + const postFirstNote = await fetch(`${SERVER_URL}/postNote`, { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({ + title: firstTitle, + content: firstContent, + }) + }) + + const postFirstBody = await postFirstNote.json(); + + const secondTitle = "NoteTitleTest2"; + const secondContent = "NoteTitleContent2"; + + const postSecondNote = await fetch(`${SERVER_URL}/postNote`, { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({ + title: secondTitle, + content: secondContent, + }) + }) + + const postSecondBody = await postSecondNote.json(); + + const getBothNotes = await fetch(`${SERVER_URL}/getAllNotes`, { + method: "GET", + headers: { + "Content-Type": "application/json", + }, + }) + + const getBothNoteBody = await getBothNotes.json(); + + expect(getBothNotes.status).toBe(200); + //expect(getBothNoteBody.response.length).toBe(2); + + await fetch(`${SERVER_URL}/deleteNote/${postFirstBody.inserteddId}`, { + method: "DELETE", + headers: { + "Content-Type": "application/json", + }, + }) + + await fetch(`${SERVER_URL}/deleteNote/${postSecondBody.inserteddId}`, { + method: "DELETE", + headers: { + "Content-Type": "application/json", + }, + }) }); test("/deleteNote - Delete a note", async () => { // Code here - expect(false).toBe(true); + const title = "NoteTitleTest"; + const content = "NoteTitleContent"; + + const postNote = await fetch(`${SERVER_URL}/postNote`, { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({ + title: title, + content: content, + }) + }) + + const noteBody = await postNote.json(); + + const deleteNote = await fetch(`${SERVER_URL}/deleteNote/${noteBody.insertedId}`, { + method: "DELETE", + headers: { + "Content-Type": "application/json", + }, + }) + + expect(deleteNote.status).toBe(200); }); test("/patchNote - Patch with content and title", async () => { // Code here - expect(false).toBe(true); + const title = "NoteTitleTest"; + const content = "NoteTitleContent"; + + const postNote = await fetch(`${SERVER_URL}/postNote`, { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({ + title: title, + content: content, + }) + }) + + const postNoteBody = await postNote.json(); + + const patchTitle = "PatchNoteTitleTest"; + const patchContent = "PatchNoteTitleContent"; + + const patchNote = await fetch(`${SERVER_URL}/patchNote/${postNoteBody.insertedId}`, { + method: "PATCH", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({ + title: patchTitle, + content: patchContent, + }) + }) + + expect(patchNote.status).toBe(200); + + await fetch(`${SERVER_URL}/deleteNote/${postNoteBody.insertedId}`, { + method: "DELETE", + headers: { + "Content-Type": "application/json", + }, + }) }); test("/patchNote - Patch with just title", async () => { // Code here - expect(false).toBe(true); + const title = "NoteTitleTest"; + const content = "NoteTitleContent"; + + const postNote = await fetch(`${SERVER_URL}/postNote`, { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({ + title: title, + content: content, + }) + }) + + const postNoteBody = await postNote.json(); + + const updateTitle = "UpdateNoteTitleTest"; + const patchNote = await fetch(`${SERVER_URL}/patchNote/${postNoteBody.insertedId}`, { + method: "PATCH", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({ + title: updateTitle, + }) + }) + + expect(patchNote.status).toBe(200); + + await fetch(`${SERVER_URL}/deleteNote/${postNoteBody.insertedId}`, { + method: "DELETE", + headers: { + "Content-Type": "application/json", + }, + }) }); test("/patchNote - Patch with just content", async () => { // Code here - expect(false).toBe(true); + const title = "NoteTitleTest"; + const content = "NoteTitleContent"; + + const postNote = await fetch(`${SERVER_URL}/postNote`, { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({ + title: title, + content: content, + }) + }) + + const postNoteBody = await postNote.json(); + + const updateContent = "UpdateNoteTitleContent"; + const patchNote = await fetch(`${SERVER_URL}/patchNote/${postNoteBody.insertedId}`, { + method: "PATCH", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({ + content: updateContent, + }) + }) + + expect(patchNote.status).toBe(200); + + await fetch(`${SERVER_URL}/deleteNote/${postNoteBody.insertedId}`, { + method: "DELETE", + headers: { + "Content-Type": "application/json", + }, + }) }); test("/deleteAllNotes - Delete one note", async () => { // Code here - expect(false).toBe(true); + const title = "NoteTitleTest"; + const content = "NoteTitleContent"; + + const postNote = await fetch(`${SERVER_URL}/postNote`, { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({ + title: title, + content: content, + }) + }) + + const postNoteBody = await postNote.json(); + + const deleteNotes = await fetch(`${SERVER_URL}/deleteAllNotes`, { + method: "DELETE", + headers: { + "Content-Type": "application/json", + }, + }) + + expect(deleteNotes.status).toBe(200); }); test("/deleteAllNotes - Delete three notes", async () => { // Code here - expect(false).toBe(true); + const title = "NoteTitleTest"; + const content = "NoteTitleContent"; + + const postFirstNote = await fetch(`${SERVER_URL}/postNote`, { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({ + title: title, + content: content, + }) + }) + + const postSecondNote = await fetch(`${SERVER_URL}/postNote`, { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({ + title: title, + content: content, + }) + }) + + const postThirdNote = await fetch(`${SERVER_URL}/postNote`, { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({ + title: title, + content: content, + }) + }) + + const postFirstBody = await postFirstNote.json(); + const postSecondBody = await postSecondNote.json(); + const postThirdBody = await postThirdNote.json(); + + const deleteNotes = await fetch(`${SERVER_URL}/deleteAllNotes`, { + method: "DELETE", + headers: { + "Content-Type": "application/json", + }, + }) + + //const deleteNoteBody = deleteNotes.json(); + expect(deleteNotes.status).toBe(200); }); test("/updateNoteColor - Update color of a note to red (#FF0000)", async () => { // Code here - expect(false).toBe(true); + const title = "NoteTitleTest"; + const content = "NoteTitleContent"; + + const postNote = await fetch(`${SERVER_URL}/postNote`, { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({ + title: title, + content: content, + }) + }) + + const postNoteBody = await postNote.json(); + + const updateNoteColour = await fetch(`${SERVER_URL}/updateNoteColor/${postNoteBody.insertedId}`, { + method: "PATCH", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({ + color: "#FF0000", + }) + }) + + expect(updateNoteColour.status).toBe(200); + + await fetch(`${SERVER_URL}/deleteNote/${postNoteBody.insertedId}`, { + method: "DELETE", + headers: { + "Content-Type": "application/json", + }, + }) }); \ No newline at end of file From a21bab96bc394a32a12b8ae2161ef4e75344242a Mon Sep 17 00:00:00 2001 From: Mitch Date: Fri, 16 Feb 2024 21:53:12 -0500 Subject: [PATCH 3/3] updated tests to include body responses --- quirknotes/backend/server.js | 2 +- quirknotes/backend/tests/status200.test.js | 99 ++++++++++++++-------- 2 files changed, 63 insertions(+), 38 deletions(-) diff --git a/quirknotes/backend/server.js b/quirknotes/backend/server.js index 96c7894..253363c 100644 --- a/quirknotes/backend/server.js +++ b/quirknotes/backend/server.js @@ -44,7 +44,7 @@ app.get("/getAllNotes", express.json(), async (req, res) => { // Find notes with username attached to them const collection = db.collection(COLLECTIONS.notes); const data = await collection.find().toArray(); - res.json({ response: [] }); + res.json({ response: data }); } catch (error) { res.status(500).json({error: error.message}) } diff --git a/quirknotes/backend/tests/status200.test.js b/quirknotes/backend/tests/status200.test.js index 7ba936a..f761955 100644 --- a/quirknotes/backend/tests/status200.test.js +++ b/quirknotes/backend/tests/status200.test.js @@ -23,6 +23,13 @@ test("/postNote - Post a note", async () => { test("/getAllNotes - Return list of zero notes for getAllNotes", async () => { // Code here + await fetch(`${SERVER_URL}/deleteAllNotes`, { + method: "DELETE", + headers: { + "Content-Type": "application/json", + }, + }); + const allNotes = await fetch(`${SERVER_URL}/getAllNotes`, { method: "GET", headers: { @@ -37,10 +44,17 @@ test("/getAllNotes - Return list of zero notes for getAllNotes", async () => { test("/getAllNotes - Return list of two notes for getAllNotes", async () => { // Code here + await fetch(`${SERVER_URL}/deleteAllNotes`, { + method: "DELETE", + headers: { + "Content-Type": "application/json", + }, + }); + const firstTitle = "NoteTitleTest"; const firstContent = "NoteTitleContent"; - const postFirstNote = await fetch(`${SERVER_URL}/postNote`, { + await fetch(`${SERVER_URL}/postNote`, { method: "POST", headers: { "Content-Type": "application/json", @@ -50,13 +64,11 @@ test("/getAllNotes - Return list of two notes for getAllNotes", async () => { content: firstContent, }) }) - - const postFirstBody = await postFirstNote.json(); const secondTitle = "NoteTitleTest2"; const secondContent = "NoteTitleContent2"; - const postSecondNote = await fetch(`${SERVER_URL}/postNote`, { + await fetch(`${SERVER_URL}/postNote`, { method: "POST", headers: { "Content-Type": "application/json", @@ -66,8 +78,6 @@ test("/getAllNotes - Return list of two notes for getAllNotes", async () => { content: secondContent, }) }) - - const postSecondBody = await postSecondNote.json(); const getBothNotes = await fetch(`${SERVER_URL}/getAllNotes`, { method: "GET", @@ -79,21 +89,7 @@ test("/getAllNotes - Return list of two notes for getAllNotes", async () => { const getBothNoteBody = await getBothNotes.json(); expect(getBothNotes.status).toBe(200); - //expect(getBothNoteBody.response.length).toBe(2); - - await fetch(`${SERVER_URL}/deleteNote/${postFirstBody.inserteddId}`, { - method: "DELETE", - headers: { - "Content-Type": "application/json", - }, - }) - - await fetch(`${SERVER_URL}/deleteNote/${postSecondBody.inserteddId}`, { - method: "DELETE", - headers: { - "Content-Type": "application/json", - }, - }) + expect(getBothNoteBody.response.length).toBe(2); }); test("/deleteNote - Delete a note", async () => { @@ -121,7 +117,10 @@ test("/deleteNote - Delete a note", async () => { }, }) + const deleteNoteBody = await deleteNote.json(); + expect(deleteNote.status).toBe(200); + expect(deleteNoteBody.response).toBe(`Document with ID ${noteBody.insertedId} deleted.`) }); test("/patchNote - Patch with content and title", async () => { @@ -156,7 +155,10 @@ test("/patchNote - Patch with content and title", async () => { }) }) + const patchNoteBody = await patchNote.json(); + expect(patchNote.status).toBe(200); + expect(patchNoteBody.response).toBe(`Document with ID ${postNoteBody.insertedId} patched.`) await fetch(`${SERVER_URL}/deleteNote/${postNoteBody.insertedId}`, { method: "DELETE", @@ -195,7 +197,10 @@ test("/patchNote - Patch with just title", async () => { }) }) + const patchNoteBody = await patchNote.json(); + expect(patchNote.status).toBe(200); + expect(patchNoteBody.response).toBe(`Document with ID ${postNoteBody.insertedId} patched.`) await fetch(`${SERVER_URL}/deleteNote/${postNoteBody.insertedId}`, { method: "DELETE", @@ -234,7 +239,10 @@ test("/patchNote - Patch with just content", async () => { }) }) + const patchNoteBody = await patchNote.json(); + expect(patchNote.status).toBe(200); + expect(patchNoteBody.response).toBe(`Document with ID ${postNoteBody.insertedId} patched.`) await fetch(`${SERVER_URL}/deleteNote/${postNoteBody.insertedId}`, { method: "DELETE", @@ -246,10 +254,17 @@ test("/patchNote - Patch with just content", async () => { test("/deleteAllNotes - Delete one note", async () => { // Code here + await fetch(`${SERVER_URL}/deleteAllNotes`, { + method: "DELETE", + headers: { + "Content-Type": "application/json", + }, + }) + const title = "NoteTitleTest"; const content = "NoteTitleContent"; - const postNote = await fetch(`${SERVER_URL}/postNote`, { + await fetch(`${SERVER_URL}/postNote`, { method: "POST", headers: { "Content-Type": "application/json", @@ -260,16 +275,19 @@ test("/deleteAllNotes - Delete one note", async () => { }) }) - const postNoteBody = await postNote.json(); + //const postNoteBody = await postNote.json(); - const deleteNotes = await fetch(`${SERVER_URL}/deleteAllNotes`, { + const deleteNote = await fetch(`${SERVER_URL}/deleteAllNotes`, { method: "DELETE", headers: { "Content-Type": "application/json", }, }) - expect(deleteNotes.status).toBe(200); + const deleteNoteBody = await deleteNote.json(); + + expect(deleteNote.status).toBe(200); + expect(deleteNoteBody.response).toBe(`1 note(s) deleted.`); }); test("/deleteAllNotes - Delete three notes", async () => { @@ -277,7 +295,7 @@ test("/deleteAllNotes - Delete three notes", async () => { const title = "NoteTitleTest"; const content = "NoteTitleContent"; - const postFirstNote = await fetch(`${SERVER_URL}/postNote`, { + await fetch(`${SERVER_URL}/postNote`, { method: "POST", headers: { "Content-Type": "application/json", @@ -288,31 +306,33 @@ test("/deleteAllNotes - Delete three notes", async () => { }) }) - const postSecondNote = await fetch(`${SERVER_URL}/postNote`, { + const title2 = "NoteTitleTest2"; + const content2 = "NoteTitleContent2"; + + await fetch(`${SERVER_URL}/postNote`, { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify({ - title: title, - content: content, + title: title2, + content: content2, }) }) - const postThirdNote = await fetch(`${SERVER_URL}/postNote`, { + const title3 = "NoteTitleTest3"; + const content3 = "NoteTitleContent3"; + + await fetch(`${SERVER_URL}/postNote`, { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify({ - title: title, - content: content, + title: title3, + content: content3, }) }) - - const postFirstBody = await postFirstNote.json(); - const postSecondBody = await postSecondNote.json(); - const postThirdBody = await postThirdNote.json(); const deleteNotes = await fetch(`${SERVER_URL}/deleteAllNotes`, { method: "DELETE", @@ -321,8 +341,10 @@ test("/deleteAllNotes - Delete three notes", async () => { }, }) - //const deleteNoteBody = deleteNotes.json(); + const deleteNotesBody = await deleteNotes.json(); + expect(deleteNotes.status).toBe(200); + expect(deleteNotesBody.response).toBe(`3 note(s) deleted.`); }); test("/updateNoteColor - Update color of a note to red (#FF0000)", async () => { @@ -353,7 +375,10 @@ test("/updateNoteColor - Update color of a note to red (#FF0000)", async () => { }) }) + const updateNoteColorBody = await updateNoteColour.json(); + expect(updateNoteColour.status).toBe(200); + expect(updateNoteColorBody.message).toBe(`Note color updated successfully.`); await fetch(`${SERVER_URL}/deleteNote/${postNoteBody.insertedId}`, { method: "DELETE",