import { StreamInteractionLibraryModel, StreamInteractionLibrarySchema, } from './stream-interaction-library.model'; describe('StreamInteractionLibraryModel', () => { describe('constructor', () => { it('should create and initialize empty model', () => { const model = new StreamInteractionLibraryModel(); expect(model.groupId).toBe(''); expect(model.groupName).toBe(null); expect(model.metadata).toStrictEqual([]); }); it('should intialize model from schema', () => { const schema: StreamInteractionLibrarySchema = { group_id: 'test-group-id', group_name: 'test-group-name', // TODO: Eventually need better typing/tests around // this metadata field metadata: [], }; const model = new StreamInteractionLibraryModel(schema); expect(model.groupId).toBe(schema.group_id); expect(model.groupName).toBe(schema.group_name); expect(model.metadata).toStrictEqual(schema.metadata); }); }); describe('#fromSchema', () => { it('should initialize from a schema input', () => { const model = new StreamInteractionLibraryModel(); expect(model.groupId).toBe(''); expect(model.groupName).toBe(null); expect(model.metadata).toStrictEqual([]); const schema: StreamInteractionLibrarySchema = { group_id: 'test-group-id', group_name: 'test-group-name', // TODO: Eventually need better typing/tests around // this metadata field metadata: [], }; model.fromSchema(schema); expect(model.groupId).toBe(schema.group_id); expect(model.groupName).toBe(schema.group_name); expect(model.metadata).toStrictEqual(schema.metadata); }); }); describe('#toSchema', () => { it('should build a schema object from the model', () => { const model = new StreamInteractionLibraryModel(); expect(model.groupId).toBe(''); expect(model.groupName).toBe(null); expect(model.metadata).toStrictEqual([]); const schema: StreamInteractionLibrarySchema = { group_id: 'test-group-id', group_name: 'test-group-name', // TODO: Eventually need better typing/tests around // this metadata field metadata: [], }; model.fromSchema(schema); const newSchema = model.toSchema(); expect(newSchema).toStrictEqual(schema); }); }); });