import { StreamAuthenticationModel } from './stream-authentication.model'; import { StreamConfigurationModel, StreamConfigurationSchema } from './stream-configuration.model'; import { StreamInteractionLibraryModel } from './stream-interaction-library.model'; import { StreamLimitsModel } from './stream-limits.model'; import { StreamOptionsModel } from './stream-options.model'; describe('StreamConfigurationModel', () => { describe('constructor', () => { it('should create and initialize empty model', () => { const model = new StreamConfigurationModel(); expect(model.streamId).toBe(0); expect(model.streamSecret).toBe('secret'); expect(model.streamSlug).toBe(null); expect(model.authentication).toBeInstanceOf(StreamAuthenticationModel); expect(model.limits).toBeInstanceOf(StreamLimitsModel); expect(model.interactions).toStrictEqual([]); }); it('should intialize model from schema', () => { const schema: StreamConfigurationSchema = { authentication: { stream_password: 'test-pass', }, description: 'test-description', interaction_library: [ { group_id: 'test-group-id', group_name: 'test-group-name', // TODO: Eventually need better typing/tests around // this metadata field metadata: [], }, ], limits: { maximum_attendees: 27, maximum_streams_per_day: 23, maximum_time_per_stream: 88, }, options: { attendee: { enable_2fa: false, enable_camera: false, enable_chat: false, enable_microphone: false, enable_multiple_hosts: false, enable_password: false, enable_private_messages: false, }, host: { enable_camera: true, enable_microphone: true, }, }, stream_id: 1234, stream_secret: 'test-key', stream_slug: 'test-slug', title: 'test-title', }; const model = new StreamConfigurationModel(schema); expect(model.streamId).toBe(schema.stream_id); expect(model.streamSecret).toBe(schema.stream_secret); expect(model.streamSlug).toBe(schema.stream_slug); const { authentication, interactions, limits, options } = model; expect(authentication).toStrictEqual(new StreamAuthenticationModel(schema.authentication)); expect(limits).toStrictEqual(new StreamLimitsModel(schema.limits)); expect(options).toStrictEqual(new StreamOptionsModel(schema.options)); expect(interactions.length).toBe(1); expect(interactions[0]).toStrictEqual( new StreamInteractionLibraryModel(schema.interaction_library[0]), ); }); }); describe('#fromSchema', () => { it('should initialize from a schema input', () => { const model = new StreamConfigurationModel(); expect(model.streamId).toBe(0); expect(model.streamSecret).toBe('secret'); expect(model.streamSlug).toBe(null); expect(model.authentication).toBeInstanceOf(StreamAuthenticationModel); expect(model.limits).toBeInstanceOf(StreamLimitsModel); expect(model.interactions).toStrictEqual([]); const schema: StreamConfigurationSchema = { authentication: { stream_password: 'test-pass', }, description: 'test-descr', interaction_library: [ { group_id: 'test-group-id', group_name: 'test-group-name', // TODO: Eventually need better typing/tests around // this metadata field metadata: [], }, ], limits: { maximum_attendees: 27, maximum_streams_per_day: 23, maximum_time_per_stream: 88, }, options: { attendee: { enable_2fa: false, enable_camera: false, enable_chat: false, enable_microphone: false, enable_multiple_hosts: false, enable_password: false, enable_private_messages: false, }, host: { enable_camera: true, enable_microphone: true, }, }, stream_id: 1234, stream_secret: 'test-key', stream_slug: 'test-slug', title: 'test-title', }; model.fromSchema(schema); expect(model.streamId).toBe(schema.stream_id); expect(model.streamSecret).toBe(schema.stream_secret); expect(model.streamSlug).toBe(schema.stream_slug); const { authentication, interactions, limits, options } = model; expect(authentication).toStrictEqual(new StreamAuthenticationModel(schema.authentication)); expect(limits).toStrictEqual(new StreamLimitsModel(schema.limits)); expect(options).toStrictEqual(new StreamOptionsModel(schema.options)); expect(interactions.length).toBe(1); expect(interactions[0]).toStrictEqual( new StreamInteractionLibraryModel(schema.interaction_library[0]), ); }); }); describe('#toSchema', () => { it('should build a schema object from the model', () => { const schema: StreamConfigurationSchema = { authentication: { stream_password: 'test-pass', }, description: 'test-description', interaction_library: [ { group_id: 'test-group-id', group_name: 'test-group-name', // TODO: Eventually need better typing/tests around // this metadata field metadata: [], }, ], limits: { maximum_attendees: 27, maximum_streams_per_day: 23, maximum_time_per_stream: 88, }, options: { attendee: { enable_2fa: false, enable_camera: false, enable_chat: false, enable_microphone: false, enable_multiple_hosts: false, enable_password: false, enable_private_messages: false, }, host: { enable_camera: true, enable_microphone: true, }, }, stream_id: 1234, stream_secret: 'test-key', stream_slug: 'test-slug', title: 'test-title', }; const model = new StreamConfigurationModel(schema); const newSchema = model.toSchema(); expect(newSchema).toStrictEqual(schema); }); }); });