snapshot of https://github.com/RocketChat/Rocket.Chat.git (develop, 2026-09-16; blobs > 131072B omitted)
Some checks failed
Create issues from TODOs / todos (push) Failing after 3s
Close inactive issues / close-issues (push) Has been cancelled
Deploy GitHub Pages / deploy-preview (push) Has been cancelled
CI / ⚙️ Variables Setup (push) Has been cancelled
CI / ⚙️ Test Guard (push) Has been cancelled
CI / 🚀 Notify external services - draft (push) Has been cancelled
CI / 📦 Build Packages (push) Has been cancelled
CI / 📦 Meteor Build (coverage) (push) Has been cancelled
CI / 📦 Meteor Build (production) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [account-service presence-service omnichannel-transcript-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [account-service presence-service omnichannel-transcript-service], fips) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [authorization-service queue-worker-service ddp-streamer-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [authorization-service queue-worker-service ddp-streamer-service], fips) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], coverage) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], fips) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [account-service presence-service omnichannel-transcript-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [authorization-service queue-worker-service ddp-streamer-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [rocketchat], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [rocketchat], coverage) (push) Has been cancelled
CI / 🚢 Publish Docker Images (ghcr.io) (push) Has been cancelled
CI / 📦 Track Image Sizes (push) Has been cancelled
CI / 🔎 Code Check - Action Lint (push) Has been cancelled
CI / 🔎 Code Check (push) Has been cancelled
CI / 🔨 Test Storybook (push) Has been cancelled
CI / 🔨 Test Unit (push) Has been cancelled
CI / 🔨 Test API (CE) (push) Has been cancelled
CI / 🔨 Test API Livechat (CE) (push) Has been cancelled
CI / 🔨 Test UI (CE) (push) Has been cancelled
CI / 🔨 Test API (EE) (push) Has been cancelled
CI / 🔨 Test API Livechat (EE) (push) Has been cancelled
CI / 🔨 Test API Apps (deno-runtime - EE) (push) Has been cancelled
CI / 🔨 Test UI (EE) (push) Has been cancelled
CI / 🔨 Test API (FIPS) (push) Has been cancelled
CI / 🔨 Test API Livechat (FIPS) (push) Has been cancelled
CI / 🔨 Test UI (FIPS) (push) Has been cancelled
CI / 🔨 Test Federation Matrix (push) Has been cancelled
CI / 📊 Report Coverage (push) Has been cancelled
CI / ✅ Tests Done (push) Has been cancelled
CI / 🚀 Publish build assets (push) Has been cancelled
CI / 🚀 Publish Docker Images (DockerHub) (push) Has been cancelled
CI / 🚀 Notify external services (push) Has been cancelled
CI / Update Version Durability (push) Has been cancelled
Release / Release (push) Has been cancelled
Auto-close duplicate issues / auto-close-duplicates (push) Failing after 1s
Code scanning - action / CodeQL-Build (push) Failing after 1s
Some checks failed
Create issues from TODOs / todos (push) Failing after 3s
Close inactive issues / close-issues (push) Has been cancelled
Deploy GitHub Pages / deploy-preview (push) Has been cancelled
CI / ⚙️ Variables Setup (push) Has been cancelled
CI / ⚙️ Test Guard (push) Has been cancelled
CI / 🚀 Notify external services - draft (push) Has been cancelled
CI / 📦 Build Packages (push) Has been cancelled
CI / 📦 Meteor Build (coverage) (push) Has been cancelled
CI / 📦 Meteor Build (production) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [account-service presence-service omnichannel-transcript-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [account-service presence-service omnichannel-transcript-service], fips) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [authorization-service queue-worker-service ddp-streamer-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [authorization-service queue-worker-service ddp-streamer-service], fips) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], coverage) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], fips) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [account-service presence-service omnichannel-transcript-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [authorization-service queue-worker-service ddp-streamer-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [rocketchat], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [rocketchat], coverage) (push) Has been cancelled
CI / 🚢 Publish Docker Images (ghcr.io) (push) Has been cancelled
CI / 📦 Track Image Sizes (push) Has been cancelled
CI / 🔎 Code Check - Action Lint (push) Has been cancelled
CI / 🔎 Code Check (push) Has been cancelled
CI / 🔨 Test Storybook (push) Has been cancelled
CI / 🔨 Test Unit (push) Has been cancelled
CI / 🔨 Test API (CE) (push) Has been cancelled
CI / 🔨 Test API Livechat (CE) (push) Has been cancelled
CI / 🔨 Test UI (CE) (push) Has been cancelled
CI / 🔨 Test API (EE) (push) Has been cancelled
CI / 🔨 Test API Livechat (EE) (push) Has been cancelled
CI / 🔨 Test API Apps (deno-runtime - EE) (push) Has been cancelled
CI / 🔨 Test UI (EE) (push) Has been cancelled
CI / 🔨 Test API (FIPS) (push) Has been cancelled
CI / 🔨 Test API Livechat (FIPS) (push) Has been cancelled
CI / 🔨 Test UI (FIPS) (push) Has been cancelled
CI / 🔨 Test Federation Matrix (push) Has been cancelled
CI / 📊 Report Coverage (push) Has been cancelled
CI / ✅ Tests Done (push) Has been cancelled
CI / 🚀 Publish build assets (push) Has been cancelled
CI / 🚀 Publish Docker Images (DockerHub) (push) Has been cancelled
CI / 🚀 Notify external services (push) Has been cancelled
CI / Update Version Durability (push) Has been cancelled
Release / Release (push) Has been cancelled
Auto-close duplicate issues / auto-close-duplicates (push) Failing after 1s
Code scanning - action / CodeQL-Build (push) Failing after 1s
This commit is contained in:
150
apps/meteor/tests/unit/server/services/team/service.tests.ts
Normal file
150
apps/meteor/tests/unit/server/services/team/service.tests.ts
Normal file
@@ -0,0 +1,150 @@
|
||||
import { expect } from 'chai';
|
||||
import { beforeEach, describe, it } from 'mocha';
|
||||
import proxyquire from 'proxyquire';
|
||||
import sinon from 'sinon';
|
||||
|
||||
const Rooms = {
|
||||
findDefaultRoomsForTeam: sinon.stub(),
|
||||
findOneById: sinon.stub(),
|
||||
unsetTeamId: sinon.stub(),
|
||||
};
|
||||
|
||||
const Users = {
|
||||
findActiveByIds: sinon.stub(),
|
||||
};
|
||||
|
||||
const Message = {
|
||||
saveSystemMessage: sinon.stub(),
|
||||
};
|
||||
|
||||
const addUserToRoom = sinon.stub();
|
||||
|
||||
const { TeamService } = proxyquire.noCallThru().load('../../../../../server/services/team/service', {
|
||||
'@rocket.chat/core-services': {
|
||||
Room: {},
|
||||
Authorization: {},
|
||||
Message,
|
||||
ServiceClassInternal: class {},
|
||||
api: {},
|
||||
},
|
||||
'@rocket.chat/models': {
|
||||
Team: {},
|
||||
Rooms,
|
||||
Subscriptions: {},
|
||||
Users,
|
||||
TeamMember: {},
|
||||
},
|
||||
'@rocket.chat/tools': {
|
||||
escapeRegExp: (value: string) => value,
|
||||
},
|
||||
'../../lib/rooms/settings': {
|
||||
saveRoomName: sinon.stub(),
|
||||
},
|
||||
'../../lib/rooms/settings/saveRoomType': {
|
||||
saveRoomType: sinon.stub(),
|
||||
},
|
||||
'../../lib/rooms/addUserToRoom': {
|
||||
addUserToRoom,
|
||||
},
|
||||
'../../lib/users/checkUsernameAvailability': {
|
||||
checkUsernameAvailability: sinon.stub(),
|
||||
},
|
||||
'../../lib/rooms/getRoomsWithSingleOwner': {
|
||||
getSubscribedRoomsForUserWithDetails: sinon.stub(),
|
||||
},
|
||||
'../../lib/rooms/removeUserFromRoom': {
|
||||
removeUserFromRoom: sinon.stub(),
|
||||
},
|
||||
'../../lib/notifyListener': {
|
||||
notifyOnSubscriptionChangedByRoomIdAndUserId: sinon.stub(),
|
||||
notifyOnRoomChangedById: sinon.stub(),
|
||||
},
|
||||
'../../settings': {
|
||||
settings: { get: sinon.stub() },
|
||||
},
|
||||
});
|
||||
|
||||
const service = new TeamService();
|
||||
|
||||
describe('Team service', () => {
|
||||
beforeEach(() => {
|
||||
addUserToRoom.reset();
|
||||
Rooms.findDefaultRoomsForTeam.reset();
|
||||
Rooms.findOneById.reset();
|
||||
Rooms.unsetTeamId.reset();
|
||||
Users.findActiveByIds.reset();
|
||||
Message.saveSystemMessage.reset();
|
||||
});
|
||||
|
||||
it('should wait for default room membership operations to finish', async function () {
|
||||
this.timeout(15000);
|
||||
|
||||
addUserToRoom.onFirstCall().resolves(true);
|
||||
addUserToRoom.onSecondCall().returns(
|
||||
new Promise<void>((resolve) => {
|
||||
setTimeout(() => {
|
||||
resolve();
|
||||
}, 20);
|
||||
}),
|
||||
);
|
||||
|
||||
Rooms.findDefaultRoomsForTeam.returns({
|
||||
toArray: () => Promise.resolve([{ _id: 'default-room' }]),
|
||||
});
|
||||
Users.findActiveByIds.returns({
|
||||
toArray: () =>
|
||||
Promise.resolve([
|
||||
{ _id: 'user-1', username: 'user-1' },
|
||||
{ _id: 'user-2', username: 'user-2' },
|
||||
]),
|
||||
});
|
||||
|
||||
await service.addMembersToDefaultRooms({ _id: 'inviter', username: 'inviter' }, 'team-id', [
|
||||
{ userId: 'user-1' },
|
||||
{ userId: 'user-2' },
|
||||
]);
|
||||
|
||||
expect(addUserToRoom.callCount).to.equal(2);
|
||||
});
|
||||
|
||||
it('should propagate errors from default room membership operations', async function () {
|
||||
this.timeout(15000);
|
||||
|
||||
addUserToRoom.rejects(new Error('room-add-failed'));
|
||||
Rooms.findDefaultRoomsForTeam.returns({
|
||||
toArray: () => Promise.resolve([{ _id: 'default-room' }]),
|
||||
});
|
||||
Users.findActiveByIds.returns({
|
||||
toArray: () => Promise.resolve([{ _id: 'user-1', username: 'user-1' }]),
|
||||
});
|
||||
|
||||
await expect(
|
||||
service.addMembersToDefaultRooms({ _id: 'inviter', username: 'inviter' }, 'team-id', [{ userId: 'user-1' }]),
|
||||
).to.be.rejectedWith('room-add-failed');
|
||||
|
||||
expect(addUserToRoom.callCount).to.equal(1);
|
||||
});
|
||||
|
||||
describe('unsetTeamIdOfRooms', () => {
|
||||
const user = { _id: 'user-1', username: 'user-1', name: 'User One' };
|
||||
const team = { _id: 'team-id', roomId: 'team-room' };
|
||||
|
||||
it('should announce the conversion on the main room and move the remaining rooms back to the workspace', async () => {
|
||||
Rooms.findOneById.resolves({ _id: 'team-room', name: 'team-room-name' });
|
||||
|
||||
await service.unsetTeamIdOfRooms(user, team);
|
||||
|
||||
expect(Message.saveSystemMessage.calledOnceWith('user-converted-to-channel', 'team-room', 'team-room-name', user)).to.be.true;
|
||||
expect(Rooms.unsetTeamId.calledOnceWith('team-id')).to.be.true;
|
||||
});
|
||||
|
||||
it('should move the remaining rooms back to the workspace when the main room no longer exists', async () => {
|
||||
Rooms.findOneById.resolves(null);
|
||||
|
||||
await service.unsetTeamIdOfRooms(user, team);
|
||||
|
||||
expect(Message.saveSystemMessage.called).to.be.false;
|
||||
expect(Rooms.unsetTeamId.calledOnceWith('team-id')).to.be.true;
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user