www

Overview

This file contains a module write_new_messages_tests which defines a suite of unit tests for the functionality related to writing or processing new messages in a message database context. The tests are conditionally compiled only when the test configuration and the feature flag "messages_db" are enabled. The primary focus is testing the behavior of the write_new_messages function, which is expected to handle messages grouped by accounts and determine which messages are new compared to those already saved.

The tests cover scenarios including:

This file is tightly coupled with types and functions such as WrappedMessage, MessageIdentifier, AccountAddress, and the account_inbox::range::MessagesRange structure, which are assumed to be defined elsewhere in the application. It also relies on synchronization primitives like Mutex and collections like BTreeMap and HashMap.

Module: write_new_messages_tests

Purpose

This module defines unit tests verifying the correctness of the write_new_messages function, specifically its ability to filter and return the new messages for accounts based on a tracking map of last saved messages.

Helper Functions

dummy_message

fn dummy_message(id: u64) -> Arc<WrappedMessage>

make_range

fn make_range(
    items: Vec<(MessageIdentifier, Arc<WrappedMessage>)>
) -> account_inbox::range::MessagesRange<MessageIdentifier, Arc<WrappedMessage>>

Test Cases

Each test case uses the helpers above to simulate message data and verifies the behavior of write_new_messages.

test_write_new_messages_empty

test_write_new_messages_no_last_saved

test_write_new_messages_with_last_saved

test_write_new_messages_all_saved

test_write_new_messages_multiple_accounts

Important Implementation Details

Interaction with Other Components

Diagram: Structure of write_new_messages_tests Module

classDiagram
class write_new_messages_tests {
-dummy_message()
-make_range()
+test_write_new_messages_empty()
+test_write_new_messages_no_last_saved()
+test_write_new_messages_with_last_saved()
+test_write_new_messages_all_saved()
+test_write_new_messages_multiple_accounts()
}

This class diagram represents the test module as a container of helper functions and test functions verifying the behavior of the message writing logic. The private helper functions (dummy_message and make_range) facilitate test setup, while the public test functions execute specific test scenarios.