mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-03 21:43:21 +00:00 
			
		
		
		
	When we were preparing the conversion to ES modules in 2019, the primary obstacle was that the Node tests extensively relied on the ability to reach into modules and mutate their CommonJS exports in order to mock things. ES module bindings are not mutable, so in commit173c9cee42we added babel-plugin-rewire-ts as a kludgy transpilation-based workaround for this to unblock the conversion. However, babel-plugin-rewire-ts is slow, buggy, nonstandard, confusing, and unmaintained. It’s incompatible with running our ES modules as native ES modules, and prevents us from taking advantage of modern tools for ES modules. So we want to excise all use of __Rewire__ (and the disallow_rewire, override_rewire helper functions that rely on it) from the tests and remove babel-plugin-rewire-ts. Commits64abdc199eande17ba5260a(#20730) prepared for this by letting us see where __Rewire__ is being used. Now we go through and remove most of the uses that are easy to remove without modifying the production code at all. Signed-off-by: Anders Kaseorg <anders@zulip.com>
		
			
				
	
	
		
			81 lines
		
	
	
		
			2.6 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			81 lines
		
	
	
		
			2.6 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
"use strict";
 | 
						|
 | 
						|
const {strict: assert} = require("assert");
 | 
						|
 | 
						|
const {zrequire} = require("../zjsunit/namespace");
 | 
						|
const {run_test} = require("../zjsunit/test");
 | 
						|
const {page_params} = require("../zjsunit/zpage_params");
 | 
						|
 | 
						|
const people = zrequire("people");
 | 
						|
const stream_create_subscribers_data = zrequire("stream_create_subscribers_data");
 | 
						|
 | 
						|
const me = {
 | 
						|
    email: "me@zulip.com",
 | 
						|
    full_name: "Zed", // Zed will sort to the top by virtue of being the current user.
 | 
						|
    user_id: 400,
 | 
						|
};
 | 
						|
 | 
						|
const test_user101 = {
 | 
						|
    email: "test101@zulip.com",
 | 
						|
    full_name: "Test User 101",
 | 
						|
    user_id: 101,
 | 
						|
};
 | 
						|
 | 
						|
const test_user102 = {
 | 
						|
    email: "test102@zulip.com",
 | 
						|
    full_name: "Test User 102",
 | 
						|
    user_id: 102,
 | 
						|
};
 | 
						|
 | 
						|
const test_user103 = {
 | 
						|
    email: "test102@zulip.com",
 | 
						|
    full_name: "Test User 103",
 | 
						|
    user_id: 103,
 | 
						|
};
 | 
						|
 | 
						|
function test(label, f) {
 | 
						|
    run_test(label, (helpers) => {
 | 
						|
        page_params.is_admin = false;
 | 
						|
        people.init();
 | 
						|
        people.add_active_user(me);
 | 
						|
        people.add_active_user(test_user101);
 | 
						|
        people.add_active_user(test_user102);
 | 
						|
        people.add_active_user(test_user103);
 | 
						|
        page_params.user_id = me.user_id;
 | 
						|
        people.initialize_current_user(me.user_id);
 | 
						|
        f(helpers);
 | 
						|
    });
 | 
						|
}
 | 
						|
 | 
						|
test("basics", () => {
 | 
						|
    stream_create_subscribers_data.initialize_with_current_user();
 | 
						|
 | 
						|
    assert.deepEqual(stream_create_subscribers_data.sorted_user_ids(), [me.user_id]);
 | 
						|
    assert.deepEqual(stream_create_subscribers_data.get_principals(), [me.user_id]);
 | 
						|
 | 
						|
    const all_user_ids = stream_create_subscribers_data.get_all_user_ids();
 | 
						|
    assert.deepEqual(all_user_ids, [101, 102, 103, 400]);
 | 
						|
 | 
						|
    stream_create_subscribers_data.add_user_ids(all_user_ids);
 | 
						|
    assert.deepEqual(stream_create_subscribers_data.sorted_user_ids(), [400, 101, 102, 103]);
 | 
						|
 | 
						|
    stream_create_subscribers_data.remove_user_ids([101, 103]);
 | 
						|
    assert.deepEqual(stream_create_subscribers_data.sorted_user_ids(), [400, 102]);
 | 
						|
    assert.deepEqual(stream_create_subscribers_data.get_potential_subscribers(), [
 | 
						|
        test_user101,
 | 
						|
        test_user103,
 | 
						|
    ]);
 | 
						|
 | 
						|
    assert.ok(stream_create_subscribers_data.must_be_subscribed(me.user_id));
 | 
						|
    assert.ok(!stream_create_subscribers_data.must_be_subscribed(test_user101.user_id));
 | 
						|
});
 | 
						|
 | 
						|
test("must_be_subscribed", () => {
 | 
						|
    page_params.is_admin = false;
 | 
						|
    assert.ok(stream_create_subscribers_data.must_be_subscribed(me.user_id));
 | 
						|
    assert.ok(!stream_create_subscribers_data.must_be_subscribed(test_user101.user_id));
 | 
						|
    page_params.is_admin = true;
 | 
						|
    assert.ok(!stream_create_subscribers_data.must_be_subscribed(me.user_id));
 | 
						|
    assert.ok(!stream_create_subscribers_data.must_be_subscribed(test_user101.user_id));
 | 
						|
});
 |