From 466757c3f10d2a534e90905282a5657122b5c72c Mon Sep 17 00:00:00 2001 From: Steve Howell Date: Wed, 26 Jul 2017 08:18:40 -0400 Subject: [PATCH] node tests: Extract topic_data.js. This mostly moves code, and it also removes some unnecessary coupling to stream_data.js. The topic_data code purely works in the stream_id space, so there's no need to set up actual stream data for it. --- frontend_tests/node_tests/stream_data.js | 65 ------------------------ frontend_tests/node_tests/topic_data.js | 60 ++++++++++++++++++++++ 2 files changed, 60 insertions(+), 65 deletions(-) create mode 100644 frontend_tests/node_tests/topic_data.js diff --git a/frontend_tests/node_tests/stream_data.js b/frontend_tests/node_tests/stream_data.js index 8372ea25bc..b1ba66355b 100644 --- a/frontend_tests/node_tests/stream_data.js +++ b/frontend_tests/node_tests/stream_data.js @@ -242,71 +242,6 @@ var people = global.people; assert(!ok); }()); -(function test_process_message() { - var stream_id = 55; - - var rome = { - name: 'Rome', - stream_id: stream_id, - }; - - stream_data.add_sub('Rome', rome); - - topic_data.add_message({ - stream_id: stream_id, - message_id: 101, - topic_name: 'toPic1', - }); - - var history = topic_data.get_recent_names(rome.stream_id); - assert.deepEqual(history, ['toPic1']); - - topic_data.add_message({ - stream_id: stream_id, - message_id: 102, - topic_name: 'Topic1', - }); - history = topic_data.get_recent_names(rome.stream_id); - assert.deepEqual(history, ['Topic1']); - - topic_data.add_message({ - stream_id: stream_id, - message_id: 103, - topic_name: 'topic2', - }); - history = topic_data.get_recent_names(rome.stream_id); - assert.deepEqual(history, ['topic2', 'Topic1']); - - // Removing first topic1 message has no effect. - topic_data.remove_message({ - stream_id: stream_id, - topic_name: 'toPic1', - }); - history = topic_data.get_recent_names(rome.stream_id); - assert.deepEqual(history, ['topic2', 'Topic1']); - - // Removing second topic1 message removes the topic. - topic_data.remove_message({ - stream_id: stream_id, - topic_name: 'Topic1', - }); - history = topic_data.get_recent_names(rome.stream_id); - assert.deepEqual(history, ['topic2']); - - // Test that duplicate remove does not crash us. - topic_data.remove_message({ - stream_id: stream_id, - topic_name: 'Topic1', - }); - history = topic_data.get_recent_names(rome.stream_id); - assert.deepEqual(history, ['topic2']); - - // get to 100% coverage for defensive code - topic_data.remove_message({ - stream_id: 9999999, - }); -}()); - (function test_is_active() { stream_data.clear_subscriptions(); diff --git a/frontend_tests/node_tests/topic_data.js b/frontend_tests/node_tests/topic_data.js new file mode 100644 index 0000000000..8b3bb4eb61 --- /dev/null +++ b/frontend_tests/node_tests/topic_data.js @@ -0,0 +1,60 @@ +var topic_data = require('js/topic_data.js'); + +(function test_basics() { + var stream_id = 55; + + topic_data.add_message({ + stream_id: stream_id, + message_id: 101, + topic_name: 'toPic1', + }); + + var history = topic_data.get_recent_names(stream_id); + assert.deepEqual(history, ['toPic1']); + + topic_data.add_message({ + stream_id: stream_id, + message_id: 102, + topic_name: 'Topic1', + }); + history = topic_data.get_recent_names(stream_id); + assert.deepEqual(history, ['Topic1']); + + topic_data.add_message({ + stream_id: stream_id, + message_id: 103, + topic_name: 'topic2', + }); + history = topic_data.get_recent_names(stream_id); + assert.deepEqual(history, ['topic2', 'Topic1']); + + // Removing first topic1 message has no effect. + topic_data.remove_message({ + stream_id: stream_id, + topic_name: 'toPic1', + }); + history = topic_data.get_recent_names(stream_id); + assert.deepEqual(history, ['topic2', 'Topic1']); + + // Removing second topic1 message removes the topic. + topic_data.remove_message({ + stream_id: stream_id, + topic_name: 'Topic1', + }); + history = topic_data.get_recent_names(stream_id); + assert.deepEqual(history, ['topic2']); + + // Test that duplicate remove does not crash us. + topic_data.remove_message({ + stream_id: stream_id, + topic_name: 'Topic1', + }); + history = topic_data.get_recent_names(stream_id); + assert.deepEqual(history, ['topic2']); + + // get to 100% coverage for defensive code + topic_data.remove_message({ + stream_id: 9999999, + }); +}()); +