diff --git a/client/cypress/integration/1-add-new-note_spec.js b/client/cypress/integration/1-add-new-note_spec.js
index 9467cb3..95b1e6d 100644
--- a/client/cypress/integration/1-add-new-note_spec.js
+++ b/client/cypress/integration/1-add-new-note_spec.js
@@ -116,7 +116,7 @@ describe(`Notes creation ${seed}`, function() {
});
describe(`Notes sharing ${seed}`, function() {
- it(`alice.${seed} share a new note, extends share`, function() {
+ it(`alice.${seed} share a new note`, function() {
cy.visit("/");
cy.login(`alice.${seed}`, password);
@@ -188,6 +188,7 @@ describe(`Notes sharing ${seed}`, function() {
// Force refresh, status of note should change.
// TODO : remove the need to refresh
+ cy.wait(2000);
cy.get('[data-test="refresh"]').click();
cy.wait(2000);
@@ -234,15 +235,7 @@ describe(`Sharing with groups ${seed}`, () => {
});
cy.get('[data-test="save"]').click();
- cy.contains(group1name).should("exist");
- });
-
- it(`alice ${seed} add a note to the group`, () => {
- cy.visit("/");
- cy.login(username, password);
- // Select the group
cy.contains(group1name).click();
- // Create notes
for (let note of notes) {
cy.contains("button", "New Note", {
@@ -261,6 +254,20 @@ describe(`Sharing with groups ${seed}`, () => {
}
});
+ it(`alice ${seed} access to the group`, () => {
+ cy.visit("/");
+ cy.login(username, password);
+ // Select the group
+ cy.contains(group1name).click();
+ // Create notes
+
+ for (let note of notes) {
+ cy.contains(".panel-body", note.content, { timeout: 30000 }).should(
+ "exist"
+ );
+ }
+ });
+
it(`bob ${seed} access to the group`, () => {
cy.visit("/");
cy.login(`bob.${seed}`, password);
@@ -358,7 +365,9 @@ describe(`Sharing with groups ${seed}`, () => {
cy.wait(5000);
- // Don't see the note
+ cy.contains(notes[0].content).should("exist");
+
+ // Don't see the second note
cy.get(".panel-body").should("not.contain", notes[1].content);
});
});
diff --git a/client/src/actions/notes.js b/client/src/actions/notes.js
index e432bfc..66236c3 100644
--- a/client/src/actions/notes.js
+++ b/client/src/actions/notes.js
@@ -50,7 +50,7 @@ function postNote(note, users, groupID) {
const response = await notesService.postNote(note, groupID, users);
note.ID = response.noteID;
await notesService.shareNote(note, users);
- const newNote = await notesService.getNote(note.ID);
+ const newNote = await notesService.getNote(note.ID, groupID);
dispatch(success(newNote));
} catch (error) {
dispatch(failure(error));
diff --git a/client/src/components/NoteLayout.js b/client/src/components/NoteLayout.js
index 85013fe..d23e215 100644
--- a/client/src/components/NoteLayout.js
+++ b/client/src/components/NoteLayout.js
@@ -22,22 +22,22 @@ export const NoteLayout = ({
{Content}
{Error && {Error}}
-
-
- {group != null ? null : (
-
- )}
- {DeletedAt || (
+ {DeletedAt || (
+
+
+ {group != null ? null : (
+
+ )}
- )}
-
-
+
+
+ )}
);
diff --git a/client/src/services/notes.js b/client/src/services/notes.js
index 1873d28..ab69214 100644
--- a/client/src/services/notes.js
+++ b/client/src/services/notes.js
@@ -20,14 +20,16 @@ export async function postNote(note, groupID, users) {
return handleResponse(response);
}
-export async function getNote(id) {
+export async function getNote(id, groupID) {
const requestOptions = {
method: "GET",
headers: authHeader(false)
};
const response = await fetch(
- `${process.env.REACT_APP_API_URL}/auth/notes/${id}`,
+ `${process.env.REACT_APP_API_URL}/auth${
+ groupID !== undefined ? `/group/${groupID}` : ""
+ }/notes/${id}`,
requestOptions
);
const { note } = await handleResponse(response);
diff --git a/server/main.go b/server/main.go
index b81f764..9f8edf5 100644
--- a/server/main.go
+++ b/server/main.go
@@ -99,6 +99,7 @@ func (e *Env) httpEngine() *gin.Engine {
group.PATCH("", e.groupEditHandler)
group.GET("/notes", e.noteGroupListHandler)
group.POST("/notes", e.noteGroupPostHandler)
+ group.GET("/notes/:noteId", e.noteGroupGetHandler)
group.DELETE("/notes/:noteId", e.noteGroupDeleteHandler)
}
diff --git a/server/main_test.go b/server/main_test.go
index 215228f..1e155ed 100644
--- a/server/main_test.go
+++ b/server/main_test.go
@@ -522,6 +522,16 @@ func TestGroup(t *testing.T) {
if note0["Title"].(string) != "this is title group" {
t.Fatalf("First note has wrong title: %v", note0["Title"].(string))
}
+ // Test get of 1 note
+ // get notes and check length
+ result, err = getJSON(t, fmt.Sprintf("/auth/group/%v/notes/%v", groupID, note0["ID"]), token1, 200)
+ if err != nil {
+ t.Fatalf("Non-expected error: %v", err)
+ }
+ newNote0 := result["note"].(map[string]interface{})
+ if note0["CreatedAt"] != newNote0["CreatedAt"] {
+ t.Fatalf("Group note is different than before")
+ }
// user2 can access group 2, not user 3
_, err = getJSON(t, fmt.Sprintf("/auth/group/%v/notes", sharedGroupID), token2, 200)
if err != nil {
diff --git a/server/notes.go b/server/notes.go
index 9c8226b..6692cbf 100644
--- a/server/notes.go
+++ b/server/notes.go
@@ -158,6 +158,24 @@ func (e *Env) noteGroupPostHandler(c *gin.Context) {
})
}
+func (e *Env) noteGroupGetHandler(c *gin.Context) {
+ var group Group
+ var note Note
+ groupID := c.Param("id")
+ noteID := c.Param("noteId")
+ err := e.db.First(&group, groupID).Error
+ if err != nil {
+ c.JSON(http.StatusUnauthorized, gin.H{"err": err})
+ return
+ }
+ err = e.db.Model(&group).Where("notes.id = ?", noteID).Related(¬e, "Notes").Error
+ if err != nil {
+ c.JSON(http.StatusUnauthorized, gin.H{"err": err})
+ return
+ }
+ c.JSON(http.StatusOK, gin.H{"note": note})
+}
+
func (e *Env) noteGroupListHandler(c *gin.Context) {
var group Group
var notes []Note