Files
upstream-zulip/web/tests/lib/example_user.cjs
upstream-mirror 64898b2c79
Some checks failed
Code scanning / CodeQL (push) Failing after 15s
Zulip production suite / Ubuntu 22.04 production build (push) Failing after 26s
Zulip production suite / Debian 12 production install with custom db name and user (push) Has been skipped
Zulip production suite / Ubuntu 22.04 production install and PostgreSQL upgrade with pgroonga (push) Has been skipped
Zulip production suite / Ubuntu 24.04 production install (push) Has been skipped
Zulip production suite / Ubuntu 26.04 production install (push) Has been skipped
Zulip production suite / Debian 13 production install (push) Has been skipped
Zulip production suite / 7.0 Version Upgrade (push) Has been skipped
Zulip production suite / 8.0 Version Upgrade (push) Has been skipped
Zulip production suite / 6.0 Version Upgrade (push) Has been skipped
Zulip production suite / 10.0 Version Upgrade (push) Has been skipped
Zulip production suite / 9.0 Version Upgrade (push) Has been skipped
Zulip production suite / 12.0 Version Upgrade (push) Has been skipped
Zulip production suite / 11.0 Version Upgrade (push) Has been skipped
GitHub Actions Security Analysis with zizmor / zizmor (push) Failing after 3s
Zulip CI / Debian 12 (Python 3.11, backend + documentation) (push) Failing after 26s
Zulip CI / Ubuntu 22.04 (Python 3.10, backend + frontend) (push) Failing after 3s
Zulip CI / Ubuntu 24.04 (Python 3.12, backend) (push) Failing after 25s
Zulip CI / Ubuntu 26.04 (Python 3.14, backend) (push) Failing after 25s
Zulip CI / Debian 13 (Python 3.13, backend) (push) Failing after 28s
Zulip production suite / Required jobs (push) Has been cancelled
Zulip CI / Required jobs (push) Has been cancelled
API Documentation Update Check / check-feature-level-updated (push) Has been cancelled
API Documentation Update Check / notify-if-api-docs-changed (push) Has been cancelled
snapshot of https://github.com/zulip/zulip.git @ 48c69911c7dd4e03b20552eb3bd77ad8151c1357 (2026-09-15)
2026-09-15 15:05:30 +05:00

74 lines
1.9 KiB
JavaScript

"use strict";
let last_issued_user_id = 1000;
const get_user_id = () => {
last_issued_user_id += 1 + Math.floor(Math.random() * 100);
return last_issued_user_id;
};
const Role = Object.freeze({
OWNER: 100,
ADMINISTRATOR: 200,
MODERATOR: 300,
MEMBER: 400,
GUEST: 600,
});
const Bot = Object.freeze({
GENERIC: 1,
INCOMING_WEBHOOK: 2,
OUTGOING_WEBHOOK: 3,
EMBEDDED: 4,
});
const bot_or_user_props = (opts = {}) => {
// Since other fields need `user_id`, we extract it early.
const user_id = opts.user_id ?? get_user_id();
const role = opts.role ?? Role.MEMBER;
const common_props = {
user_id,
delivery_email: opts.delivery_email ?? null,
email: `user-${user_id}@example.org`,
full_name: `user-${user_id}-ex_name`,
date_joined: Date.now(),
// Derived from role, matching people._add_user() production logic.
is_owner: role === Role.OWNER,
is_admin: role === Role.OWNER || role === Role.ADMINISTRATOR,
is_guest: role === Role.GUEST,
is_moderator: role === Role.OWNER || role === Role.ADMINISTRATOR || role === Role.MODERATOR,
timezone: "UTC",
avatar_version: 0,
role,
};
return {...common_props, ...opts};
};
const make_user = (opts = {}) => ({
...bot_or_user_props(opts),
is_bot: opts.is_bot ?? false,
// By default an empty dictionary.
profile_data: opts.profile_data ?? {},
});
const make_bot = (opts = {}) => ({
...bot_or_user_props(opts),
is_bot: true,
// By default a generic bot.
bot_type: opts.bot_type ?? Bot.GENERIC,
bot_owner_id: opts.bot_owner_id ?? null,
});
const make_cross_realm_bot = (opts = {}) => ({
...make_bot(opts),
is_system_bot: true,
});
exports.make_bot = make_bot;
exports.make_user = make_user;
exports.make_cross_realm_bot = make_cross_realm_bot;
exports.Role = Role;
exports.Bot = Bot;