mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-10-18 21:16:47 +00:00
feat(plugins): add quota-limited session storage API
This commit is contained in:
@@ -131,6 +131,30 @@ describe('validateManifest', () => {
|
||||
});
|
||||
|
||||
describe('createMockHost', () => {
|
||||
it('mocks plugin UI session storage with scope isolation and production limits', async () => {
|
||||
const host = createMockHost({ sessionTripId: 42 });
|
||||
await host.session.set('filters', ['hotel']);
|
||||
await host.session.set('filters', ['flight'], { scope: 'trip' });
|
||||
await expect(host.session.get('filters')).resolves.toEqual(['hotel']);
|
||||
await expect(host.session.get('filters', { scope: 'trip' })).resolves.toEqual(['flight']);
|
||||
|
||||
await expect(host.session.set('x'.repeat(65), true)).rejects.toThrow(/SESSION_INVALID_KEY/);
|
||||
await expect(host.session.set('large', 'x'.repeat(1024))).rejects.toThrow(/SESSION_VALUE_TOO_LARGE/);
|
||||
await expect(host.session.set('x'.repeat(64), 'x'.repeat(1022))).resolves.toBeUndefined();
|
||||
|
||||
await host.session.clear();
|
||||
await host.session.clear({ scope: 'trip' });
|
||||
for (let index = 0; index < 32; index += 1) await host.session.set(`key-${index}`, index);
|
||||
await expect(host.session.set('key-32', 32)).rejects.toThrow(/SESSION_KEY_LIMIT/);
|
||||
await expect(host.session.set('trip-key', true, { scope: 'trip' })).resolves.toBeUndefined();
|
||||
|
||||
});
|
||||
|
||||
it('requires a trip context for trip-scoped mock session storage', async () => {
|
||||
const { session } = createMockHost();
|
||||
await expect(session.get('filters', { scope: 'trip' })).rejects.toThrow(/NO_TRIP_CONTEXT/);
|
||||
});
|
||||
|
||||
it('enforces the granted permission set', async () => {
|
||||
const { ctx } = createMockHost({ grants: ['db:own'] });
|
||||
await expect(ctx.db.migrate('1', 'CREATE TABLE t (x)')).resolves.toEqual({ applied: true });
|
||||
|
||||
Reference in New Issue
Block a user