mirror of
https://github.com/zulip/zulip.git
synced 2025-11-03 13:33:24 +00:00
node tests: Introduce message_store.create_mock_message() helper.
Previously, it was tedious to create actual message objects in message_store for use in node tests. This was mainly because, `add_message_metadata` in message_store has many dependencies and validation checks. Since it was difficult to create actual message objects, many tests just mocked the `message_store.get()` method to return the desired message. This commit adds a new helper method (`create_mock_message`) to message_store, for use in node tests. This just stores the object passed to it in the `stores_messages` map, without any validation. We do not add any default fields to the message object before saving it from this helper, because doing so would decrease the utility of this helper, and, if a test depends on some field having a particular value, then it would be better to just pass the field: value pair from the test itself, for readability, rather than relying on the helper to add the field for us. This helper allows us to write deeper tests. This commit also replaces some instances of mocking `message_store.get()` to use this new helper method.
This commit is contained in:
committed by
Tim Abbott
parent
aa0e5dd35b
commit
206fe1ef3b
@@ -33,6 +33,12 @@ export function user_ids() {
|
||||
return Array.from(message_user_ids);
|
||||
}
|
||||
|
||||
export function create_mock_message(message) {
|
||||
// For use in tests only. `id` is a required field,
|
||||
// everything else is optional, as required in the test.
|
||||
stored_messages.set(message.id, message);
|
||||
}
|
||||
|
||||
export function get(message_id) {
|
||||
if (message_id === undefined || message_id === null) {
|
||||
blueslip.error("message_store.get got bad value: " + message_id);
|
||||
|
||||
Reference in New Issue
Block a user