Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions datastore/sync_entity_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1104,6 +1104,53 @@ func (suite *SyncEntityTestSuite) TestClearServerDataLegacyMissingMtime() {
suite.Empty(remaining, "row should be deleted even without Mtime")
}

// TestBraveNewsCommitAndGetUpdates exercises the real datastore paths for the
// new BRAVE_NEWS data type (oneof field 10000000): CreateDBSyncEntity (which
// extracts the data type via reflection on the protobuf tag), InsertSyncEntity,
// and GetUpdatesForType, then confirms the specifics blob round-trips.
func (suite *SyncEntityTestSuite) TestBraveNewsCommitAndGetUpdates() {
braveNews := &sync_pb.BraveNewsSpecifics{
Name: aws.String("brave.today.sources"),
Value: &sync_pb.BraveNewsSpecifics_DictValue{DictValue: `{"pub1":true}`},
}
specifics := &sync_pb.EntitySpecifics{
SpecificsVariant: &sync_pb.EntitySpecifics_BraveNews{BraveNews: braveNews},
}
pbEntity := sync_pb.SyncEntity{
IdString: aws.String("brave_news_item_id"),
Version: aws.Int64(0),
Name: aws.String("brave.today.sources"),
NonUniqueName: aws.String("brave.today.sources"),
ClientTagHash: aws.String("brave.today.sources"),
Deleted: aws.Bool(false),
Folder: aws.Bool(false),
Specifics: specifics,
}

// The data type must be extracted as 10000000 from the protobuf tag.
dbEntity, err := datastore.CreateDBSyncEntity(
&pbEntity, aws.String("guid"), "bn_client")
suite.Require().NoError(err, "CreateDBSyncEntity should succeed")
suite.Require().NotNil(dbEntity.DataType)
suite.Equal(10000000, *dbEntity.DataType, "BRAVE_NEWS data type ID")

_, err = suite.dynamo.InsertSyncEntity(context.Background(), dbEntity)
suite.Require().NoError(err, "InsertSyncEntity should succeed")

hasChangesRemaining, syncItems, err := suite.dynamo.GetUpdatesForType(
context.Background(), 10000000, 0, true, "bn_client", 100)
suite.Require().NoError(err, "GetUpdatesForType should succeed")
suite.False(hasChangesRemaining)
suite.Require().Len(syncItems, 1, "should return the one BRAVE_NEWS entity")

// The stored specifics blob must round-trip back to the original values.
var gotSpecifics sync_pb.EntitySpecifics
err = proto.Unmarshal(syncItems[0].Specifics, &gotSpecifics)
suite.Require().NoError(err, "Unmarshal specifics should succeed")
suite.Equal("brave.today.sources", gotSpecifics.GetBraveNews().GetName())
suite.Equal(`{"pub1":true}`, gotSpecifics.GetBraveNews().GetDictValue())
}

func TestSyncEntityTestSuite(t *testing.T) {
suite.Run(t, new(SyncEntityTestSuite))
}
206 changes: 206 additions & 0 deletions schema/protobuf/sync_pb/brave_news_specifics.pb.go

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

28 changes: 28 additions & 0 deletions schema/protobuf/sync_pb/brave_news_specifics.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright (c) 2026 The Brave Authors. All rights reserved.
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this file,
// You can obtain one at http://mozilla.org/MPL/2.0/.

syntax = "proto2";

option go_package = "./sync_pb";

option java_multiple_files = true;
option java_package = "org.chromium.components.sync.protocol";

option optimize_for = LITE_RUNTIME;

package sync_pb;

// One entity per synced Brave News preference. Mirrors the client definition in
// brave-core (brave/components/sync/protocol/brave_news_specifics.proto). The
// server stores the specifics opaquely; this definition only needs to exist so
// the brave_news oneof field (10000000) is recognized and the data type can be
// extracted.
message BraveNewsSpecifics {
optional string name = 1;
oneof value {
bool bool_value = 2;
string dict_value = 3;
}
}
Loading
Loading