aboutsummaryrefslogtreecommitdiffstats
path: root/bug/op_edit_comment_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'bug/op_edit_comment_test.go')
-rw-r--r--bug/op_edit_comment_test.go53
1 files changed, 53 insertions, 0 deletions
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")
+}