Skip to content

Commit

Permalink
Merge pull request #2675 from G-Ambatte/fixAuthorDeletion-#2674
Browse files Browse the repository at this point in the history
Fix author deletion #2674
  • Loading branch information
calculuschild authored Feb 18, 2023
2 parents b6a95a2 + 6a8a2f0 commit 4fca81f
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 5 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@ todo.md
startDB.bat
startMViewer.bat
.vscode

coverage
10 changes: 10 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,16 @@ pre {
## changelog
For a full record of development, visit our [Github Page](https://github.com/naturalcrit/homebrewery).

### Saturday 18/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
Expand Down
3 changes: 1 addition & 2 deletions server/homebrew.api.js
Original file line number Diff line number Diff line change
Expand Up @@ -317,8 +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
brew.markModified('authors'); //Mongo will not properly update arrays without markModified()
await brew.save()
.catch((err)=>{
throw { status: 500, message: err };
Expand Down
12 changes: 9 additions & 3 deletions server/homebrew.api.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ describe('Tests for api', ()=>{
let modelBrew;
let saveFunc;
let removeFunc;
let markModifiedFunc;
let saved;

beforeEach(()=>{
Expand All @@ -20,15 +21,18 @@ 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;
delete this.markModified;
return this;
}
});
Expand Down Expand Up @@ -627,6 +631,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();
Expand Down Expand Up @@ -716,6 +721,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();
Expand Down

0 comments on commit 4fca81f

Please sign in to comment.