import { HostBillingModel } from './host-billing.model'; import { HostCredentialSchema } from './host-credential.model'; import { HostIdentificationModel } from './host-identification.model'; import { HostModel, HostSchema } from './host.model'; import { OwnerModel } from './owner.model'; import { StreamConfigurationModel } from './stream-configuration.model'; import { CoreConfigurationModel, } from './core-configuration.model'; describe('HostModel', () => { describe('constructor', () => { it('should create and initialize empty model', () => { const model = new HostModel(); expect(model.billing).toBeInstanceOf(HostBillingModel); expect(model.coreConfiguration).toBeInstanceOf(CoreConfigurationModel); expect(model.createdAt).toBeInstanceOf(Date); expect(model.identification).toBeInstanceOf(HostIdentificationModel); expect(model.owner).toBeInstanceOf(OwnerModel); expect(model.schemaVersion).toBe(1); expect(model.streamConfiguration).toBeInstanceOf(StreamConfigurationModel); expect(model.credentials).toBeInstanceOf(Map); }); it('should intialize model from schema', () => { const hostSchema: HostSchema = { billing: { account_type: 'free', end_date: 'Tue, 06 Oct 2020 13:07:50 GMT', minutes: 100, payments: [], }, core_configuration: { editor_configuration: {}, media_configuration: { media: [], media_types: [], }, }, created_at: 'Sat, 01 Dec 2012 05:00:00 GMT', credentials: [ { key: 'test-credential-key', }, ], identification: { email: 'test-email', family_name: 'test-family-name', given_name: 'test-given-name', issuer_metadata: {}, nickname: 'test-nickname', picture: 'test-picture', sub: 'test-sub', updated_at: 'Tue, 06 Oct 2020 22:07:50 GMT', }, owner: { client_id: 'test-client', user_id: 'test-user', }, schema_version: 1, stream_configuration: { 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 HostModel(hostSchema); expect(model.identification).toStrictEqual( new HostIdentificationModel(hostSchema.identification), ); expect(model.owner).toStrictEqual(new OwnerModel(hostSchema.owner)); expect(model.streamConfiguration).toStrictEqual( new StreamConfigurationModel(hostSchema.stream_configuration), ); expect(model.credentials.size).toBe(1); expect(model.getCredential('test-credential-key')).toStrictEqual({ key: 'test-credential-key', }); }); }); describe('#fromSchema', () => { it('should initialize from a schema input', () => { const model = new HostModel(); const hostSchema: HostSchema = { billing: { account_type: 'free', end_date: 'Tue, 06 Oct 2020 13:07:50 GMT', minutes: 100, payments: [], }, core_configuration: { editor_configuration: {}, media_configuration: { media: [], media_types: [], }, }, created_at: 'Sat, 01 Dec 2012 05:00:00 GMT', credentials: [ { key: 'test-credential-key', }, ], identification: { email: 'test-email', family_name: 'test-family-name', given_name: 'test-given-name', issuer_metadata: {}, nickname: 'test-nickname', picture: 'test-picture', sub: 'test-sub', updated_at: 'Tue, 06 Oct 2020 22:07:50 GMT', }, owner: { client_id: 'test-client', user_id: 'test-user', }, schema_version: 1, stream_configuration: { 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(hostSchema); expect(model.identification).toStrictEqual( new HostIdentificationModel(hostSchema.identification), ); expect(model.owner).toStrictEqual(new OwnerModel(hostSchema.owner)); expect(model.streamConfiguration).toStrictEqual( new StreamConfigurationModel(hostSchema.stream_configuration), ); expect(model.credentials.size).toBe(1); expect(model.getCredential('test-credential-key')).toStrictEqual({ key: 'test-credential-key', }); }); }); describe('#toSchema', () => { it('should build a schema object from the model', () => { const hostSchema: HostSchema = { billing: { account_type: 'free', end_date: 'Tue, 06 Oct 2020 13:07:50 GMT', minutes: 100, payments: [], }, core_configuration: { editor_configuration: {}, media_configuration: { media: [], media_types: [], }, }, created_at: 'Sat, 01 Dec 2012 05:00:00 GMT', credentials: [], identification: { email: 'test-email', family_name: 'test-family-name', given_name: 'test-given-name', issuer_metadata: {}, nickname: 'test-nickname', picture: 'test-picture', sub: 'test-sub', updated_at: 'Tue, 06 Oct 2020 22:07:50 GMT', }, owner: { client_id: 'test-client', user_id: 'test-user', }, schema_version: 1, stream_configuration: { 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 HostModel(hostSchema); const newSchema = model.toSchema(); expect(newSchema).toStrictEqual(hostSchema); }); }); describe('#credentials', () => { let model: HostModel; beforeEach(() => { model = new HostModel(); const mockSchema: HostCredentialSchema = { key: 'mock_key', }; model.setCredential('mock_key', mockSchema); }); it('should delete credentials', () => { model.deleteCredential('mock_key'); expect(model.getCredential('mock_Key')).toBeUndefined(); }); }); });