From c46d01f8c10e6363b680fa6876e91bd8eaf3bb3e Mon Sep 17 00:00:00 2001 From: Michael Muré Date: Sat, 29 Sep 2018 20:41:19 +0200 Subject: bug: implement comment edition - add a new operation - add a new "timeline" in the snapshot that hold a processed version of the operations --- bug/op_edit_comment_test.go | 53 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 bug/op_edit_comment_test.go (limited to 'bug/op_edit_comment_test.go') diff --git a/bug/op_edit_comment_test.go b/bug/op_edit_comment_test.go new file mode 100644 index 00000000..9c32051d --- /dev/null +++ b/bug/op_edit_comment_test.go @@ -0,0 +1,53 @@ +package bug + +import ( + "testing" + "time" + + "gotest.tools/assert" +) + +func TestEdit(t *testing.T) { + snapshot := Snapshot{} + + var rene = Person{ + Name: "René Descartes", + Email: "rene@descartes.fr", + } + + unix := time.Now().Unix() + + create := NewCreateOp(rene, unix, "title", "create", nil) + create.Apply(&snapshot) + + hash1, err := create.Hash() + if err != nil { + t.Fatal(err) + } + + comment := NewAddCommentOp(rene, unix, "comment", nil) + comment.Apply(&snapshot) + + hash2, err := comment.Hash() + if err != nil { + t.Fatal(err) + } + + edit := NewEditCommentOp(rene, unix, hash1, "create edited", nil) + edit.Apply(&snapshot) + + assert.Equal(t, len(snapshot.Timeline), 2) + assert.Equal(t, len(snapshot.Timeline[0].(*CreateTimelineItem).History), 2) + assert.Equal(t, len(snapshot.Timeline[1].(*CommentTimelineItem).History), 1) + assert.Equal(t, snapshot.Comments[0].Message, "create edited") + assert.Equal(t, snapshot.Comments[1].Message, "comment") + + edit2 := NewEditCommentOp(rene, unix, hash2, "comment edited", nil) + edit2.Apply(&snapshot) + + assert.Equal(t, len(snapshot.Timeline), 2) + assert.Equal(t, len(snapshot.Timeline[0].(*CreateTimelineItem).History), 2) + assert.Equal(t, len(snapshot.Timeline[1].(*CommentTimelineItem).History), 2) + assert.Equal(t, snapshot.Comments[0].Message, "create edited") + assert.Equal(t, snapshot.Comments[1].Message, "comment edited") +} -- cgit