Skip to content

Commit

Permalink
test(backend): add tests for block revisions
Browse files Browse the repository at this point in the history
Add test to reproduce #1301. Seems to be working fine though.
  • Loading branch information
burdiyan committed Feb 27, 2023
1 parent 01f4e10 commit e18879f
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions backend/daemon/api/documents/v1alpha/documents_test.go
Expand Up @@ -21,6 +21,50 @@ import (
"google.golang.org/protobuf/proto"
)

func TestBug_BlockRevisionMustUpdate(t *testing.T) {
t.Parallel()

// See: https://github.com/mintterteam/mintter/issues/1301.

api := newTestDocsAPI(t, "alice")
ctx := context.Background()

doc, err := api.CreateDraft(ctx, &documents.CreateDraftRequest{})
require.NoError(t, err)
doc = updateDraft(ctx, t, api, doc.Id, []*documents.DocumentChange{
{Op: &documents.DocumentChange_SetTitle{SetTitle: "My new document title"}},
{Op: &documents.DocumentChange_MoveBlock_{MoveBlock: &documents.DocumentChange_MoveBlock{BlockId: "b1"}}},
{Op: &documents.DocumentChange_ReplaceBlock{ReplaceBlock: &documents.Block{
Id: "b1",
Type: "statement",
Text: "Hello world!",
}}},
})

pub1, err := api.PublishDraft(ctx, &documents.PublishDraftRequest{DocumentId: doc.Id})
require.NoError(t, err)

blk := pub1.Document.Children[0]
require.NotEqual(t, "", blk.Block.Revision)

// Update draft.
doc, err = api.CreateDraft(ctx, &documents.CreateDraftRequest{ExistingDocumentId: pub1.Document.Id})
require.NoError(t, err)
doc = updateDraft(ctx, t, api, doc.Id, []*documents.DocumentChange{
{Op: &documents.DocumentChange_ReplaceBlock{ReplaceBlock: &documents.Block{
Id: "b1",
Type: "statement",
Text: "Updated!",
}}},
})
pub2, err := api.PublishDraft(ctx, &documents.PublishDraftRequest{DocumentId: doc.Id})
require.NoError(t, err)

blkNew := pub2.Document.Children[0]
require.NotEqual(t, "", blkNew.Block.Revision)
require.NotEqual(t, blk.Block.Revision, blkNew.Block.Revision, "block revision must update")
}

func TestCreateDraftFromPublication(t *testing.T) {
t.Parallel()

Expand Down

1 comment on commit e18879f

@vercel
Copy link

@vercel vercel bot commented on e18879f Feb 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.