|
|
|
@ -21,7 +21,7 @@ import { |
|
|
|
SchemaDto, |
|
|
|
SchemasService, |
|
|
|
UpdateSchemaCategoryDto, |
|
|
|
Versioned |
|
|
|
versioned |
|
|
|
} from './../'; |
|
|
|
|
|
|
|
import { TestValues } from './_test-helpers'; |
|
|
|
@ -65,167 +65,152 @@ describe('SchemasState', () => { |
|
|
|
dialogs = Mock.ofType<DialogService>(); |
|
|
|
|
|
|
|
schemasService = Mock.ofType<SchemasService>(); |
|
|
|
|
|
|
|
schemasService.setup(x => x.getSchemas(app)) |
|
|
|
.returns(() => of(oldSchemas)); |
|
|
|
|
|
|
|
schemasService.setup(x => x.getSchema(app, schema.name)) |
|
|
|
.returns(() => of(schema)); |
|
|
|
|
|
|
|
schemasService.setup(x => x.getSchema(app, schema.name)) |
|
|
|
.returns(() => of(schema)); |
|
|
|
|
|
|
|
schemasState = new SchemasState(appsState.object, authService.object, dialogs.object, schemasService.object); |
|
|
|
schemasState.load().subscribe(); |
|
|
|
}); |
|
|
|
|
|
|
|
it('should load schemas', () => { |
|
|
|
expect(schemasState.snapshot.schemas.values).toEqual(oldSchemas); |
|
|
|
expect(schemasState.snapshot.isLoaded).toBeTruthy(); |
|
|
|
expect(schemasState.snapshot.categories).toEqual({ 'category1': false, 'category2': false }); |
|
|
|
|
|
|
|
afterEach(() => { |
|
|
|
schemasService.verifyAll(); |
|
|
|
}); |
|
|
|
|
|
|
|
it('should not remove custom category when loading schemas', () => { |
|
|
|
schemasState.addCategory('category3'); |
|
|
|
schemasState.load(true).subscribe(); |
|
|
|
describe('Loading', () => { |
|
|
|
it('should load schemas', () => { |
|
|
|
schemasService.setup(x => x.getSchemas(app)) |
|
|
|
.returns(() => of(oldSchemas)).verifiable(); |
|
|
|
|
|
|
|
expect(schemasState.snapshot.schemas.values).toEqual(oldSchemas); |
|
|
|
expect(schemasState.snapshot.isLoaded).toBeTruthy(); |
|
|
|
expect(schemasState.snapshot.categories).toEqual({ 'category1': false, 'category2': false, 'category3': true }); |
|
|
|
schemasState.load().subscribe(); |
|
|
|
|
|
|
|
schemasService.verifyAll(); |
|
|
|
}); |
|
|
|
expect(schemasState.snapshot.schemas.values).toEqual(oldSchemas); |
|
|
|
expect(schemasState.snapshot.isLoaded).toBeTruthy(); |
|
|
|
expect(schemasState.snapshot.categories).toEqual({ 'category1': false, 'category2': false }); |
|
|
|
|
|
|
|
it('should show notification on load when reload is true', () => { |
|
|
|
schemasState.load(true).subscribe(); |
|
|
|
schemasService.verifyAll(); |
|
|
|
}); |
|
|
|
|
|
|
|
expect().nothing(); |
|
|
|
it('should not remove custom category when loading schemas', () => { |
|
|
|
schemasService.setup(x => x.getSchemas(app)) |
|
|
|
.returns(() => of(oldSchemas)).verifiable(); |
|
|
|
|
|
|
|
dialogs.verify(x => x.notifyInfo(It.isAnyString()), Times.once()); |
|
|
|
}); |
|
|
|
schemasState.addCategory('category3'); |
|
|
|
schemasState.load(true).subscribe(); |
|
|
|
|
|
|
|
it('should add category', () => { |
|
|
|
schemasState.addCategory('category3'); |
|
|
|
expect(schemasState.snapshot.schemas.values).toEqual(oldSchemas); |
|
|
|
expect(schemasState.snapshot.isLoaded).toBeTruthy(); |
|
|
|
expect(schemasState.snapshot.categories).toEqual({ 'category1': false, 'category2': false, 'category3': true }); |
|
|
|
|
|
|
|
expect(schemasState.snapshot.categories).toEqual({ 'category1': false, 'category2': false, 'category3': true }); |
|
|
|
}); |
|
|
|
schemasService.verifyAll(); |
|
|
|
}); |
|
|
|
|
|
|
|
it('should remove category', () => { |
|
|
|
schemasState.removeCategory('category1'); |
|
|
|
it('should show notification on load when reload is true', () => { |
|
|
|
schemasService.setup(x => x.getSchemas(app)) |
|
|
|
.returns(() => of(oldSchemas)).verifiable(); |
|
|
|
|
|
|
|
expect(schemasState.snapshot.categories).toEqual({ 'category2': false }); |
|
|
|
}); |
|
|
|
schemasState.load(true).subscribe(); |
|
|
|
|
|
|
|
it('should return schema on select and reload when already loaded', () => { |
|
|
|
schemasState.select('name2').subscribe(); |
|
|
|
schemasState.select('name2').subscribe(); |
|
|
|
expect().nothing(); |
|
|
|
|
|
|
|
schemasService.verify(x => x.getSchema(app, 'name2'), Times.exactly(2)); |
|
|
|
|
|
|
|
expect().nothing(); |
|
|
|
dialogs.verify(x => x.notifyInfo(It.isAnyString()), Times.once()); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
it('should return schema on select and load when not loaded', () => { |
|
|
|
let selectedSchema: SchemaDetailsDto; |
|
|
|
describe('Updates', () => { |
|
|
|
beforeEach(() => { |
|
|
|
schemasService.setup(x => x.getSchemas(app)) |
|
|
|
.returns(() => of(oldSchemas)).verifiable(); |
|
|
|
|
|
|
|
schemasState.select('name2').subscribe(x => { |
|
|
|
selectedSchema = x!; |
|
|
|
schemasState.load().subscribe(); |
|
|
|
}); |
|
|
|
|
|
|
|
expect(selectedSchema!).toBe(schema); |
|
|
|
expect(schemasState.snapshot.selectedSchema).toBe(schema); |
|
|
|
expect(schemasState.snapshot.selectedSchema).toBe(<SchemaDetailsDto>schemasState.snapshot.schemas.at(1)); |
|
|
|
}); |
|
|
|
it('should add category', () => { |
|
|
|
schemasState.addCategory('category3'); |
|
|
|
|
|
|
|
it('should return null on select when loading failed', () => { |
|
|
|
schemasService.setup(x => x.getSchema(app, 'failed')) |
|
|
|
.returns(() => throwError({})); |
|
|
|
expect(schemasState.snapshot.categories).toEqual({ 'category1': false, 'category2': false, 'category3': true }); |
|
|
|
}); |
|
|
|
|
|
|
|
let selectedSchema: SchemaDetailsDto; |
|
|
|
it('should remove category', () => { |
|
|
|
schemasState.removeCategory('category1'); |
|
|
|
|
|
|
|
schemasState.select('failed').subscribe(x => { |
|
|
|
selectedSchema = x!; |
|
|
|
expect(schemasState.snapshot.categories).toEqual({ 'category2': false }); |
|
|
|
}); |
|
|
|
|
|
|
|
expect(selectedSchema!).toBeNull(); |
|
|
|
expect(schemasState.snapshot.selectedSchema).toBeNull(); |
|
|
|
}); |
|
|
|
it('should return schema on select and reload when already loaded', () => { |
|
|
|
schemasService.setup(x => x.getSchema(app, schema.name)) |
|
|
|
.returns(() => of(schema)).verifiable(Times.exactly(2)); |
|
|
|
|
|
|
|
it('should return null on select when unselecting schema', () => { |
|
|
|
let selectedSchema: SchemaDetailsDto; |
|
|
|
schemasState.select('name2').subscribe(); |
|
|
|
schemasState.select('name2').subscribe(); |
|
|
|
|
|
|
|
schemasState.select(null).subscribe(x => { |
|
|
|
selectedSchema = x!; |
|
|
|
expect().nothing(); |
|
|
|
}); |
|
|
|
|
|
|
|
expect(selectedSchema!).toBeNull(); |
|
|
|
expect(schemasState.snapshot.selectedSchema).toBeNull(); |
|
|
|
it('should return schema on select and load when not loaded', () => { |
|
|
|
schemasService.setup(x => x.getSchema(app, schema.name)) |
|
|
|
.returns(() => of(schema)).verifiable(); |
|
|
|
|
|
|
|
schemasService.verify(x => x.getSchema(app, It.isAnyString()), Times.never()); |
|
|
|
}); |
|
|
|
let selectedSchema: SchemaDetailsDto; |
|
|
|
|
|
|
|
it('should mark published and update user info when published', () => { |
|
|
|
schemasService.setup(x => x.publishSchema(app, oldSchemas[0].name, version)) |
|
|
|
.returns(() => of(new Versioned(newVersion, {}))); |
|
|
|
schemasState.select('name2').subscribe(x => { |
|
|
|
selectedSchema = x!; |
|
|
|
}); |
|
|
|
|
|
|
|
schemasState.publish(oldSchemas[0], modified).subscribe(); |
|
|
|
expect(selectedSchema!).toBe(schema); |
|
|
|
expect(schemasState.snapshot.selectedSchema).toBe(schema); |
|
|
|
expect(schemasState.snapshot.selectedSchema).toBe(<SchemaDetailsDto>schemasState.snapshot.schemas.at(1)); |
|
|
|
}); |
|
|
|
|
|
|
|
const schema_1 = schemasState.snapshot.schemas.at(0); |
|
|
|
it('should return null on select when loading failed', () => { |
|
|
|
schemasService.setup(x => x.getSchema(app, 'failed')) |
|
|
|
.returns(() => throwError({})).verifiable(); |
|
|
|
|
|
|
|
expect(schema_1.isPublished).toBeTruthy(); |
|
|
|
expectToBeModified(schema_1); |
|
|
|
}); |
|
|
|
let selectedSchema: SchemaDetailsDto; |
|
|
|
|
|
|
|
it('should unmark published and update user info when unpublished', () => { |
|
|
|
schemasService.setup(x => x.unpublishSchema(app, oldSchemas[1].name, version)) |
|
|
|
.returns(() => of(new Versioned(newVersion, {}))); |
|
|
|
schemasState.select('failed').subscribe(x => { |
|
|
|
selectedSchema = x!; |
|
|
|
}); |
|
|
|
|
|
|
|
schemasState.unpublish(oldSchemas[1], modified).subscribe(); |
|
|
|
|
|
|
|
const schema_1 = schemasState.snapshot.schemas.at(1); |
|
|
|
expect(selectedSchema!).toBeNull(); |
|
|
|
expect(schemasState.snapshot.selectedSchema).toBeNull(); |
|
|
|
}); |
|
|
|
|
|
|
|
expect(schema_1.isPublished).toBeFalsy(); |
|
|
|
expectToBeModified(schema_1); |
|
|
|
}); |
|
|
|
it('should return null on select when unselecting schema', () => { |
|
|
|
let selectedSchema: SchemaDetailsDto; |
|
|
|
|
|
|
|
it('should change category and update user info when category changed', () => { |
|
|
|
const category = 'my-new-category'; |
|
|
|
schemasState.select(null).subscribe(x => { |
|
|
|
selectedSchema = x!; |
|
|
|
}); |
|
|
|
|
|
|
|
schemasService.setup(x => x.putCategory(app, oldSchemas[0].name, It.is<UpdateSchemaCategoryDto>(i => i.name === category), version)) |
|
|
|
.returns(() => of(new Versioned(newVersion, {}))); |
|
|
|
expect(selectedSchema!).toBeNull(); |
|
|
|
expect(schemasState.snapshot.selectedSchema).toBeNull(); |
|
|
|
}); |
|
|
|
|
|
|
|
schemasState.changeCategory(oldSchemas[0], category, modified).subscribe(); |
|
|
|
it('should mark published and update user info when published', () => { |
|
|
|
schemasService.setup(x => x.publishSchema(app, oldSchemas[0].name, version)) |
|
|
|
.returns(() => of(versioned(newVersion))).verifiable(); |
|
|
|
|
|
|
|
const schema_1 = schemasState.snapshot.schemas.at(0); |
|
|
|
schemasState.publish(oldSchemas[0], modified).subscribe(); |
|
|
|
|
|
|
|
expect(schema_1.category).toEqual(category); |
|
|
|
expectToBeModified(schema_1); |
|
|
|
}); |
|
|
|
const schema_1 = schemasState.snapshot.schemas.at(0); |
|
|
|
|
|
|
|
describe('with selection', () => { |
|
|
|
beforeEach(() => { |
|
|
|
schemasState.select(schema.name).subscribe(); |
|
|
|
expect(schema_1.isPublished).toBeTruthy(); |
|
|
|
expectToBeModified(schema_1); |
|
|
|
}); |
|
|
|
|
|
|
|
it('should nmark published and update user info when published selected schema', () => { |
|
|
|
schemasService.setup(x => x.publishSchema(app, schema.name, version)) |
|
|
|
.returns(() => of(new Versioned(newVersion, {}))); |
|
|
|
it('should unmark published and update user info when unpublished', () => { |
|
|
|
schemasService.setup(x => x.unpublishSchema(app, oldSchemas[1].name, version)) |
|
|
|
.returns(() => of(versioned(newVersion))).verifiable(); |
|
|
|
|
|
|
|
schemasState.publish(schema, modified).subscribe(); |
|
|
|
schemasState.unpublish(oldSchemas[1], modified).subscribe(); |
|
|
|
|
|
|
|
const schema_1 = <SchemaDetailsDto>schemasState.snapshot.schemas.at(1); |
|
|
|
const schema_1 = schemasState.snapshot.schemas.at(1); |
|
|
|
|
|
|
|
expect(schema_1.isPublished).toBeTruthy(); |
|
|
|
expect(schema_1.isPublished).toBeFalsy(); |
|
|
|
expectToBeModified(schema_1); |
|
|
|
}); |
|
|
|
|
|
|
|
it('should change category and update user info when category of selected schema changed', () => { |
|
|
|
it('should change category and update user info when category changed', () => { |
|
|
|
const category = 'my-new-category'; |
|
|
|
|
|
|
|
schemasService.setup(x => x.putCategory(app, oldSchemas[0].name, It.is<UpdateSchemaCategoryDto>(i => i.name === category), version)) |
|
|
|
.returns(() => of(new Versioned(newVersion, {}))); |
|
|
|
.returns(() => of(versioned(newVersion))).verifiable(); |
|
|
|
|
|
|
|
schemasState.changeCategory(oldSchemas[0], category, modified).subscribe(); |
|
|
|
|
|
|
|
@ -235,305 +220,340 @@ describe('SchemasState', () => { |
|
|
|
expectToBeModified(schema_1); |
|
|
|
}); |
|
|
|
|
|
|
|
it('should update properties and update user info when updated', () => { |
|
|
|
const request = { label: 'name2_label', hints: 'name2_hints' }; |
|
|
|
describe('with selection', () => { |
|
|
|
beforeEach(() => { |
|
|
|
schemasService.setup(x => x.getSchema(app, schema.name)) |
|
|
|
.returns(() => of(schema)).verifiable(); |
|
|
|
|
|
|
|
schemasService.setup(x => x.putSchema(app, schema.name, It.isAny(), version)) |
|
|
|
.returns(() => of(new Versioned(newVersion, {}))); |
|
|
|
schemasState.select(schema.name).subscribe(); |
|
|
|
}); |
|
|
|
|
|
|
|
schemasState.update(schema, request, modified).subscribe(); |
|
|
|
it('should nmark published and update user info when published selected schema', () => { |
|
|
|
schemasService.setup(x => x.publishSchema(app, schema.name, version)) |
|
|
|
.returns(() => of(versioned(newVersion))).verifiable(); |
|
|
|
|
|
|
|
const schema_1 = <SchemaDetailsDto>schemasState.snapshot.schemas.at(1); |
|
|
|
schemasState.publish(schema, modified).subscribe(); |
|
|
|
|
|
|
|
expect(schema_1.properties.label).toEqual(request.label); |
|
|
|
expect(schema_1.properties.hints).toEqual(request.hints); |
|
|
|
expectToBeModified(schema_1); |
|
|
|
}); |
|
|
|
const schema_1 = <SchemaDetailsDto>schemasState.snapshot.schemas.at(1); |
|
|
|
|
|
|
|
it('should update script properties and update user info when scripts configured', () => { |
|
|
|
const request = { query: '<query-script>' }; |
|
|
|
expect(schema_1.isPublished).toBeTruthy(); |
|
|
|
expectToBeModified(schema_1); |
|
|
|
}); |
|
|
|
|
|
|
|
schemasService.setup(x => x.putScripts(app, schema.name, It.isAny(), version)) |
|
|
|
.returns(() => of(new Versioned(newVersion, {}))); |
|
|
|
it('should change category and update user info when category of selected schema changed', () => { |
|
|
|
const category = 'my-new-category'; |
|
|
|
|
|
|
|
schemasState.configureScripts(schema, request, modified).subscribe(); |
|
|
|
schemasService.setup(x => x.putCategory(app, oldSchemas[0].name, It.is<UpdateSchemaCategoryDto>(i => i.name === category), version)) |
|
|
|
.returns(() => of(versioned(newVersion))).verifiable(); |
|
|
|
|
|
|
|
const schema_1 = <SchemaDetailsDto>schemasState.snapshot.schemas.at(1); |
|
|
|
schemasState.changeCategory(oldSchemas[0], category, modified).subscribe(); |
|
|
|
|
|
|
|
expect(schema_1.scripts['query']).toEqual('<query-script>'); |
|
|
|
expectToBeModified(schema_1); |
|
|
|
}); |
|
|
|
const schema_1 = schemasState.snapshot.schemas.at(0); |
|
|
|
|
|
|
|
it('should update script properties and update user info when preview urls configured', () => { |
|
|
|
const request = { web: 'url' }; |
|
|
|
expect(schema_1.category).toEqual(category); |
|
|
|
expectToBeModified(schema_1); |
|
|
|
}); |
|
|
|
|
|
|
|
schemasService.setup(x => x.putPreviewUrls(app, schema.name, It.isAny(), version)) |
|
|
|
.returns(() => of(new Versioned(newVersion, {}))); |
|
|
|
it('should update properties and update user info when updated', () => { |
|
|
|
const request = { label: 'name2_label', hints: 'name2_hints' }; |
|
|
|
|
|
|
|
schemasState.configurePreviewUrls(schema, request, modified).subscribe(); |
|
|
|
schemasService.setup(x => x.putSchema(app, schema.name, It.isAny(), version)) |
|
|
|
.returns(() => of(versioned(newVersion))).verifiable(); |
|
|
|
|
|
|
|
const schema_1 = <SchemaDetailsDto>schemasState.snapshot.schemas.at(1); |
|
|
|
schemasState.update(schema, request, modified).subscribe(); |
|
|
|
|
|
|
|
expect(schema_1.previewUrls).toEqual(request); |
|
|
|
expectToBeModified(schema_1); |
|
|
|
}); |
|
|
|
const schema_1 = <SchemaDetailsDto>schemasState.snapshot.schemas.at(1); |
|
|
|
|
|
|
|
it('should add schema to snapshot when created', () => { |
|
|
|
const request = new CreateSchemaDto('newName'); |
|
|
|
expect(schema_1.properties.label).toEqual(request.label); |
|
|
|
expect(schema_1.properties.hints).toEqual(request.hints); |
|
|
|
expectToBeModified(schema_1); |
|
|
|
}); |
|
|
|
|
|
|
|
const result = new SchemaDetailsDto('id4', 'newName', '', {}, false, false, modified, modifier, modified, modifier, version); |
|
|
|
it('should update script properties and update user info when scripts configured', () => { |
|
|
|
const request = { query: '<query-script>' }; |
|
|
|
|
|
|
|
schemasService.setup(x => x.postSchema(app, request, modifier, modified)) |
|
|
|
.returns(() => of(result)); |
|
|
|
schemasService.setup(x => x.putScripts(app, schema.name, It.isAny(), version)) |
|
|
|
.returns(() => of(versioned(newVersion))).verifiable(); |
|
|
|
|
|
|
|
schemasState.create(request, modified).subscribe(); |
|
|
|
schemasState.configureScripts(schema, request, modified).subscribe(); |
|
|
|
|
|
|
|
expect(schemasState.snapshot.schemas.values.length).toBe(3); |
|
|
|
expect(schemasState.snapshot.schemas.at(2)).toBe(result); |
|
|
|
}); |
|
|
|
const schema_1 = <SchemaDetailsDto>schemasState.snapshot.schemas.at(1); |
|
|
|
|
|
|
|
it('should remove schema from snapshot when deleted', () => { |
|
|
|
schemasService.setup(x => x.deleteSchema(app, schema.name, version)) |
|
|
|
.returns(() => of(new Versioned(newVersion, {}))); |
|
|
|
expect(schema_1.scripts['query']).toEqual('<query-script>'); |
|
|
|
expectToBeModified(schema_1); |
|
|
|
}); |
|
|
|
|
|
|
|
schemasState.delete(schema).subscribe(); |
|
|
|
it('should update script properties and update user info when preview urls configured', () => { |
|
|
|
const request = { web: 'url' }; |
|
|
|
|
|
|
|
expect(schemasState.snapshot.schemas.values.length).toBe(1); |
|
|
|
expect(schemasState.snapshot.selectedSchema).toBeNull(); |
|
|
|
}); |
|
|
|
schemasService.setup(x => x.putPreviewUrls(app, schema.name, It.isAny(), version)) |
|
|
|
.returns(() => of(versioned(newVersion))).verifiable(); |
|
|
|
|
|
|
|
it('should add field and update user info when field added', () => { |
|
|
|
const request = new AddFieldDto(field1.name, field1.partitioning, field1.properties); |
|
|
|
schemasState.configurePreviewUrls(schema, request, modified).subscribe(); |
|
|
|
|
|
|
|
const newField = new RootFieldDto(3, '3', createProperties('String'), 'invariant'); |
|
|
|
const schema_1 = <SchemaDetailsDto>schemasState.snapshot.schemas.at(1); |
|
|
|
|
|
|
|
schemasService.setup(x => x.postField(app, schema.name, It.isAny(), undefined, version)) |
|
|
|
.returns(() => of(new Versioned(newVersion, newField))); |
|
|
|
expect(schema_1.previewUrls).toEqual(request); |
|
|
|
expectToBeModified(schema_1); |
|
|
|
}); |
|
|
|
|
|
|
|
schemasState.addField(schema, request, undefined, modified).subscribe(); |
|
|
|
it('should add schema to snapshot when created', () => { |
|
|
|
const request = new CreateSchemaDto('newName'); |
|
|
|
|
|
|
|
const schema_1 = <SchemaDetailsDto>schemasState.snapshot.schemas.at(1); |
|
|
|
const result = new SchemaDetailsDto('id4', 'newName', '', {}, false, false, modified, modifier, modified, modifier, version); |
|
|
|
|
|
|
|
expect(schema_1.fields).toEqual([field1, field2, newField]); |
|
|
|
expectToBeModified(schema_1); |
|
|
|
}); |
|
|
|
schemasService.setup(x => x.postSchema(app, request, modifier, modified)) |
|
|
|
.returns(() => of(result)).verifiable(); |
|
|
|
|
|
|
|
it('should add field and update user info when nested field added', () => { |
|
|
|
const request = new AddFieldDto(field1.name, field1.partitioning, field1.properties); |
|
|
|
schemasState.create(request, modified).subscribe(); |
|
|
|
|
|
|
|
const newField = new NestedFieldDto(3, '3', createProperties('String'), 2); |
|
|
|
expect(schemasState.snapshot.schemas.values.length).toBe(3); |
|
|
|
expect(schemasState.snapshot.schemas.at(2)).toBe(result); |
|
|
|
}); |
|
|
|
|
|
|
|
schemasService.setup(x => x.postField(app, schema.name, It.isAny(), 2, version)) |
|
|
|
.returns(() => of(new Versioned(newVersion, newField))); |
|
|
|
it('should remove schema from snapshot when deleted', () => { |
|
|
|
schemasService.setup(x => x.deleteSchema(app, schema.name, version)) |
|
|
|
.returns(() => of(versioned(newVersion))).verifiable(); |
|
|
|
|
|
|
|
schemasState.addField(schema, request, field2, modified).subscribe(); |
|
|
|
schemasState.delete(schema).subscribe(); |
|
|
|
|
|
|
|
const schema_1 = <SchemaDetailsDto>schemasState.snapshot.schemas.at(1); |
|
|
|
expect(schemasState.snapshot.schemas.values.length).toBe(1); |
|
|
|
expect(schemasState.snapshot.selectedSchema).toBeNull(); |
|
|
|
}); |
|
|
|
|
|
|
|
expect(schema_1.fields[1].nested).toEqual([nested1, nested2, newField]); |
|
|
|
expectToBeModified(schema_1); |
|
|
|
}); |
|
|
|
it('should add field and update user info when field added', () => { |
|
|
|
const request = new AddFieldDto(field1.name, field1.partitioning, field1.properties); |
|
|
|
|
|
|
|
it('should remove field and update user info when field removed', () => { |
|
|
|
schemasService.setup(x => x.deleteField(app, schema.name, field1.fieldId, undefined, version)) |
|
|
|
.returns(() => of(new Versioned(newVersion, {}))); |
|
|
|
const newField = new RootFieldDto(3, '3', createProperties('String'), 'invariant'); |
|
|
|
|
|
|
|
schemasState.deleteField(schema, field1, modified).subscribe(); |
|
|
|
schemasService.setup(x => x.postField(app, schema.name, It.isAny(), undefined, version)) |
|
|
|
.returns(() => of(versioned(newVersion, newField))).verifiable(); |
|
|
|
|
|
|
|
const schema_1 = <SchemaDetailsDto>schemasState.snapshot.schemas.at(1); |
|
|
|
schemasState.addField(schema, request, undefined, modified).subscribe(); |
|
|
|
|
|
|
|
expect(schema_1.fields).toEqual([field2]); |
|
|
|
expectToBeModified(schema_1); |
|
|
|
}); |
|
|
|
const schema_1 = <SchemaDetailsDto>schemasState.snapshot.schemas.at(1); |
|
|
|
|
|
|
|
it('should remove field and update user info when nested field removed', () => { |
|
|
|
schemasService.setup(x => x.deleteField(app, schema.name, nested1.fieldId, 2, version)) |
|
|
|
.returns(() => of(new Versioned(newVersion, {}))); |
|
|
|
expect(schema_1.fields).toEqual([field1, field2, newField]); |
|
|
|
expectToBeModified(schema_1); |
|
|
|
}); |
|
|
|
|
|
|
|
schemasState.deleteField(schema, nested1, modified).subscribe(); |
|
|
|
it('should add field and update user info when nested field added', () => { |
|
|
|
const request = new AddFieldDto(field1.name, field1.partitioning, field1.properties); |
|
|
|
|
|
|
|
const schema_1 = <SchemaDetailsDto>schemasState.snapshot.schemas.at(1); |
|
|
|
const newField = new NestedFieldDto(3, '3', createProperties('String'), 2); |
|
|
|
|
|
|
|
expect(schema_1.fields[1].nested).toEqual([nested2]); |
|
|
|
expectToBeModified(schema_1); |
|
|
|
}); |
|
|
|
schemasService.setup(x => x.postField(app, schema.name, It.isAny(), 2, version)) |
|
|
|
.returns(() => of(versioned(newVersion, newField))).verifiable(); |
|
|
|
|
|
|
|
it('should sort fields and update user info when fields sorted', () => { |
|
|
|
schemasService.setup(x => x.putFieldOrdering(app, schema.name, [field2.fieldId, field1.fieldId], undefined, version)) |
|
|
|
.returns(() => of(new Versioned(newVersion, {}))); |
|
|
|
schemasState.addField(schema, request, field2, modified).subscribe(); |
|
|
|
|
|
|
|
schemasState.sortFields(schema, [field2, field1], undefined, modified).subscribe(); |
|
|
|
const schema_1 = <SchemaDetailsDto>schemasState.snapshot.schemas.at(1); |
|
|
|
|
|
|
|
const schema_1 = <SchemaDetailsDto>schemasState.snapshot.schemas.at(1); |
|
|
|
expect(schema_1.fields[1].nested).toEqual([nested1, nested2, newField]); |
|
|
|
expectToBeModified(schema_1); |
|
|
|
}); |
|
|
|
|
|
|
|
expect(schema_1.fields).toEqual([field2, field1]); |
|
|
|
expectToBeModified(schema_1); |
|
|
|
}); |
|
|
|
it('should remove field and update user info when field removed', () => { |
|
|
|
schemasService.setup(x => x.deleteField(app, schema.name, field1.fieldId, undefined, version)) |
|
|
|
.returns(() => of(versioned(newVersion))).verifiable(); |
|
|
|
|
|
|
|
it('should sort fields and update user info when nested fields sorted', () => { |
|
|
|
schemasService.setup(x => x.putFieldOrdering(app, schema.name, [nested2.fieldId, nested1.fieldId], 2, version)) |
|
|
|
.returns(() => of(new Versioned(newVersion, {}))); |
|
|
|
schemasState.deleteField(schema, field1, modified).subscribe(); |
|
|
|
|
|
|
|
schemasState.sortFields(schema, [nested2, nested1], field2, modified).subscribe(); |
|
|
|
const schema_1 = <SchemaDetailsDto>schemasState.snapshot.schemas.at(1); |
|
|
|
|
|
|
|
const schema_1 = <SchemaDetailsDto>schemasState.snapshot.schemas.at(1); |
|
|
|
expect(schema_1.fields).toEqual([field2]); |
|
|
|
expectToBeModified(schema_1); |
|
|
|
}); |
|
|
|
|
|
|
|
expect(schema_1.fields[1].nested).toEqual([nested2, nested1]); |
|
|
|
expectToBeModified(schema_1); |
|
|
|
}); |
|
|
|
it('should remove field and update user info when nested field removed', () => { |
|
|
|
schemasService.setup(x => x.deleteField(app, schema.name, nested1.fieldId, 2, version)) |
|
|
|
.returns(() => of(versioned(newVersion))).verifiable(); |
|
|
|
|
|
|
|
it('should update field properties and update user info when field updated', () => { |
|
|
|
const request = { properties: createProperties('String') }; |
|
|
|
schemasState.deleteField(schema, nested1, modified).subscribe(); |
|
|
|
|
|
|
|
schemasService.setup(x => x.putField(app, schema.name, field1.fieldId, request, undefined, version)) |
|
|
|
.returns(() => of(new Versioned(newVersion, {}))); |
|
|
|
const schema_1 = <SchemaDetailsDto>schemasState.snapshot.schemas.at(1); |
|
|
|
|
|
|
|
schemasState.updateField(schema, field1, request, modified).subscribe(); |
|
|
|
expect(schema_1.fields[1].nested).toEqual([nested2]); |
|
|
|
expectToBeModified(schema_1); |
|
|
|
}); |
|
|
|
|
|
|
|
const schema_1 = <SchemaDetailsDto>schemasState.snapshot.schemas.at(1); |
|
|
|
it('should sort fields and update user info when fields sorted', () => { |
|
|
|
schemasService.setup(x => x.putFieldOrdering(app, schema.name, [field2.fieldId, field1.fieldId], undefined, version)) |
|
|
|
.returns(() => of(versioned(newVersion))).verifiable(); |
|
|
|
|
|
|
|
expect(schema_1.fields[0].properties).toBe(request.properties); |
|
|
|
expectToBeModified(schema_1); |
|
|
|
}); |
|
|
|
schemasState.sortFields(schema, [field2, field1], undefined, modified).subscribe(); |
|
|
|
|
|
|
|
it('should update field properties and update user info when nested field updated', () => { |
|
|
|
const request = { properties: createProperties('String') }; |
|
|
|
const schema_1 = <SchemaDetailsDto>schemasState.snapshot.schemas.at(1); |
|
|
|
|
|
|
|
schemasService.setup(x => x.putField(app, schema.name, nested1.fieldId, request, 2, version)) |
|
|
|
.returns(() => of(new Versioned(newVersion, {}))); |
|
|
|
expect(schema_1.fields).toEqual([field2, field1]); |
|
|
|
expectToBeModified(schema_1); |
|
|
|
}); |
|
|
|
|
|
|
|
schemasState.updateField(schema, nested1, request, modified).subscribe(); |
|
|
|
it('should sort fields and update user info when nested fields sorted', () => { |
|
|
|
schemasService.setup(x => x.putFieldOrdering(app, schema.name, [nested2.fieldId, nested1.fieldId], 2, version)) |
|
|
|
.returns(() => of(versioned(newVersion))).verifiable(); |
|
|
|
|
|
|
|
const schema_1 = <SchemaDetailsDto>schemasState.snapshot.schemas.at(1); |
|
|
|
schemasState.sortFields(schema, [nested2, nested1], field2, modified).subscribe(); |
|
|
|
|
|
|
|
expect(schema_1.fields[1].nested[0].properties).toBe(request.properties); |
|
|
|
expectToBeModified(schema_1); |
|
|
|
}); |
|
|
|
const schema_1 = <SchemaDetailsDto>schemasState.snapshot.schemas.at(1); |
|
|
|
|
|
|
|
it('should mark field hidden and update user info when field hidden', () => { |
|
|
|
schemasService.setup(x => x.hideField(app, schema.name, field1.fieldId, undefined, version)) |
|
|
|
.returns(() => of(new Versioned(newVersion, {}))); |
|
|
|
expect(schema_1.fields[1].nested).toEqual([nested2, nested1]); |
|
|
|
expectToBeModified(schema_1); |
|
|
|
}); |
|
|
|
|
|
|
|
schemasState.hideField(schema, field1, modified).subscribe(); |
|
|
|
it('should update field properties and update user info when field updated', () => { |
|
|
|
const request = { properties: createProperties('String') }; |
|
|
|
|
|
|
|
const schema_1 = <SchemaDetailsDto>schemasState.snapshot.schemas.at(1); |
|
|
|
schemasService.setup(x => x.putField(app, schema.name, field1.fieldId, request, undefined, version)) |
|
|
|
.returns(() => of(versioned(newVersion))).verifiable(); |
|
|
|
|
|
|
|
expect(schema_1.fields[0].isHidden).toBeTruthy(); |
|
|
|
expectToBeModified(schema_1); |
|
|
|
}); |
|
|
|
schemasState.updateField(schema, field1, request, modified).subscribe(); |
|
|
|
|
|
|
|
it('should mark field hidden and update user info when nested field hidden', () => { |
|
|
|
schemasService.setup(x => x.hideField(app, schema.name, nested1.fieldId, 2, version)) |
|
|
|
.returns(() => of(new Versioned(newVersion, {}))); |
|
|
|
const schema_1 = <SchemaDetailsDto>schemasState.snapshot.schemas.at(1); |
|
|
|
|
|
|
|
schemasState.hideField(schema, nested1, modified).subscribe(); |
|
|
|
expect(schema_1.fields[0].properties).toBe(request.properties); |
|
|
|
expectToBeModified(schema_1); |
|
|
|
}); |
|
|
|
|
|
|
|
const schema_1 = <SchemaDetailsDto>schemasState.snapshot.schemas.at(1); |
|
|
|
it('should update field properties and update user info when nested field updated', () => { |
|
|
|
const request = { properties: createProperties('String') }; |
|
|
|
|
|
|
|
expect(schema_1.fields[1].nested[0].isHidden).toBeTruthy(); |
|
|
|
expectToBeModified(schema_1); |
|
|
|
}); |
|
|
|
schemasService.setup(x => x.putField(app, schema.name, nested1.fieldId, request, 2, version)) |
|
|
|
.returns(() => of(versioned(newVersion))).verifiable(); |
|
|
|
|
|
|
|
it('should mark field disabled and update user info when field disabled', () => { |
|
|
|
schemasService.setup(x => x.disableField(app, schema.name, field1.fieldId, undefined, version)) |
|
|
|
.returns(() => of(new Versioned(newVersion, {}))); |
|
|
|
schemasState.updateField(schema, nested1, request, modified).subscribe(); |
|
|
|
|
|
|
|
schemasState.disableField(schema, field1, modified).subscribe(); |
|
|
|
const schema_1 = <SchemaDetailsDto>schemasState.snapshot.schemas.at(1); |
|
|
|
|
|
|
|
const schema_1 = <SchemaDetailsDto>schemasState.snapshot.schemas.at(1); |
|
|
|
expect(schema_1.fields[1].nested[0].properties).toBe(request.properties); |
|
|
|
expectToBeModified(schema_1); |
|
|
|
}); |
|
|
|
|
|
|
|
expect(schema_1.fields[0].isDisabled).toBeTruthy(); |
|
|
|
expectToBeModified(schema_1); |
|
|
|
}); |
|
|
|
it('should mark field hidden and update user info when field hidden', () => { |
|
|
|
schemasService.setup(x => x.hideField(app, schema.name, field1.fieldId, undefined, version)) |
|
|
|
.returns(() => of(versioned(newVersion))).verifiable(); |
|
|
|
|
|
|
|
it('should mark field disabled and update user info when nested disabled', () => { |
|
|
|
schemasService.setup(x => x.disableField(app, schema.name, nested1.fieldId, 2, version)) |
|
|
|
.returns(() => of(new Versioned(newVersion, {}))); |
|
|
|
schemasState.hideField(schema, field1, modified).subscribe(); |
|
|
|
|
|
|
|
schemasState.disableField(schema, nested1, modified).subscribe(); |
|
|
|
const schema_1 = <SchemaDetailsDto>schemasState.snapshot.schemas.at(1); |
|
|
|
|
|
|
|
const schema_1 = <SchemaDetailsDto>schemasState.snapshot.schemas.at(1); |
|
|
|
expect(schema_1.fields[0].isHidden).toBeTruthy(); |
|
|
|
expectToBeModified(schema_1); |
|
|
|
}); |
|
|
|
|
|
|
|
expect(schema_1.fields[1].nested[0].isDisabled).toBeTruthy(); |
|
|
|
expectToBeModified(schema_1); |
|
|
|
}); |
|
|
|
it('should mark field hidden and update user info when nested field hidden', () => { |
|
|
|
schemasService.setup(x => x.hideField(app, schema.name, nested1.fieldId, 2, version)) |
|
|
|
.returns(() => of(versioned(newVersion))).verifiable(); |
|
|
|
|
|
|
|
it('should mark field locked and update user info when field locked', () => { |
|
|
|
schemasService.setup(x => x.lockField(app, schema.name, field1.fieldId, undefined, version)) |
|
|
|
.returns(() => of(new Versioned(newVersion, {}))); |
|
|
|
schemasState.hideField(schema, nested1, modified).subscribe(); |
|
|
|
|
|
|
|
schemasState.lockField(schema, field1, modified).subscribe(); |
|
|
|
const schema_1 = <SchemaDetailsDto>schemasState.snapshot.schemas.at(1); |
|
|
|
|
|
|
|
const schema_1 = <SchemaDetailsDto>schemasState.snapshot.schemas.at(1); |
|
|
|
expect(schema_1.fields[1].nested[0].isHidden).toBeTruthy(); |
|
|
|
expectToBeModified(schema_1); |
|
|
|
}); |
|
|
|
|
|
|
|
expect(schema_1.fields[0].isLocked).toBeTruthy(); |
|
|
|
expectToBeModified(schema_1); |
|
|
|
}); |
|
|
|
it('should mark field disabled and update user info when field disabled', () => { |
|
|
|
schemasService.setup(x => x.disableField(app, schema.name, field1.fieldId, undefined, version)) |
|
|
|
.returns(() => of(versioned(newVersion))); |
|
|
|
|
|
|
|
it('should mark field locked and update user info when nested field locked', () => { |
|
|
|
schemasService.setup(x => x.lockField(app, schema.name, nested1.fieldId, 2, version)) |
|
|
|
.returns(() => of(new Versioned(newVersion, {}))); |
|
|
|
schemasState.disableField(schema, field1, modified).subscribe(); |
|
|
|
|
|
|
|
schemasState.lockField(schema, nested1, modified).subscribe(); |
|
|
|
const schema_1 = <SchemaDetailsDto>schemasState.snapshot.schemas.at(1); |
|
|
|
|
|
|
|
const schema_1 = <SchemaDetailsDto>schemasState.snapshot.schemas.at(1); |
|
|
|
expect(schema_1.fields[0].isDisabled).toBeTruthy(); |
|
|
|
expectToBeModified(schema_1); |
|
|
|
}); |
|
|
|
|
|
|
|
expect(schema_1.fields[1].nested[0].isLocked).toBeTruthy(); |
|
|
|
expectToBeModified(schema_1); |
|
|
|
}); |
|
|
|
it('should mark field disabled and update user info when nested disabled', () => { |
|
|
|
schemasService.setup(x => x.disableField(app, schema.name, nested1.fieldId, 2, version)) |
|
|
|
.returns(() => of(versioned(newVersion))).verifiable(); |
|
|
|
|
|
|
|
it('should unmark field hidden and update user info when field shown', () => { |
|
|
|
schemasService.setup(x => x.showField(app, schema.name, field2.fieldId, undefined, version)) |
|
|
|
.returns(() => of(new Versioned(newVersion, {}))); |
|
|
|
schemasState.disableField(schema, nested1, modified).subscribe(); |
|
|
|
|
|
|
|
schemasState.showField(schema, field2, modified).subscribe(); |
|
|
|
const schema_1 = <SchemaDetailsDto>schemasState.snapshot.schemas.at(1); |
|
|
|
|
|
|
|
const schema_1 = <SchemaDetailsDto>schemasState.snapshot.schemas.at(1); |
|
|
|
expect(schema_1.fields[1].nested[0].isDisabled).toBeTruthy(); |
|
|
|
expectToBeModified(schema_1); |
|
|
|
}); |
|
|
|
|
|
|
|
expect(schema_1.fields[1].isHidden).toBeFalsy(); |
|
|
|
expectToBeModified(schema_1); |
|
|
|
}); |
|
|
|
it('should mark field locked and update user info when field locked', () => { |
|
|
|
schemasService.setup(x => x.lockField(app, schema.name, field1.fieldId, undefined, version)) |
|
|
|
.returns(() => of(versioned(newVersion))).verifiable(); |
|
|
|
|
|
|
|
it('should unmark field hidden and update user info when nested field shown', () => { |
|
|
|
schemasService.setup(x => x.showField(app, schema.name, nested2.fieldId, 2, version)) |
|
|
|
.returns(() => of(new Versioned(newVersion, {}))); |
|
|
|
schemasState.lockField(schema, field1, modified).subscribe(); |
|
|
|
|
|
|
|
schemasState.showField(schema, nested2, modified).subscribe(); |
|
|
|
const schema_1 = <SchemaDetailsDto>schemasState.snapshot.schemas.at(1); |
|
|
|
|
|
|
|
const schema_1 = <SchemaDetailsDto>schemasState.snapshot.schemas.at(1); |
|
|
|
expect(schema_1.fields[0].isLocked).toBeTruthy(); |
|
|
|
expectToBeModified(schema_1); |
|
|
|
}); |
|
|
|
|
|
|
|
expect(schema_1.fields[1].nested[1].isHidden).toBeFalsy(); |
|
|
|
expectToBeModified(schema_1); |
|
|
|
}); |
|
|
|
it('should mark field locked and update user info when nested field locked', () => { |
|
|
|
schemasService.setup(x => x.lockField(app, schema.name, nested1.fieldId, 2, version)) |
|
|
|
.returns(() => of(versioned(newVersion))).verifiable(); |
|
|
|
|
|
|
|
it('should unmark field disabled and update user info when field enabled', () => { |
|
|
|
schemasService.setup(x => x.enableField(app, schema.name, field2.fieldId, undefined, version)) |
|
|
|
.returns(() => of(new Versioned(newVersion, {}))); |
|
|
|
schemasState.lockField(schema, nested1, modified).subscribe(); |
|
|
|
|
|
|
|
schemasState.enableField(schema, field2, modified).subscribe(); |
|
|
|
const schema_1 = <SchemaDetailsDto>schemasState.snapshot.schemas.at(1); |
|
|
|
|
|
|
|
const schema_1 = <SchemaDetailsDto>schemasState.snapshot.schemas.at(1); |
|
|
|
expect(schema_1.fields[1].nested[0].isLocked).toBeTruthy(); |
|
|
|
expectToBeModified(schema_1); |
|
|
|
}); |
|
|
|
|
|
|
|
expect(schema_1.fields[1].isDisabled).toBeFalsy(); |
|
|
|
expectToBeModified(schema_1); |
|
|
|
}); |
|
|
|
it('should unmark field hidden and update user info when field shown', () => { |
|
|
|
schemasService.setup(x => x.showField(app, schema.name, field2.fieldId, undefined, version)) |
|
|
|
.returns(() => of(versioned(newVersion))).verifiable(); |
|
|
|
|
|
|
|
it('should unmark field disabled and update user info when nested field enabled', () => { |
|
|
|
schemasService.setup(x => x.enableField(app, schema.name, nested2.fieldId, 2, version)) |
|
|
|
.returns(() => of(new Versioned(newVersion, {}))); |
|
|
|
schemasState.showField(schema, field2, modified).subscribe(); |
|
|
|
|
|
|
|
schemasState.enableField(schema, nested2, modified).subscribe(); |
|
|
|
const schema_1 = <SchemaDetailsDto>schemasState.snapshot.schemas.at(1); |
|
|
|
|
|
|
|
const schema_1 = <SchemaDetailsDto>schemasState.snapshot.schemas.at(1); |
|
|
|
expect(schema_1.fields[1].isHidden).toBeFalsy(); |
|
|
|
expectToBeModified(schema_1); |
|
|
|
}); |
|
|
|
|
|
|
|
expect(schema_1.fields[1].nested[1].isDisabled).toBeFalsy(); |
|
|
|
expectToBeModified(schema_1); |
|
|
|
it('should unmark field hidden and update user info when nested field shown', () => { |
|
|
|
schemasService.setup(x => x.showField(app, schema.name, nested2.fieldId, 2, version)) |
|
|
|
.returns(() => of(versioned(newVersion))).verifiable(); |
|
|
|
|
|
|
|
schemasState.showField(schema, nested2, modified).subscribe(); |
|
|
|
|
|
|
|
const schema_1 = <SchemaDetailsDto>schemasState.snapshot.schemas.at(1); |
|
|
|
|
|
|
|
expect(schema_1.fields[1].nested[1].isHidden).toBeFalsy(); |
|
|
|
expectToBeModified(schema_1); |
|
|
|
}); |
|
|
|
|
|
|
|
it('should unmark field disabled and update user info when field enabled', () => { |
|
|
|
schemasService.setup(x => x.enableField(app, schema.name, field2.fieldId, undefined, version)) |
|
|
|
.returns(() => of(versioned(newVersion))).verifiable(); |
|
|
|
|
|
|
|
schemasState.enableField(schema, field2, modified).subscribe(); |
|
|
|
|
|
|
|
const schema_1 = <SchemaDetailsDto>schemasState.snapshot.schemas.at(1); |
|
|
|
|
|
|
|
expect(schema_1.fields[1].isDisabled).toBeFalsy(); |
|
|
|
expectToBeModified(schema_1); |
|
|
|
}); |
|
|
|
|
|
|
|
it('should unmark field disabled and update user info when nested field enabled', () => { |
|
|
|
schemasService.setup(x => x.enableField(app, schema.name, nested2.fieldId, 2, version)) |
|
|
|
.returns(() => of(versioned(newVersion))).verifiable(); |
|
|
|
|
|
|
|
schemasState.enableField(schema, nested2, modified).subscribe(); |
|
|
|
|
|
|
|
const schema_1 = <SchemaDetailsDto>schemasState.snapshot.schemas.at(1); |
|
|
|
|
|
|
|
expect(schema_1.fields[1].nested[1].isDisabled).toBeFalsy(); |
|
|
|
expectToBeModified(schema_1); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
function expectToBeModified(schema_1: SchemaDto) { |
|
|
|
expect(schema_1.lastModified).toEqual(modified); |
|
|
|
expect(schema_1.lastModifiedBy).toEqual(modifier); |
|
|
|
expect(schema_1.version).toEqual(newVersion); |
|
|
|
} |
|
|
|
function expectToBeModified(schema_1: SchemaDto) { |
|
|
|
expect(schema_1.lastModified).toEqual(modified); |
|
|
|
expect(schema_1.lastModifiedBy).toEqual(modifier); |
|
|
|
expect(schema_1.version).toEqual(newVersion); |
|
|
|
} |
|
|
|
}); |
|
|
|
}); |