src/modular/bin/sessionmgr/storage/session_storage_unittest.cc
// Verifies that an on_annotations_updated callback for a story that does not yet exist is
// only called when the annotations are updated.
Verifies that an on_annotations_updated callback for a story that does not yet exist is
only called when the annotations are updated.
Verifies that an on_annotations_updated callback for a story that does not yet exist is only called when the annotations are updated .
TEST_F(SessionStorageTest, OnAnnotationsUpdatedCallbackBeforeCreate) {
  static constexpr auto story_name = "story";
  auto storage = CreateStorage();
  bool updated{};
  int annotations_count = 0;
  storage->add_on_annotations_updated_once(
      story_name, [&](std::string story_id, std::vector<fuchsia::modular::Annotation> annotations) {
        updated = true;
        annotations_count = annotations.size();
      });
  std::vector<fuchsia::modular::Annotation> first_annotations{};
  fuchsia::modular::AnnotationValue first_annotation_value;
  first_annotation_value.set_text("first_test_annotation_value");
  auto first_annotation =
      fuchsia::modular::Annotation{.key = "first_test_annotation_key",
                                   .value = fidl::MakeOptional(std::move(first_annotation_value))};
  first_annotations.push_back(fidl::Clone(first_annotation));
  storage->CreateStory(story_name, std::move(first_annotations));
  EXPECT_FALSE(updated);
  EXPECT_EQ(0, annotations_count);
  std::vector<fuchsia::modular::Annotation> second_annotations{};
  fuchsia::modular::AnnotationValue second_annotation_value;
  second_annotation_value.set_text("second_test_annotation_value");
  auto second_annotation =
      fuchsia::modular::Annotation{.key = "second_test_annotation_key",
                                   .value = fidl::MakeOptional(std::move(second_annotation_value))};
  second_annotations.push_back(fidl::Clone(second_annotation));
  storage->MergeStoryAnnotations(story_name, std::move(second_annotations));
  EXPECT_TRUE(updated);
  EXPECT_EQ(2, annotations_count);
}
TEST_F ( SessionStorageTest , OnAnnotationsUpdatedCallbackBeforeCreate ) { static constexpr auto story_name = " " ; auto storage = CreateStorage ( ) ; bool updated { } ; int annotations_count = 0 ; storage -> add_on_annotations_updated_once ( story_name , [ & ] ( std :: string story_id , std :: vector < fuchsia :: modular :: Annotation > annotations ) { updated = true ; annotations_count = annotations . size ( ) ; } ) ; std :: vector < fuchsia :: modular :: Annotation > first_annotations { } ; fuchsia :: modular :: AnnotationValue first_annotation_value ; first_annotation_value . set_text ( " " ) ; auto first_annotation = fuchsia :: modular :: Annotation { . key = " " , . value = fidl :: MakeOptional ( std :: move ( first_annotation_value ) ) } ; first_annotations . push_back ( fidl :: Clone ( first_annotation ) ) ; storage -> CreateStory ( story_name , std :: move ( first_annotations ) ) ; EXPECT_FALSE ( updated ) ; EXPECT_EQ ( 0 , annotations_count ) ; std :: vector < fuchsia :: modular :: Annotation > second_annotations { } ; fuchsia :: modular :: AnnotationValue second_annotation_value ; second_annotation_value . set_text ( " " ) ; auto second_annotation = fuchsia :: modular :: Annotation { . key = " " , . value = fidl :: MakeOptional ( std :: move ( second_annotation_value ) ) } ; second_annotations . push_back ( fidl :: Clone ( second_annotation ) ) ; storage -> MergeStoryAnnotations ( story_name , std :: move ( second_annotations ) ) ; EXPECT_TRUE ( updated ) ; EXPECT_EQ ( 2 , annotations_count ) ; }
Verifies that an on_annotations_updated callback for a story that does not yet exist is
only called when the annotations are updated.
Verifies that an on_annotations_updated callback for a story that does not yet exist is only called when the annotations are updated .
// Add a callback. // Create a story with some annotations. // The callback should not have been invoked. // Annotate the story. // The callback should have been invoked.