From 4b98c1ac895c41acea5022a3cd554f82b537bb74 Mon Sep 17 00:00:00 2001 From: "G.Ambatte" Date: Fri, 17 Feb 2023 11:26:11 +1300 Subject: [PATCH 01/10] Add markModified to fix authors array in DB --- server/homebrew.api.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/server/homebrew.api.js b/server/homebrew.api.js index f531bdcf9..228a08128 100644 --- a/server/homebrew.api.js +++ b/server/homebrew.api.js @@ -319,6 +319,11 @@ If you believe you should have access to this brew, ask the file owner to invite } // Otherwise, save the brew with updated author list + // markModified() is necessary to have Mongoose reduce the array length in the database + // Without it, starting with an array of ['A', 'B', 'C'] in the database: + // - when reduced to ['A', 'B'] will result in ['A', 'B', 'C'] saved in the database + // - when reduced to ['B', 'C'] will result in ['B', 'C', 'C'] saved in the database + brew.markModified('authors'); await brew.save() .catch((err)=>{ throw { status: 500, message: err }; From 2bab0b50d20f09016177489bba03620fa0f8af91 Mon Sep 17 00:00:00 2001 From: "G.Ambatte" Date: Fri, 17 Feb 2023 11:26:29 +1300 Subject: [PATCH 02/10] Add coverage folder to gitignore --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index ecd6009b6..150d81008 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,5 @@ todo.md startDB.bat startMViewer.bat .vscode + +coverage From 43d1cb12dbeb957a669c0ab307c5196ac6f7d6e7 Mon Sep 17 00:00:00 2001 From: "G.Ambatte" Date: Fri, 17 Feb 2023 11:30:16 +1300 Subject: [PATCH 03/10] Add change log entry for v3.6.1 --- changelog.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/changelog.md b/changelog.md index 3e6216607..11b354dcb 100644 --- a/changelog.md +++ b/changelog.md @@ -61,6 +61,16 @@ pre { ## changelog For a full record of development, visit our [Github Page](https://github.com/naturalcrit/homebrewery). +### Friday 17/02/2023 - v3.6.1 +{{taskList +##### G-Ambatte + +* [x] Fix users not being removed from Authors list correctly + +Fixes issues [#2674](https://github.com/naturalcrit/homebrewery/issues/2674) +}} + + ### Friday 23/01/2023 - v3.6.0 {{taskList ##### calculuschild From 860070b0c2588acea5e03a7789aae23cc0ca1bba Mon Sep 17 00:00:00 2001 From: "G.Ambatte" Date: Fri, 17 Feb 2023 15:48:55 +1300 Subject: [PATCH 04/10] Remove coverage folder from .gitignore --- .gitignore | 2 -- 1 file changed, 2 deletions(-) diff --git a/.gitignore b/.gitignore index 150d81008..ecd6009b6 100644 --- a/.gitignore +++ b/.gitignore @@ -12,5 +12,3 @@ todo.md startDB.bat startMViewer.bat .vscode - -coverage From 74e14ca72a08827cf6aeba74edd611dc113f7fc3 Mon Sep 17 00:00:00 2001 From: "G.Ambatte" Date: Fri, 17 Feb 2023 16:05:32 +1300 Subject: [PATCH 05/10] Restore coverage to .gitignore --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index ecd6009b6..150d81008 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,5 @@ todo.md startDB.bat startMViewer.bat .vscode + +coverage From 41db670e63e127d832ec9ff90da687a83f767cbe Mon Sep 17 00:00:00 2001 From: "G.Ambatte" Date: Fri, 17 Feb 2023 16:14:33 +1300 Subject: [PATCH 06/10] Add mock markModified when it does not exist --- server/homebrew.api.js | 1 + 1 file changed, 1 insertion(+) diff --git a/server/homebrew.api.js b/server/homebrew.api.js index 228a08128..afbabdc40 100644 --- a/server/homebrew.api.js +++ b/server/homebrew.api.js @@ -323,6 +323,7 @@ If you believe you should have access to this brew, ask the file owner to invite // Without it, starting with an array of ['A', 'B', 'C'] in the database: // - when reduced to ['A', 'B'] will result in ['A', 'B', 'C'] saved in the database // - when reduced to ['B', 'C'] will result in ['B', 'C', 'C'] saved in the database + if(!brew.markModified) { brew.markModified = ()=>{return true;}; }; brew.markModified('authors'); await brew.save() .catch((err)=>{ From e751f9a25cbed1e29ca558d3b646df23242f66d5 Mon Sep 17 00:00:00 2001 From: "G.Ambatte" Date: Fri, 17 Feb 2023 17:42:56 +1300 Subject: [PATCH 07/10] Remove mocking function from homebrew.api.js --- server/homebrew.api.js | 1 - 1 file changed, 1 deletion(-) diff --git a/server/homebrew.api.js b/server/homebrew.api.js index afbabdc40..228a08128 100644 --- a/server/homebrew.api.js +++ b/server/homebrew.api.js @@ -323,7 +323,6 @@ If you believe you should have access to this brew, ask the file owner to invite // Without it, starting with an array of ['A', 'B', 'C'] in the database: // - when reduced to ['A', 'B'] will result in ['A', 'B', 'C'] saved in the database // - when reduced to ['B', 'C'] will result in ['B', 'C', 'C'] saved in the database - if(!brew.markModified) { brew.markModified = ()=>{return true;}; }; brew.markModified('authors'); await brew.save() .catch((err)=>{ From 1fb7fe24875b0cb8e77b691a73169bd26edff998 Mon Sep 17 00:00:00 2001 From: "G.Ambatte" Date: Fri, 17 Feb 2023 17:43:21 +1300 Subject: [PATCH 08/10] Add markModified mock function to test spec --- server/homebrew.api.spec.js | 99 ++++++++++++++++++++----------------- 1 file changed, 53 insertions(+), 46 deletions(-) diff --git a/server/homebrew.api.spec.js b/server/homebrew.api.spec.js index 22f80155c..a244f01ef 100644 --- a/server/homebrew.api.spec.js +++ b/server/homebrew.api.spec.js @@ -11,6 +11,7 @@ describe('Tests for api', ()=>{ let modelBrew; let saveFunc; let removeFunc; + let markModifiedFunc; let saved; beforeEach(()=>{ @@ -20,12 +21,14 @@ describe('Tests for api', ()=>{ return saved; }); removeFunc = jest.fn(async function() {}); + markModifiedFunc = jest.fn(()=>true); modelBrew = (brew)=>({ ...brew, - save : saveFunc, - remove : removeFunc, - toObject : function() { + save : saveFunc, + remove : removeFunc, + markModified : markModifiedFunc, + toObject : function() { delete this.save; delete this.toObject; delete this.remove; @@ -435,27 +438,28 @@ brew`); expect(res.status).toHaveBeenCalledWith(200); expect(res.send).toHaveBeenCalledWith({ - _id : '1', - authors : ['test user'], - createdAt : undefined, - description : '', - editId : expect.any(String), - gDrive : false, - pageCount : 1, - published : false, - renderer : 'V3', - shareId : expect.any(String), - style : undefined, - systems : [], - tags : [], - text : undefined, - textBin : expect.objectContaining({}), - theme : '5ePHB', - thumbnail : '', - title : 'asdf', - trashed : false, - updatedAt : undefined, - views : 0 + _id : '1', + authors : ['test user'], + createdAt : undefined, + description : '', + editId : expect.any(String), + gDrive : false, + markModified : expect.any(Function), + pageCount : 1, + published : false, + renderer : 'V3', + shareId : expect.any(String), + style : undefined, + systems : [], + tags : [], + text : undefined, + textBin : expect.objectContaining({}), + theme : '5ePHB', + thumbnail : '', + title : 'asdf', + trashed : false, + updatedAt : undefined, + views : 0 }); }); @@ -493,28 +497,29 @@ brew`); expect(google.newGoogleBrew).toHaveBeenCalled(); expect(res.status).toHaveBeenCalledWith(200); expect(res.send).toHaveBeenCalledWith({ - _id : '1', - authors : ['test user'], - createdAt : undefined, - description : '', - editId : expect.any(String), - gDrive : false, - pageCount : undefined, - published : false, - renderer : undefined, - shareId : expect.any(String), - googleId : expect.any(String), - style : undefined, - systems : [], - tags : [], - text : undefined, - textBin : undefined, - theme : '5ePHB', - thumbnail : '', - title : 'asdf', - trashed : false, - updatedAt : undefined, - views : 0 + _id : '1', + authors : ['test user'], + createdAt : undefined, + description : '', + editId : expect.any(String), + gDrive : false, + pageCount : undefined, + published : false, + renderer : undefined, + shareId : expect.any(String), + googleId : expect.any(String), + markModified : expect.any(Function), + style : undefined, + systems : [], + tags : [], + text : undefined, + textBin : undefined, + theme : '5ePHB', + thumbnail : '', + title : 'asdf', + trashed : false, + updatedAt : undefined, + views : 0 }); }); @@ -627,6 +632,7 @@ brew`); await api.deleteBrew(req, res); expect(api.getBrew).toHaveBeenCalled(); + expect(markModifiedFunc).toHaveBeenCalled(); expect(model.findOne).toHaveBeenCalled(); expect(removeFunc).not.toHaveBeenCalled(); expect(saveFunc).toHaveBeenCalled(); @@ -716,6 +722,7 @@ brew`); await api.deleteBrew(req, res); expect(api.getBrew).toHaveBeenCalled(); + // expect(markModifiedFunc).toHaveBeenCalled(); expect(model.findOne).toHaveBeenCalled(); expect(removeFunc).not.toHaveBeenCalled(); expect(api.deleteGoogleBrew).toHaveBeenCalled(); From 298a10bc429c327a1d05efeac4f888ecdaba2064 Mon Sep 17 00:00:00 2001 From: Trevor Buckner Date: Sat, 18 Feb 2023 13:48:02 -0500 Subject: [PATCH 09/10] Clean up tests --- changelog.md | 2 +- server/homebrew.api.js | 8 +------- server/homebrew.api.spec.js | 5 ++--- 3 files changed, 4 insertions(+), 11 deletions(-) diff --git a/changelog.md b/changelog.md index 11b354dcb..10899a485 100644 --- a/changelog.md +++ b/changelog.md @@ -61,7 +61,7 @@ pre { ## changelog For a full record of development, visit our [Github Page](https://github.com/naturalcrit/homebrewery). -### Friday 17/02/2023 - v3.6.1 +### Saturday 18/02/2023 - v3.6.1 {{taskList ##### G-Ambatte diff --git a/server/homebrew.api.js b/server/homebrew.api.js index 228a08128..6f5fcb1ef 100644 --- a/server/homebrew.api.js +++ b/server/homebrew.api.js @@ -317,13 +317,7 @@ If you believe you should have access to this brew, ask the file owner to invite brew.textBin = zlib.deflateRawSync(brew.text); brew.text = undefined; } - - // Otherwise, save the brew with updated author list - // markModified() is necessary to have Mongoose reduce the array length in the database - // Without it, starting with an array of ['A', 'B', 'C'] in the database: - // - when reduced to ['A', 'B'] will result in ['A', 'B', 'C'] saved in the database - // - when reduced to ['B', 'C'] will result in ['B', 'C', 'C'] saved in the database - brew.markModified('authors'); + brew.markModified('authors'); //Mongo will not properly update arrays without markModified() await brew.save() .catch((err)=>{ throw { status: 500, message: err }; diff --git a/server/homebrew.api.spec.js b/server/homebrew.api.spec.js index a244f01ef..ee00677d5 100644 --- a/server/homebrew.api.spec.js +++ b/server/homebrew.api.spec.js @@ -32,6 +32,7 @@ describe('Tests for api', ()=>{ delete this.save; delete this.toObject; delete this.remove; + delete this.markModified; return this; } }); @@ -444,7 +445,6 @@ brew`); description : '', editId : expect.any(String), gDrive : false, - markModified : expect.any(Function), pageCount : 1, published : false, renderer : 'V3', @@ -508,7 +508,6 @@ brew`); renderer : undefined, shareId : expect.any(String), googleId : expect.any(String), - markModified : expect.any(Function), style : undefined, systems : [], tags : [], @@ -722,7 +721,7 @@ brew`); await api.deleteBrew(req, res); expect(api.getBrew).toHaveBeenCalled(); - // expect(markModifiedFunc).toHaveBeenCalled(); + expect(markModifiedFunc).toHaveBeenCalled(); expect(model.findOne).toHaveBeenCalled(); expect(removeFunc).not.toHaveBeenCalled(); expect(api.deleteGoogleBrew).toHaveBeenCalled(); From 6a8a2f080c5f326e759a616999a4bcd88fee3d5c Mon Sep 17 00:00:00 2001 From: Trevor Buckner Date: Sat, 18 Feb 2023 13:48:32 -0500 Subject: [PATCH 10/10] Lint --- server/homebrew.api.spec.js | 86 ++++++++++++++++++------------------- 1 file changed, 43 insertions(+), 43 deletions(-) diff --git a/server/homebrew.api.spec.js b/server/homebrew.api.spec.js index ee00677d5..3f3eb9794 100644 --- a/server/homebrew.api.spec.js +++ b/server/homebrew.api.spec.js @@ -439,27 +439,27 @@ brew`); expect(res.status).toHaveBeenCalledWith(200); expect(res.send).toHaveBeenCalledWith({ - _id : '1', - authors : ['test user'], - createdAt : undefined, - description : '', - editId : expect.any(String), - gDrive : false, - pageCount : 1, - published : false, - renderer : 'V3', - shareId : expect.any(String), - style : undefined, - systems : [], - tags : [], - text : undefined, - textBin : expect.objectContaining({}), - theme : '5ePHB', - thumbnail : '', - title : 'asdf', - trashed : false, - updatedAt : undefined, - views : 0 + _id : '1', + authors : ['test user'], + createdAt : undefined, + description : '', + editId : expect.any(String), + gDrive : false, + pageCount : 1, + published : false, + renderer : 'V3', + shareId : expect.any(String), + style : undefined, + systems : [], + tags : [], + text : undefined, + textBin : expect.objectContaining({}), + theme : '5ePHB', + thumbnail : '', + title : 'asdf', + trashed : false, + updatedAt : undefined, + views : 0 }); }); @@ -497,28 +497,28 @@ brew`); expect(google.newGoogleBrew).toHaveBeenCalled(); expect(res.status).toHaveBeenCalledWith(200); expect(res.send).toHaveBeenCalledWith({ - _id : '1', - authors : ['test user'], - createdAt : undefined, - description : '', - editId : expect.any(String), - gDrive : false, - pageCount : undefined, - published : false, - renderer : undefined, - shareId : expect.any(String), - googleId : expect.any(String), - style : undefined, - systems : [], - tags : [], - text : undefined, - textBin : undefined, - theme : '5ePHB', - thumbnail : '', - title : 'asdf', - trashed : false, - updatedAt : undefined, - views : 0 + _id : '1', + authors : ['test user'], + createdAt : undefined, + description : '', + editId : expect.any(String), + gDrive : false, + pageCount : undefined, + published : false, + renderer : undefined, + shareId : expect.any(String), + googleId : expect.any(String), + style : undefined, + systems : [], + tags : [], + text : undefined, + textBin : undefined, + theme : '5ePHB', + thumbnail : '', + title : 'asdf', + trashed : false, + updatedAt : undefined, + views : 0 }); });