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 2s
55 lines
2.4 KiB
TypeScript
55 lines
2.4 KiB
TypeScript
import { LocalAttributeStore } from './LocalAttributeStore';
|
|
|
|
const ensureMock = jest.fn();
|
|
jest.mock('../helper', () => ({ ensureAttributeDefinitionsExist: (...a: unknown[]) => ensureMock(...a) }));
|
|
const findPaginated = jest.fn();
|
|
jest.mock('@rocket.chat/models', () => ({ AbacAttributes: { findPaginated: (...a: unknown[]) => findPaginated(...a) } }));
|
|
|
|
const actor = { _id: 'u', username: 'bob', name: 'Bob' };
|
|
|
|
beforeEach(() => {
|
|
ensureMock.mockReset();
|
|
findPaginated.mockReset();
|
|
});
|
|
|
|
describe('LocalAttributeStore', () => {
|
|
it('validateAssignable delegates to ensureAttributeDefinitionsExist', async () => {
|
|
const attrs = [{ key: 'k', values: ['v'] }];
|
|
await new LocalAttributeStore().validateAssignable(attrs, actor);
|
|
expect(ensureMock).toHaveBeenCalledWith(attrs);
|
|
});
|
|
|
|
it('scopeRoomsPage is identity pass-through (no flag)', async () => {
|
|
const rooms = [{ _id: 'r1', abacAttributes: [{ key: 'k', values: ['v'] }] }];
|
|
const out = await new LocalAttributeStore().scopeRoomsPage(rooms, actor);
|
|
expect(out).toEqual(rooms);
|
|
expect(out[0]).not.toHaveProperty('abacAttributesRedacted');
|
|
});
|
|
|
|
it('assertCanModifyRoom is a no-op', async () => {
|
|
await expect(new LocalAttributeStore().assertCanModifyRoom({ _id: 'r', abacAttributes: [] }, actor)).resolves.toBeUndefined();
|
|
});
|
|
|
|
it('entitlementsOf returns the everything sentinel (empty map)', async () => {
|
|
const e = await new LocalAttributeStore().entitlementsOf(actor);
|
|
expect(e.size).toBe(0);
|
|
});
|
|
|
|
it('list queries AbacAttributes paginated (no filters)', async () => {
|
|
const docs = [{ _id: 'id1', key: 'k', values: ['v'] }];
|
|
findPaginated.mockReturnValue({ cursor: { toArray: async () => docs }, totalCount: Promise.resolve(1) });
|
|
const r = await new LocalAttributeStore().list(actor, { offset: 0, count: 25 });
|
|
expect(findPaginated).toHaveBeenCalledWith({}, { projection: { key: 1, values: 1 }, skip: 0, limit: 25 });
|
|
expect(r).toEqual({ attributes: docs, offset: 0, count: 1, total: 1 });
|
|
});
|
|
|
|
it('list builds $or query when key and values filters provided', async () => {
|
|
findPaginated.mockReturnValue({ cursor: { toArray: async () => [] }, totalCount: Promise.resolve(0) });
|
|
await new LocalAttributeStore().list(actor, { key: 'foo', values: 'bar', offset: 5, count: 10 });
|
|
expect(findPaginated).toHaveBeenCalledWith(
|
|
{ $or: [{ key: /foo/i }, { values: /bar/i }] },
|
|
{ projection: { key: 1, values: 1 }, skip: 5, limit: 10 },
|
|
);
|
|
});
|
|
});
|