Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion quirknotes/backend/data/db/WiredTiger.turtle
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ WiredTiger 11.2.0: (November 10, 2022)
WiredTiger version
major=11,minor=2,patch=0
file:WiredTiger.wt
access_pattern_hint=none,allocation_size=4KB,app_metadata=,assert=(commit_timestamp=none,durable_timestamp=none,read_timestamp=none,write_timestamp=off),block_allocation=best,block_compressor=,cache_resident=false,checksum=on,collator=,columns=,dictionary=0,encryption=(keyid=,name=),format=btree,huffman_key=,huffman_value=,id=0,ignore_in_memory_cache_size=false,internal_item_max=0,internal_key_max=0,internal_key_truncate=true,internal_page_max=4KB,key_format=S,key_gap=10,leaf_item_max=0,leaf_key_max=0,leaf_page_max=32KB,leaf_value_max=0,log=(enabled=true),memory_page_image_max=0,memory_page_max=5MB,os_cache_dirty_max=0,os_cache_max=0,prefix_compression=false,prefix_compression_min=4,readonly=false,split_deepen_min_child=0,split_deepen_per_child=0,split_pct=90,tiered_object=false,tiered_storage=(auth_token=,bucket=,bucket_prefix=,cache_directory=,local_retention=300,name=,object_target_size=0),value_format=S,verbose=[],version=(major=1,minor=1),write_timestamp_usage=none,checkpoint=(WiredTigerCheckpoint.80=(addr="018381e4546d63488481e41f4fdcd18581e4e5dfaccc808080e3010fc0e23fc0",order=80,time=1708023407,size=28672,newest_start_durable_ts=0,oldest_start_ts=0,newest_txn=54,newest_stop_durable_ts=0,newest_stop_ts=-1,newest_stop_txn=-11,prepare=0,write_gen=239,run_write_gen=96)),checkpoint_backup_info=,checkpoint_lsn=(2,31104)
access_pattern_hint=none,allocation_size=4KB,app_metadata=,assert=(commit_timestamp=none,durable_timestamp=none,read_timestamp=none,write_timestamp=off),block_allocation=best,block_compressor=,cache_resident=false,checksum=on,collator=,columns=,dictionary=0,encryption=(keyid=,name=),format=btree,huffman_key=,huffman_value=,id=0,ignore_in_memory_cache_size=false,internal_item_max=0,internal_key_max=0,internal_key_truncate=true,internal_page_max=4KB,key_format=S,key_gap=10,leaf_item_max=0,leaf_key_max=0,leaf_page_max=32KB,leaf_value_max=0,log=(enabled=true),memory_page_image_max=0,memory_page_max=5MB,os_cache_dirty_max=0,os_cache_max=0,prefix_compression=false,prefix_compression_min=4,readonly=false,split_deepen_min_child=0,split_deepen_per_child=0,split_pct=90,tiered_object=false,tiered_storage=(auth_token=,bucket=,bucket_prefix=,cache_directory=,local_retention=300,name=,object_target_size=0),value_format=S,verbose=[],version=(major=1,minor=1),write_timestamp_usage=none,checkpoint=(WiredTigerCheckpoint.132=(addr="018381e424a0fcf28481e41f4fdcd18581e4b1d5bf34808080e3010fc0e23fc0",order=132,time=1708027302,size=28672,newest_start_durable_ts=0,oldest_start_ts=0,newest_txn=489,newest_stop_durable_ts=0,newest_stop_ts=-1,newest_stop_txn=-11,prepare=0,write_gen=395,run_write_gen=243)),checkpoint_backup_info=,checkpoint_lsn=(3,161408)
Binary file modified quirknotes/backend/data/db/WiredTiger.wt
Binary file not shown.
Binary file modified quirknotes/backend/data/db/collection-2-5500651194477838497.wt
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified quirknotes/backend/data/db/diagnostic.data/metrics.interim
Binary file not shown.
Binary file modified quirknotes/backend/data/db/index-3-5500651194477838497.wt
Binary file not shown.
Binary file modified quirknotes/backend/data/db/index-5-5500651194477838497.wt
Binary file not shown.
Binary file modified quirknotes/backend/data/db/index-6-5500651194477838497.wt
Binary file not shown.
Binary file modified quirknotes/backend/data/db/index-8-5500651194477838497.wt
Binary file not shown.
Binary file not shown.
2 changes: 1 addition & 1 deletion quirknotes/backend/data/db/mongod.lock
Original file line number Diff line number Diff line change
@@ -1 +1 @@
27516
28804
Binary file modified quirknotes/backend/data/db/sizeStorer.wt
Binary file not shown.
4 changes: 2 additions & 2 deletions quirknotes/backend/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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})
}
Expand All @@ -71,7 +71,7 @@ app.post("/postNote", express.json(), async (req, res) => {
createdAt
});
res.json({
response: "Note added succesfully.",
response: "Note added successfully.",
insertedId: result.insertedId,
});

Expand Down
262 changes: 260 additions & 2 deletions quirknotes/backend/tests/status200.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ test("1+2=3, empty array is empty", () => {

const SERVER_URL = "http://localhost:4000";


test("/postNote - Post a note", async () => {
const title = "NoteTitleTest";
const content = "NoteTitleContent";
Expand All @@ -23,5 +24,262 @@ test("/postNote - Post a note", async () => {
const postNoteBody = await postNoteRes.json();

expect(postNoteRes.status).toBe(200);
expect(postNoteBody.response).toBe("Note added succesfully.");
});
expect(postNoteBody.response).toBe("Note added successfully.");

});

test("/getAllNotes - Return list of zero notes for getAllNotes", async () => {
const deleteAllRes = await fetch(`${SERVER_URL}/deleteAllNotes`, {
method: "DELETE"
});
const getAllNotesRes = await fetch(`${SERVER_URL}/getAllNotes`, {
method: "GET"
});

const getAllNotesBody = await getAllNotesRes.json();

expect(getAllNotesRes.status).toBe(200);
expect(getAllNotesBody.response.length).toBe(0);
});

test("/getAllNotes - Return list of two notes for getAllNotes", async () => {
const deleteAllRes = await fetch(`${SERVER_URL}/deleteAllNotes`, {
method: "DELETE"
});
const title = "NoteTitleTest";
const content = "NoteTitleContent";

const postNoteRes1 = await fetch(`${SERVER_URL}/postNote`, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
title: title + "1",
content: content + "1",
}),
});
const postNoteRes2 = await fetch(`${SERVER_URL}/postNote`, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
title: title + "2",
content: content + "2",
}),
});

const getAllNotesRes = await fetch(`${SERVER_URL}/getAllNotes`, {
method: "GET"
});

const getAllNotesBody = await getAllNotesRes.json();

expect(getAllNotesRes.status).toBe(200);
expect(getAllNotesBody.response.length).toBe(2);
});

test("/deleteNote - Delete a note", async () => {
const postNoteRes = await fetch(`${SERVER_URL}/postNote`, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
title: "Title to delete",
content: "Content to delete",
}),
});
const postNoteBody = await postNoteRes.json();

const deleteNoteRes = await fetch(`${SERVER_URL}/deleteNote/${postNoteBody.insertedId}`, {
method: "DELETE",
});
const deleteNoteBody = await deleteNoteRes.json();
expect(deleteNoteRes.status).toBe(200);
expect(deleteNoteBody.response).toBe(`Document with ID ${postNoteBody.insertedId} deleted.`);
});

test("/patchNote - Patch with content and title", async () => {
const postNoteRes = await fetch(`${SERVER_URL}/postNote`, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
title: "Title to patch oops",
content: "Content to patch oops",
}),
});
const postNoteBody = await postNoteRes.json();

const patchNoteRes = await fetch(`${SERVER_URL}/patchNote/${postNoteBody.insertedId}`, {
method: "PATCH",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
title: "Title to patch",
content: "Content to patch",
}),
});

const patchNoteBody = await patchNoteRes.json();
expect(patchNoteRes.status).toBe(200);
expect(patchNoteBody.response).toBe(`Document with ID ${postNoteBody.insertedId} patched.`);
});

test("/patchNote - Patch with just title", async () => {
const postNoteRes = await fetch(`${SERVER_URL}/postNote`, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
title: "Title to patch oops",
content: "Content to patch",
}),
});
const postNoteBody = await postNoteRes.json();

const patchNoteRes = await fetch(`${SERVER_URL}/patchNote/${postNoteBody.insertedId}`, {
method: "PATCH",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
title: "Title to patch",
}),
});

const patchNoteBody = await patchNoteRes.json();
expect(patchNoteRes.status).toBe(200);
expect(patchNoteBody.response).toBe(`Document with ID ${postNoteBody.insertedId} patched.`);
});

test("/patchNote - Patch with just content", async () => {
const postNoteRes = await fetch(`${SERVER_URL}/postNote`, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
title: "Title to patch",
content: "Content to patch oops",
}),
});
const postNoteBody = await postNoteRes.json();

const patchNoteRes = await fetch(`${SERVER_URL}/patchNote/${postNoteBody.insertedId}`, {
method: "PATCH",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
content: "Content to patch",
}),
});

const patchNoteBody = await patchNoteRes.json();
expect(patchNoteRes.status).toBe(200);
expect(patchNoteBody.response).toBe(`Document with ID ${postNoteBody.insertedId} patched.`);
});

test("/deleteAllNotes - Delete one note", async () => {
const deleteAllResFirst = await fetch(`${SERVER_URL}/deleteAllNotes`, {
method: "DELETE"
});
const title = "NoteTitleTest";
const content = "NoteTitleContent";

const postNoteRes = await fetch(`${SERVER_URL}/postNote`, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
title: title,
content: content,
}),
});

const deleteAllRes = await fetch(`${SERVER_URL}/deleteAllNotes`, {
method: "DELETE"
});
const deleteAllNotesBody = await deleteAllRes.json();
expect(deleteAllRes.status).toBe(200);
expect(deleteAllNotesBody.response).toBe("1 note(s) deleted.");
});

test("/deleteAllNotes - Delete three notes", async () => {
const deleteAllResFirst = await fetch(`${SERVER_URL}/deleteAllNotes`, {
method: "DELETE"
});
const title = "NoteTitleTest";
const content = "NoteTitleContent";

const postNoteRes1 = await fetch(`${SERVER_URL}/postNote`, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
title: title + "1",
content: content + "1",
}),
});
const postNoteRes2 = await fetch(`${SERVER_URL}/postNote`, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
title: title + "2",
content: content + "2",
}),
});
const postNoteRes3 = await fetch(`${SERVER_URL}/postNote`, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
title: title + "3",
content: content + "3",
}),
});
const deleteAllRes = await fetch(`${SERVER_URL}/deleteAllNotes`, {
method: "DELETE"
});
const deleteAllNotesBody = await deleteAllRes.json();
expect(deleteAllRes.status).toBe(200);
expect(deleteAllNotesBody.response).toBe("3 note(s) deleted.");
});

test("/updateNoteColor - Update color of a note to red (#FF0000)", async () => {
const postNoteRes = await fetch(`${SERVER_URL}/postNote`, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
title: "Title to patch",
content: "Content to patch oops",
}),
});
const postNoteBody = await postNoteRes.json();

const updateNoteColorRes = await fetch(`${SERVER_URL}/updateNoteColor/${postNoteBody.insertedId}`, {
method: "PATCH",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
color: "#FF0000",
}),
});
const updateNoteColorBody = await updateNoteColorRes.json();
expect(updateNoteColorRes.status).toBe(200);
expect(updateNoteColorBody.message).toBe("Note color updated successfully.");
});