Skip to content
This repository has been archived by the owner on Jan 2, 2025. It is now read-only.

Commit

Permalink
fix(daemon): rename + tests
Browse files Browse the repository at this point in the history
  • Loading branch information
juligasa committed Apr 23, 2024
1 parent 9d0b0d4 commit bdb48b3
Show file tree
Hide file tree
Showing 10 changed files with 182 additions and 172 deletions.
4 changes: 2 additions & 2 deletions backend/daemon/api/entities/v1alpha/entities.go
Original file line number Diff line number Diff line change
Expand Up @@ -513,8 +513,8 @@ func (api *Server) DeleteEntity(ctx context.Context, in *entities.DeleteEntityRe
return &emptypb.Empty{}, err
}

// RestoreEntity implements the corresponding gRPC method.
func (api *Server) RestoreEntity(ctx context.Context, in *entities.RestoreEntityRequest) (*emptypb.Empty, error) {
// UndeleteEntity implements the corresponding gRPC method.
func (api *Server) UndeleteEntity(ctx context.Context, in *entities.UndeleteEntityRequest) (*emptypb.Empty, error) {
if in.Id == "" {
return nil, status.Errorf(codes.InvalidArgument, "must specify entity ID to restore")
}
Expand Down
2 changes: 1 addition & 1 deletion backend/daemon/api/entities/v1alpha/entities_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ func TestDeleteEntity(t *testing.T) {
}

func newTestDocsAPI(t *testing.T, db *sqlitex.Pool, name string) *documents.Server {
u := coretest.NewTester("alice")
u := coretest.NewTester(name)

fut := future.New[core.Identity]()
require.NoError(t, fut.Resolve(u.Identity))
Expand Down
20 changes: 15 additions & 5 deletions backend/daemon/daemon_e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,8 @@ func TestAPIDeleteAndRestoreEntity(t *testing.T) {
require.Equal(t, doc.Document.Id, lst.DeletedEntities[0].Id)
require.Equal(t, reason, lst.DeletedEntities[0].DeletedReason)

// bob creates another document that should get to Alice
BobsPub := publishDocument(t, ctx, bob, "")
// Even if we sync we shouldn't get the document back
_, err = alice.RPC.Daemon.ForceSync(ctx, &daemon.ForceSyncRequest{})
require.NoError(t, err)
Expand All @@ -280,8 +282,8 @@ func TestAPIDeleteAndRestoreEntity(t *testing.T) {

pubList, err := alice.RPC.Documents.ListPublications(ctx, &documents.ListPublicationsRequest{})
require.NoError(t, err)
require.Len(t, pubList.Publications, 1)
require.Equal(t, pubList.Publications[0].Document.Id, linkedDoc.Document.Id, "Alice SHould see the document linking the deleted one")
require.Len(t, pubList.Publications, 2)
require.Equal(t, pubList.Publications[1].Document.Id, linkedDoc.Document.Id, "Alice Should see the document linking the deleted one")

_, err = alice.RPC.Documents.GetComment(ctx, &documents.GetCommentRequest{
Id: reply.Id,
Expand All @@ -291,8 +293,16 @@ func TestAPIDeleteAndRestoreEntity(t *testing.T) {
Id: comment.Id,
})
require.Error(t, err)

// But she should get Bob's document
_, err = alice.RPC.Documents.GetPublication(ctx, &documents.GetPublicationRequest{
DocumentId: BobsPub.Document.Id,
LocalOnly: true,
})
require.NoError(t, err)

// Only after restoring the document we should get it back.
_, err = alice.RPC.Entities.RestoreEntity(ctx, &entities.RestoreEntityRequest{
_, err = alice.RPC.Entities.UndeleteEntity(ctx, &entities.UndeleteEntityRequest{
Id: doc.Document.Id,
})
require.NoError(t, err)
Expand All @@ -314,8 +324,8 @@ func TestAPIDeleteAndRestoreEntity(t *testing.T) {

pubList, err = alice.RPC.Documents.ListPublications(ctx, &documents.ListPublicationsRequest{})
require.NoError(t, err)
require.Len(t, pubList.Publications, 2)
require.Equal(t, pubList.Publications[1].Document.Id, doc.Document.Id, "alice should see her document on the list")
require.Len(t, pubList.Publications, 3)
require.Equal(t, pubList.Publications[2].Document.Id, doc.Document.Id, "alice should see her document on the list")

comm, err = alice.RPC.Documents.GetComment(ctx, &documents.GetCommentRequest{
Id: comment.Id,
Expand Down
240 changes: 120 additions & 120 deletions backend/genproto/entities/v1alpha/entities.pb.go

Large diffs are not rendered by default.

34 changes: 17 additions & 17 deletions backend/genproto/entities/v1alpha/entities_grpc.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/* eslint-disable */
// @ts-nocheck

import { Change, DeleteEntityRequest, DiscoverEntityRequest, DiscoverEntityResponse, EntityTimeline, GetChangeRequest, GetEntityTimelineRequest, ListDeletedEntitiesRequest, ListDeletedEntitiesResponse, ListEntityMentionsRequest, ListEntityMentionsResponse, RestoreEntityRequest, SearchEntitiesRequest, SearchEntitiesResponse } from "./entities_pb";
import { Change, DeleteEntityRequest, DiscoverEntityRequest, DiscoverEntityResponse, EntityTimeline, GetChangeRequest, GetEntityTimelineRequest, ListDeletedEntitiesRequest, ListDeletedEntitiesResponse, ListEntityMentionsRequest, ListEntityMentionsResponse, SearchEntitiesRequest, SearchEntitiesResponse, UndeleteEntityRequest } from "./entities_pb";
import { Empty, MethodKind } from "@bufbuild/protobuf";

/**
Expand Down Expand Up @@ -83,14 +83,14 @@ export const Entities = {
kind: MethodKind.Unary,
},
/**
* Try to bring back the deleted entity in next syncync round. It may fail if there is no
* provider for that entity, even though it once was when the entity was created.
* Undo the entity delition by removing the entity from the deleted list. That entity, if available
* will be synced back in the next syncing round (or manually discovered).
*
* @generated from rpc com.mintter.entities.v1alpha.Entities.RestoreEntity
* @generated from rpc com.mintter.entities.v1alpha.Entities.UndeleteEntity
*/
restoreEntity: {
name: "RestoreEntity",
I: RestoreEntityRequest,
undeleteEntity: {
name: "UndeleteEntity",
I: UndeleteEntityRequest,
O: Empty,
kind: MethodKind.Unary,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -780,9 +780,9 @@ export class ListDeletedEntitiesResponse extends Message<ListDeletedEntitiesResp
/**
* Request for restoring an entity.
*
* @generated from message com.mintter.entities.v1alpha.RestoreEntityRequest
* @generated from message com.mintter.entities.v1alpha.UndeleteEntityRequest
*/
export class RestoreEntityRequest extends Message<RestoreEntityRequest> {
export class UndeleteEntityRequest extends Message<UndeleteEntityRequest> {
/**
* Entity ID of the entity to be restored.
* All versions will also be restored.
Expand All @@ -791,31 +791,31 @@ export class RestoreEntityRequest extends Message<RestoreEntityRequest> {
*/
id = "";

constructor(data?: PartialMessage<RestoreEntityRequest>) {
constructor(data?: PartialMessage<UndeleteEntityRequest>) {
super();
proto3.util.initPartial(data, this);
}

static readonly runtime: typeof proto3 = proto3;
static readonly typeName = "com.mintter.entities.v1alpha.RestoreEntityRequest";
static readonly typeName = "com.mintter.entities.v1alpha.UndeleteEntityRequest";
static readonly fields: FieldList = proto3.util.newFieldList(() => [
{ no: 1, name: "id", kind: "scalar", T: 9 /* ScalarType.STRING */ },
]);

static fromBinary(bytes: Uint8Array, options?: Partial<BinaryReadOptions>): RestoreEntityRequest {
return new RestoreEntityRequest().fromBinary(bytes, options);
static fromBinary(bytes: Uint8Array, options?: Partial<BinaryReadOptions>): UndeleteEntityRequest {
return new UndeleteEntityRequest().fromBinary(bytes, options);
}

static fromJson(jsonValue: JsonValue, options?: Partial<JsonReadOptions>): RestoreEntityRequest {
return new RestoreEntityRequest().fromJson(jsonValue, options);
static fromJson(jsonValue: JsonValue, options?: Partial<JsonReadOptions>): UndeleteEntityRequest {
return new UndeleteEntityRequest().fromJson(jsonValue, options);
}

static fromJsonString(jsonString: string, options?: Partial<JsonReadOptions>): RestoreEntityRequest {
return new RestoreEntityRequest().fromJsonString(jsonString, options);
static fromJsonString(jsonString: string, options?: Partial<JsonReadOptions>): UndeleteEntityRequest {
return new UndeleteEntityRequest().fromJsonString(jsonString, options);
}

static equals(a: RestoreEntityRequest | PlainMessage<RestoreEntityRequest> | undefined, b: RestoreEntityRequest | PlainMessage<RestoreEntityRequest> | undefined): boolean {
return proto3.util.equals(RestoreEntityRequest, a, b);
static equals(a: UndeleteEntityRequest | PlainMessage<UndeleteEntityRequest> | undefined, b: UndeleteEntityRequest | PlainMessage<UndeleteEntityRequest> | undefined): boolean {
return proto3.util.equals(UndeleteEntityRequest, a, b);
}
}

Expand Down
8 changes: 4 additions & 4 deletions proto/entities/v1alpha/entities.proto
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ service Entities {
// Lists deleted entities.
rpc ListDeletedEntities(ListDeletedEntitiesRequest) returns (ListDeletedEntitiesResponse);

// Try to bring back the deleted entity in next syncync round. It may fail if there is no
// provider for that entity, even though it once was when the entity was created.
rpc RestoreEntity(RestoreEntityRequest) returns (google.protobuf.Empty);
// Undo the entity delition by removing the entity from the deleted list. That entity, if available
// will be synced back in the next syncing round (or manually discovered).
rpc UndeleteEntity(UndeleteEntityRequest) returns (google.protobuf.Empty);

// List mentions of a given Entity across the locally-available content.
rpc ListEntityMentions(ListEntityMentionsRequest) returns (ListEntityMentionsResponse);
Expand Down Expand Up @@ -205,7 +205,7 @@ message ListDeletedEntitiesResponse {
}

// Request for restoring an entity.
message RestoreEntityRequest {
message UndeleteEntityRequest {
// Entity ID of the entity to be restored.
// All versions will also be restored.
string id = 1;
Expand Down
4 changes: 2 additions & 2 deletions proto/entities/v1alpha/go.gensum
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
srcs: cccf497fe9d8a95807a05f5b1ec8c3c4
outs: 6e3cff7705286d0a9738d1ad8022dc30
srcs: 88d8c11556872d740f7fa0f1906f7dd6
outs: 7c70d380ac797d424f0dcd250d8b2a49
4 changes: 2 additions & 2 deletions proto/entities/v1alpha/js.gensum
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
srcs: cccf497fe9d8a95807a05f5b1ec8c3c4
outs: 6d0832554fc6707c426b9e6129faded5
srcs: 88d8c11556872d740f7fa0f1906f7dd6
outs: 110805268d5e364675d92d111db1ceaf

0 comments on commit bdb48b3

Please sign in to comment.