import { describe, it } from 'bun:test'; import { expect } from 'chai'; import { AttributeScope, Context } from './context'; describe('web Context attributes', () => { const inRequest = (fn: () => void) => Context.run(() => { Context.setCurrent(new Context({} as any, {} as any)); fn(); }); it('without a session, the session scope is empty instead of throwing', () => inRequest(() => { expect(Context.getAttr('missing')).to.equal(undefined); expect(Context.getAttr('missing', AttributeScope.Session)).to.equal(undefined); })); it('falsy request values count as set; the session comes before the app', () => inRequest(() => { Context.setAttr('count', 0); expect(Context.getAttr('count')).to.equal(0); Context.setSession({ 'ctx-spec-user': 'alice' } as any); Context.setAttr('ctx-spec-user', 'app', AttributeScope.App); expect(Context.getAttr('ctx-spec-user')).to.equal('alice'); Context.setAttr('flag', false, AttributeScope.Session); expect(Context.getAttr('flag')).to.equal(false); })); });