diff --git a/src/Squidex/app/features/schemas/pages/schema/schema-page.component.ts b/src/Squidex/app/features/schemas/pages/schema/schema-page.component.ts index 3aa62e2ce..d2e01b99a 100644 --- a/src/Squidex/app/features/schemas/pages/schema/schema-page.component.ts +++ b/src/Squidex/app/features/schemas/pages/schema/schema-page.component.ts @@ -129,7 +129,7 @@ export class SchemaPageComponent extends AppComponentBase implements OnInit { this.appNameOnce() .switchMap(app => this.schemasService.enableField(app, this.schema.name, field.fieldId, this.schema.version)).retry(2) .subscribe(() => { - this.updateSchema(this.schema.updateField(this.authService.user.token, field.enable())); + this.updateSchema(this.schema.updateField(field.enable(), this.authService.user.token)); }, error => { this.notifyError(error); }); @@ -139,7 +139,7 @@ export class SchemaPageComponent extends AppComponentBase implements OnInit { this.appNameOnce() .switchMap(app => this.schemasService.disableField(app, this.schema.name, field.fieldId, this.schema.version)).retry(2) .subscribe(() => { - this.updateSchema(this.schema.updateField(this.authService.user.token, field.disable())); + this.updateSchema(this.schema.updateField(field.disable(), this.authService.user.token)); }, error => { this.notifyError(error); }); @@ -149,7 +149,7 @@ export class SchemaPageComponent extends AppComponentBase implements OnInit { this.appNameOnce() .switchMap(app => this.schemasService.showField(app, this.schema.name, field.fieldId, this.schema.version)).retry(2) .subscribe(() => { - this.updateSchema(this.schema.updateField(this.authService.user.token, field.show())); + this.updateSchema(this.schema.updateField(field.show(), this.authService.user.token)); }, error => { this.notifyError(error); }); @@ -159,7 +159,7 @@ export class SchemaPageComponent extends AppComponentBase implements OnInit { this.appNameOnce() .switchMap(app => this.schemasService.hideField(app, this.schema.name, field.fieldId, this.schema.version)).retry(2) .subscribe(() => { - this.updateSchema(this.schema.updateField(this.authService.user.token, field.hide())); + this.updateSchema(this.schema.updateField(field.hide(), this.authService.user.token)); }, error => { this.notifyError(error); }); @@ -169,7 +169,7 @@ export class SchemaPageComponent extends AppComponentBase implements OnInit { this.appNameOnce() .switchMap(app => this.schemasService.deleteField(app, this.schema.name, field.fieldId, this.schema.version)).retry(2) .subscribe(() => { - this.updateSchema(this.schema.removeField(this.authService.user.token, field)); + this.updateSchema(this.schema.removeField(field, this.authService.user.token)); }, error => { this.notifyError(error); }); @@ -179,7 +179,7 @@ export class SchemaPageComponent extends AppComponentBase implements OnInit { this.appNameOnce() .switchMap(app => this.schemasService.putFieldOrdering(app, this.schema.name, fields.map(t => t.fieldId), this.schema.version)).retry(2) .subscribe(() => { - this.updateSchema(this.schema.replaceFields(this.authService.user.token, fields)); + this.updateSchema(this.schema.replaceFields(fields, this.authService.user.token)); }, error => { this.notifyError(error); }); @@ -191,7 +191,7 @@ export class SchemaPageComponent extends AppComponentBase implements OnInit { this.appNameOnce() .switchMap(app => this.schemasService.putField(app, this.schema.name, field.fieldId, requestDto, this.schema.version)).retry(2) .subscribe(() => { - this.updateSchema(this.schema.updateField(this.authService.user.token, field)); + this.updateSchema(this.schema.updateField(field, this.authService.user.token)); }, error => { this.notifyError(error); }); @@ -231,7 +231,7 @@ export class SchemaPageComponent extends AppComponentBase implements OnInit { this.appNameOnce() .switchMap(app => this.schemasService.postField(app, this.schema.name, requestDto, this.schema.version)) .subscribe(dto => { - this.updateSchema(this.schema.addField(this.authService.user.token, dto)); + this.updateSchema(this.schema.addField(dto, this.authService.user.token)); reset(); }, error => { this.notifyError(error); @@ -246,7 +246,7 @@ export class SchemaPageComponent extends AppComponentBase implements OnInit { } public onSchemaSaved(properties: SchemaPropertiesDto) { - this.updateSchema(this.schema.update(this.authService.user.token, properties)); + this.updateSchema(this.schema.update(properties, this.authService.user.token)); this.editSchemaDialog.hide(); } diff --git a/src/Squidex/app/framework/utils/pager.spec.ts b/src/Squidex/app/framework/utils/pager.spec.ts index bc9d08942..28df5c8e9 100644 --- a/src/Squidex/app/framework/utils/pager.spec.ts +++ b/src/Squidex/app/framework/utils/pager.spec.ts @@ -8,7 +8,7 @@ import { Pager } from './../'; describe('Pager', () => { - it('Should init with default values', () => { + it('should init with default values', () => { const pager_1 = new Pager(0); expect(Object.assign({}, pager_1)).toEqual({ @@ -23,7 +23,7 @@ describe('Pager', () => { }); }); - it('Should init with page size and page', () => { + it('should init with page size and page', () => { const pager_1 = new Pager(23, 2, 10); expect(Object.assign({}, pager_1)).toEqual({ @@ -38,7 +38,7 @@ describe('Pager', () => { }); }); - it('Should reset page on reset', () => { + it('should reset page on reset', () => { const pager_1 = new Pager(23, 2, 10); const pager_2 = pager_1.reset(); diff --git a/src/Squidex/app/shared/services/app-clients.service.spec.ts b/src/Squidex/app/shared/services/app-clients.service.spec.ts index 99e439411..e8a3f0805 100644 --- a/src/Squidex/app/shared/services/app-clients.service.spec.ts +++ b/src/Squidex/app/shared/services/app-clients.service.spec.ts @@ -18,6 +18,22 @@ import { Version } from './../'; +describe('AppClientDto', () => { + it('should update name property when renaming', () => { + const client_1 = new AppClientDto('1', 'old-name', 'secret', false); + const client_2 = client_1.rename('new-name'); + + expect(client_2.name).toBe('new-name'); + }); + + it('should update isReader property when changing', () => { + const client_1 = new AppClientDto('1', 'old-name', 'secret', false); + const client_2 = client_1.change(true); + + expect(client_2.isReader).toBeTruthy(); + }); +}); + describe('AppClientsService', () => { let version = new Version('1'); diff --git a/src/Squidex/app/shared/services/app-contributors.service.spec.ts b/src/Squidex/app/shared/services/app-contributors.service.spec.ts index dde363a33..b1f617dc4 100644 --- a/src/Squidex/app/shared/services/app-contributors.service.spec.ts +++ b/src/Squidex/app/shared/services/app-contributors.service.spec.ts @@ -16,6 +16,15 @@ import { Version } from './../'; +describe('AppContributorDto', () => { + it('should update permission property when changing', () => { + const contributor_1 = new AppContributorDto('1', 'Owner'); + const contributor_2 = contributor_1.changePermission('Editor'); + + expect(contributor_2.permission).toBe('Editor'); + }); +}); + describe('AppContributorsService', () => { let version = new Version('1'); diff --git a/src/Squidex/app/shared/services/app-languages.service.spec.ts b/src/Squidex/app/shared/services/app-languages.service.spec.ts index efdad2282..68059cc8d 100644 --- a/src/Squidex/app/shared/services/app-languages.service.spec.ts +++ b/src/Squidex/app/shared/services/app-languages.service.spec.ts @@ -17,6 +17,18 @@ import { Version } from './../'; + +describe('AppLanguageDto', () => { + it('should update properties when updating', () => { + const language_1 = new AppLanguageDto('de', 'English', false, false, []); + const language_2 = language_1.update(true, true, ['de', 'it']); + + expect(language_2.isMaster).toBeTruthy(); + expect(language_2.isOptional).toBeTruthy(); + expect(language_2.fallback).toEqual(['de', 'it']); + }); +}); + describe('AppLanguagesService', () => { let version = new Version('1'); diff --git a/src/Squidex/app/shared/services/assets.service.spec.ts b/src/Squidex/app/shared/services/assets.service.spec.ts index 43a87ce53..54f80e578 100644 --- a/src/Squidex/app/shared/services/assets.service.spec.ts +++ b/src/Squidex/app/shared/services/assets.service.spec.ts @@ -19,6 +19,37 @@ import { Version } from './../'; +describe('AssetDto', () => { + it('should update name property and user info when renaming', () => { + const now = DateTime.now(); + + const asset_1 = new AssetDto('1', 'other', 'other', DateTime.today(), DateTime.today(), 'name', 1, 1, 'image/png', false, 1, 1, null); + const asset_2 = asset_1.rename('new-name', 'me', now); + + expect(asset_2.fileName).toEqual('new-name'); + expect(asset_2.lastModified).toEqual(now); + expect(asset_2.lastModifiedBy).toEqual('me'); + }); + + it('should update file properties when uploading', () => { + const now = DateTime.now(); + + const update = new AssetReplacedDto(2, 2, 'image/jpeg', true, 2, 2, null); + + const asset_1 = new AssetDto('1', 'other', 'other', DateTime.today(), DateTime.today(), 'name', 1, 1, 'image/png', false, 1, 1, null); + const asset_2 = asset_1.update(update, 'me', now); + + expect(asset_2.fileSize).toEqual(2); + expect(asset_2.fileVersion).toEqual(2); + expect(asset_2.mimeType).toEqual('image/jpeg'); + expect(asset_2.isImage).toBeTruthy(); + expect(asset_2.pixelWidth).toEqual(2); + expect(asset_2.pixelHeight).toEqual(2); + expect(asset_2.lastModified).toEqual(now); + expect(asset_2.lastModifiedBy).toEqual('me'); + }); +}); + describe('AssetsService', () => { let now = DateTime.now(); let user = 'me'; diff --git a/src/Squidex/app/shared/services/assets.service.ts b/src/Squidex/app/shared/services/assets.service.ts index b50dec185..4594a3bb5 100644 --- a/src/Squidex/app/shared/services/assets.service.ts +++ b/src/Squidex/app/shared/services/assets.service.ts @@ -42,26 +42,27 @@ export class AssetDto { ) { } - public update(result: AssetReplacedDto, user: string): AssetDto { + public update(update: AssetReplacedDto, user: string, now?: DateTime): AssetDto { return new AssetDto( this.id, this.createdBy, user, - this.created, DateTime.now(), + this.created, now || DateTime.now(), this.fileName, - result.fileSize, - result.fileVersion, - result.mimeType, - result.isImage, - result.pixelWidth, - result.pixelHeight, - result.version) + update.fileSize, + update.fileVersion, + update.mimeType, + update.isImage, + update.pixelWidth, + update.pixelHeight, + update.version) } - public rename(name: string, user: string): AssetDto { + public rename(name: string, user: string, now?: DateTime): AssetDto { return new AssetDto( this.id, this.createdBy, user, - this.created, DateTime.now(), name, + this.created, now || DateTime.now(), + name, this.fileSize, this.fileVersion, this.mimeType, diff --git a/src/Squidex/app/shared/services/contents.service.spec.ts b/src/Squidex/app/shared/services/contents.service.spec.ts index 75ee710da..8e875f384 100644 --- a/src/Squidex/app/shared/services/contents.service.spec.ts +++ b/src/Squidex/app/shared/services/contents.service.spec.ts @@ -17,6 +17,41 @@ import { Version } from './../'; +describe('ContentDto', () => { + it('should update data property and user info when updating', () => { + const now = DateTime.now(); + + const content_1 = new ContentDto('1', false, 'other', 'other', DateTime.now(), DateTime.now(), { data: 1 }, null); + const content_2 = content_1.update({ data: 2 }, 'me', now); + + expect(content_2.data).toEqual({ data: 2 }); + expect(content_2.lastModified).toEqual(now); + expect(content_2.lastModifiedBy).toEqual('me'); + }); + + it('should update isPublished property and user info when publishing', () => { + const now = DateTime.now(); + + const content_1 = new ContentDto('1', false, 'other', 'other', DateTime.now(), DateTime.now(), { data: 1 }, null); + const content_2 = content_1.publish('me', now); + + expect(content_2.isPublished).toBeTruthy(); + expect(content_2.lastModified).toEqual(now); + expect(content_2.lastModifiedBy).toEqual('me'); + }); + + it('should update isPublished property and user info when unpublishing', () => { + const now = DateTime.now(); + + const content_1 = new ContentDto('1', true, 'other', 'other', DateTime.now(), DateTime.now(), { data: 1 }, null); + const content_2 = content_1.unpublish('me', now); + + expect(content_2.isPublished).toBeFalsy(); + expect(content_2.lastModified).toEqual(now); + expect(content_2.lastModifiedBy).toEqual('me'); + }); +}); + describe('ContentsService', () => { let version = new Version('1'); diff --git a/src/Squidex/app/shared/services/contents.service.ts b/src/Squidex/app/shared/services/contents.service.ts index 0d1b192fc..c79014d45 100644 --- a/src/Squidex/app/shared/services/contents.service.ts +++ b/src/Squidex/app/shared/services/contents.service.ts @@ -39,32 +39,32 @@ export class ContentDto { ) { } - public publish(user: string): ContentDto { + public publish(user: string, now?: DateTime): ContentDto { return new ContentDto( this.id, true, this.createdBy, user, - this.created, DateTime.now(), + this.created, now || DateTime.now(), this.data, this.version); } - public unpublish(user: string): ContentDto { + public unpublish(user: string, now?: DateTime): ContentDto { return new ContentDto( this.id, false, this.createdBy, user, - this.created, DateTime.now(), + this.created, now || DateTime.now(), this.data, this.version); } - public update(data: any, user: string): ContentDto { + public update(data: any, user: string, now?: DateTime): ContentDto { return new ContentDto( this.id, this.isPublished, this.createdBy, user, - this.created, DateTime.now(), + this.created, now || DateTime.now(), data, this.version); } diff --git a/src/Squidex/app/shared/services/event-consumers.service.spec.ts b/src/Squidex/app/shared/services/event-consumers.service.spec.ts index 04c9e503d..9b6e0ae69 100644 --- a/src/Squidex/app/shared/services/event-consumers.service.spec.ts +++ b/src/Squidex/app/shared/services/event-consumers.service.spec.ts @@ -14,6 +14,29 @@ import { EventConsumersService } from './../'; +describe('EventConsumerDto', () => { + it('should update isStopped property when starting', () => { + const consumer_1 = new EventConsumerDto('consumer', true, false, 'error', 'position'); + const consumer_2 = consumer_1.start(); + + expect(consumer_2.isStopped).toBeFalsy(); + }); + + it('should update isStopped property when starting', () => { + const consumer_1 = new EventConsumerDto('consumer', false, false, 'error', 'position'); + const consumer_2 = consumer_1.stop(); + + expect(consumer_2.isStopped).toBeTruthy(); + }); + + it('should update isResetting property when resetting', () => { + const consumer_1 = new EventConsumerDto('consumer', false, false, 'error', 'position'); + const consumer_2 = consumer_1.reset(); + + expect(consumer_2.isResetting).toBeTruthy(); + }); +}); + describe('EventConsumersService', () => { beforeEach(() => { TestBed.configureTestingModule({ diff --git a/src/Squidex/app/shared/services/schemas.fields.spec.ts b/src/Squidex/app/shared/services/schemas.fields.spec.ts index 92bf4a9d4..6bdafcf54 100644 --- a/src/Squidex/app/shared/services/schemas.fields.spec.ts +++ b/src/Squidex/app/shared/services/schemas.fields.spec.ts @@ -8,6 +8,7 @@ import { AssetsFieldPropertiesDto, BooleanFieldPropertiesDto, + createProperties, DateTimeFieldPropertiesDto, FieldDto, FieldPropertiesDto, @@ -18,6 +19,45 @@ import { StringFieldPropertiesDto } from './../'; +describe('FieldDto', () => { + it('should update isHidden property when hiding', () => { + const field_1 = createField(createProperties('String')); + const field_2 = field_1.hide(); + + expect(field_2.isHidden).toBeTruthy(); + }); + + it('should update isHidden property when showing', () => { + const field_1 = createField(createProperties('String')).hide(); + const field_2 = field_1.show(); + + expect(field_2.isHidden).toBeFalsy(); + }); + + it('should update isDisabled property when disabling', () => { + const field_1 = createField(createProperties('String')); + const field_2 = field_1.disable(); + + expect(field_2.isDisabled).toBeTruthy(); + }); + + it('should update isDisabled property when enabling', () => { + const field_1 = createField(createProperties('String')).disable(); + const field_2 = field_1.enable(); + + expect(field_2.isDisabled).toBeFalsy(); + }); + + it('should update properties property when updating', () => { + const newProperty = createProperties('Number'); + + const field_1 = createField(createProperties('String')); + const field_2 = field_1.update(newProperty); + + expect(field_2.properties).toEqual(newProperty); + }); +}); + describe('AssetsField', () => { const field = createField(new AssetsFieldPropertiesDto(null, null, null, true, false, 1, 1)); diff --git a/src/Squidex/app/shared/services/schemas.service.spec.ts b/src/Squidex/app/shared/services/schemas.service.spec.ts index c04efe6cd..b3f1f7efa 100644 --- a/src/Squidex/app/shared/services/schemas.service.spec.ts +++ b/src/Squidex/app/shared/services/schemas.service.spec.ts @@ -24,6 +24,141 @@ import { Version } from './../'; +describe('SchemaDto', () => { + const properties = new SchemaPropertiesDto('Name', null); + + it('should update isPublished property and user info when publishing', () => { + const now = DateTime.now(); + + const schema_1 = new SchemaDto('1', 'name', properties, false, 'other', 'other', DateTime.now(), DateTime.now(), null); + const schema_2 = schema_1.publish('me', now); + + expect(schema_2.isPublished).toBeTruthy(); + expect(schema_2.lastModified).toEqual(now); + expect(schema_2.lastModifiedBy).toEqual('me'); + }); + + it('should update isPublished property and user info when unpublishing', () => { + const now = DateTime.now(); + + const schema_1 = new SchemaDto('1', 'name', properties, true, 'other', 'other', DateTime.now(), DateTime.now(), null); + const schema_2 = schema_1.unpublish('me', now); + + expect(schema_2.isPublished).toBeFalsy(); + expect(schema_2.lastModified).toEqual(now); + expect(schema_2.lastModifiedBy).toEqual('me'); + }); + + it('should update properties property and user info when updating', () => { + const newProperties = new SchemaPropertiesDto('New Name', null); + + const now = DateTime.now(); + + const schema_1 = new SchemaDto('1', 'name', properties, false, 'other', 'other', DateTime.now(), DateTime.now(), null); + const schema_2 = schema_1.update(newProperties, 'me', now); + + expect(schema_2.properties).toEqual(newProperties); + expect(schema_2.lastModified).toEqual(now); + expect(schema_2.lastModifiedBy).toEqual('me'); + }); +}); + +describe('SchemaDetailsDto', () => { + const properties = new SchemaPropertiesDto('Name', null); + + it('should update isPublished property and user info when publishing', () => { + const now = DateTime.now(); + + const schema_1 = new SchemaDetailsDto('1', 'name', properties, false, 'other', 'other', DateTime.now(), DateTime.now(), null, []); + const schema_2 = schema_1.publish('me', now); + + expect(schema_2.isPublished).toBeTruthy(); + expect(schema_2.lastModified).toEqual(now); + expect(schema_2.lastModifiedBy).toEqual('me'); + }); + + it('should update isPublished property and user info when unpublishing', () => { + const now = DateTime.now(); + + const schema_1 = new SchemaDetailsDto('1', 'name', properties, true, 'other', 'other', DateTime.now(), DateTime.now(), null, []); + const schema_2 = schema_1.unpublish('me', now); + + expect(schema_2.isPublished).toBeFalsy(); + expect(schema_2.lastModified).toEqual(now); + expect(schema_2.lastModifiedBy).toEqual('me'); + }); + + it('should update properties property and user info when updating', () => { + const newProperties = new SchemaPropertiesDto('New Name', null); + + const now = DateTime.now(); + + const schema_1 = new SchemaDetailsDto('1', 'name', properties, false, 'other', 'other', DateTime.now(), DateTime.now(), null, []); + const schema_2 = schema_1.update(newProperties, 'me', now); + + expect(schema_2.properties).toEqual(newProperties); + expect(schema_2.lastModified).toEqual(now); + expect(schema_2.lastModifiedBy).toEqual('me'); + }); + + it('should update fields property and user info when adding field', () => { + const field1 = new FieldDto(1, '1', false, false, 'l', createProperties('String')); + const field2 = new FieldDto(2, '2', false, false, 'l', createProperties('Number')); + + const now = DateTime.now(); + + const schema_1 = new SchemaDetailsDto('1', 'name', properties, false, 'other', 'other', DateTime.now(), DateTime.now(), null, [field1]); + const schema_2 = schema_1.addField(field2, 'me', now); + + expect(schema_2.fields).toEqual([field1, field2]); + expect(schema_2.lastModified).toEqual(now); + expect(schema_2.lastModifiedBy).toEqual('me'); + }); + + it('should update fields property and user info when removing field', () => { + const field1 = new FieldDto(1, '1', false, false, 'l', createProperties('String')); + const field2 = new FieldDto(2, '2', false, false, 'l', createProperties('Number')); + + const now = DateTime.now(); + + const schema_1 = new SchemaDetailsDto('1', 'name', properties, false, 'other', 'other', DateTime.now(), DateTime.now(), null, [field1, field2]); + const schema_2 = schema_1.removeField(field1, 'me', now); + + expect(schema_2.fields).toEqual([field2]); + expect(schema_2.lastModified).toEqual(now); + expect(schema_2.lastModifiedBy).toEqual('me'); + }); + + it('should update fields property and user info when replacing fields', () => { + const field1 = new FieldDto(1, '1', false, false, 'l', createProperties('String')); + const field2 = new FieldDto(2, '2', false, false, 'l', createProperties('Number')); + + const now = DateTime.now(); + + const schema_1 = new SchemaDetailsDto('1', 'name', properties, false, 'other', 'other', DateTime.now(), DateTime.now(), null, [field1, field2]); + const schema_2 = schema_1.replaceFields([field2, field1], 'me', now); + + expect(schema_2.fields).toEqual([field2, field1]); + expect(schema_2.lastModified).toEqual(now); + expect(schema_2.lastModifiedBy).toEqual('me'); + }); + + it('should update fields property and user info when updatinmg field', () => { + const field1 = new FieldDto(1, '1', false, false, 'l', createProperties('String')); + const field2_1 = new FieldDto(2, '2', false, false, 'l', createProperties('Number')); + const field2_2 = new FieldDto(2, '2', false, false, 'l', createProperties('Boolean')); + + const now = DateTime.now(); + + const schema_1 = new SchemaDetailsDto('1', 'name', properties, false, 'other', 'other', DateTime.now(), DateTime.now(), null, [field1, field2_1]); + const schema_2 = schema_1.updateField(field2_2, 'me', now); + + expect(schema_2.fields).toEqual([field1, field2_2]); + expect(schema_2.lastModified).toEqual(now); + expect(schema_2.lastModifiedBy).toEqual('me'); + }); +}); + describe('SchemasService', () => { let now = DateTime.now(); let user = 'me'; diff --git a/src/Squidex/app/shared/services/schemas.service.ts b/src/Squidex/app/shared/services/schemas.service.ts index 4d3e71421..18d739328 100644 --- a/src/Squidex/app/shared/services/schemas.service.ts +++ b/src/Squidex/app/shared/services/schemas.service.ts @@ -84,36 +84,36 @@ export class SchemaDto { ) { } - public publish(user: string): SchemaDto { + public publish(user: string, now?: DateTime): SchemaDto { return new SchemaDto( this.id, this.name, this.properties, true, this.createdBy, user, - this.created, DateTime.now(), + this.created, now || DateTime.now(), this.version); } - public unpublish(user: string): SchemaDto { + public unpublish(user: string, now?: DateTime): SchemaDto { return new SchemaDto( this.id, this.name, this.properties, false, this.createdBy, user, - this.created, DateTime.now(), + this.created, now || DateTime.now(), this.version); } - public update(user: string, properties: SchemaPropertiesDto): SchemaDto { + public update(properties: SchemaPropertiesDto, user: string, now?: DateTime): SchemaDto { return new SchemaDto( this.id, this.name, properties, this.isPublished, this.createdBy, user, - this.created, DateTime.now(), + this.created, now || DateTime.now(), this.version); } } @@ -125,86 +125,86 @@ export class SchemaDetailsDto extends SchemaDto { super(id, name, properties, isPublished, createdBy, lastModifiedBy, created, lastModified, version); } - public publish(user: string): SchemaDetailsDto { + public publish(user: string, now?: DateTime): SchemaDetailsDto { return new SchemaDetailsDto( this.id, this.name, this.properties, true, this.createdBy, user, - this.created, DateTime.now(), + this.created, now || DateTime.now(), this.version, this.fields); } - public unpublish(user: string): SchemaDetailsDto { + public unpublish(user: string, now?: DateTime): SchemaDetailsDto { return new SchemaDetailsDto( this.id, this.name, this.properties, false, this.createdBy, user, - this.created, DateTime.now(), + this.created, now || DateTime.now(), this.version, this.fields); } - public update(user: string, properties: SchemaPropertiesDto): SchemaDetailsDto { + public update(properties: SchemaPropertiesDto, user: string, now?: DateTime): SchemaDetailsDto { return new SchemaDetailsDto( this.id, this.name, properties, this.isPublished, this.createdBy, user, - this.created, DateTime.now(), + this.created, now || DateTime.now(), this.version, this.fields); } - public addField(user: string, field: FieldDto): SchemaDetailsDto { + public addField(field: FieldDto, user: string, now?: DateTime): SchemaDetailsDto { return new SchemaDetailsDto( this.id, this.name, this.properties, this.isPublished, this.createdBy, user, - this.created, DateTime.now(), + this.created, now || DateTime.now(), this.version, [...this.fields, field]); } - public updateField(user: string, field: FieldDto): SchemaDetailsDto { + public updateField(field: FieldDto, user: string, now?: DateTime): SchemaDetailsDto { return new SchemaDetailsDto( this.id, this.name, this.properties, this.isPublished, this.createdBy, user, - this.created, DateTime.now(), + this.created, now || DateTime.now(), this.version, this.fields.map(f => f.fieldId === field.fieldId ? field : f)); } - public replaceFields(user: string, fields: FieldDto[]): SchemaDetailsDto { + public replaceFields(fields: FieldDto[], user: string, now?: DateTime): SchemaDetailsDto { return new SchemaDetailsDto( this.id, this.name, this.properties, this.isPublished, this.createdBy, user, - this.created, DateTime.now(), + this.created, now || DateTime.now(), this.version, fields); } - public removeField(user: string, field: FieldDto): SchemaDetailsDto { + public removeField(field: FieldDto, user: string, now?: DateTime): SchemaDetailsDto { return new SchemaDetailsDto( this.id, this.name, this.properties, this.isPublished, this.createdBy, user, - this.created, DateTime.now(), + this.created, now || DateTime.now(), this.version, this.fields.filter(f => f.fieldId !== field.fieldId)); } @@ -226,7 +226,7 @@ export class FieldDto { } public hide(): FieldDto { - return new FieldDto(this.fieldId, this.name, false, this.isDisabled, this.partitioning, this.properties); + return new FieldDto(this.fieldId, this.name, true, this.isDisabled, this.partitioning, this.properties); } public enable(): FieldDto { diff --git a/src/Squidex/app/shared/services/users-provider.service.spec.ts b/src/Squidex/app/shared/services/users-provider.service.spec.ts index ba1c62647..0da564166 100644 --- a/src/Squidex/app/shared/services/users-provider.service.spec.ts +++ b/src/Squidex/app/shared/services/users-provider.service.spec.ts @@ -27,7 +27,7 @@ describe('UsersProviderService', () => { usersProviderService = new UsersProviderService(usersService.object, authService.object); }); - it('Should return users service when user not cached', () => { + it('should return users service when user not cached', () => { const user = new UserDto('123', 'mail@domain.com', 'User1', 'path/to/image', true); usersService.setup(x => x.getUser('123')) @@ -44,7 +44,7 @@ describe('UsersProviderService', () => { usersService.verifyAll(); }); - it('Should return provide user from cache', () => { + it('should return provide user from cache', () => { const user = new UserDto('123', 'mail@domain.com', 'User1', 'path/to/image', true); usersService.setup(x => x.getUser('123')) @@ -63,7 +63,7 @@ describe('UsersProviderService', () => { usersService.verifyAll(); }); - it('Should return me when user is current user', () => { + it('should return me when user is current user', () => { const user = new UserDto('123', 'mail@domain.com', 'User1', 'path/to/image', true); authService.setup(x => x.user) @@ -83,7 +83,7 @@ describe('UsersProviderService', () => { usersService.verifyAll(); }); - it('Should return invalid user when not found', () => { + it('should return invalid user when not found', () => { authService.setup(x => x.user) .returns(() => new Profile({ profile: { sub: '123'}})); diff --git a/src/Squidex/app/shared/services/users.service.spec.ts b/src/Squidex/app/shared/services/users.service.spec.ts index 37a072be9..0ffb79c7f 100644 --- a/src/Squidex/app/shared/services/users.service.spec.ts +++ b/src/Squidex/app/shared/services/users.service.spec.ts @@ -18,6 +18,30 @@ import { UsersService } from './../'; +describe('UserDto', () => { + it('should update email and display name property when unlocking', () => { + const user_1 = new UserDto('1', 'sebastian@squidex.io', 'Sebastian', 'picture', true); + const user_2 = user_1.update('qaisar@squidex.io', 'Qaisar'); + + expect(user_2.email).toEqual('qaisar@squidex.io'); + expect(user_2.displayName).toEqual('Qaisar'); + }); + + it('should update isLocked property when locking', () => { + const user_1 = new UserDto('1', 'sebastian@squidex.io', 'Sebastian', 'picture', false); + const user_2 = user_1.lock(); + + expect(user_2.isLocked).toBeTruthy(); + }); + + it('should update isLocked property when unlocking', () => { + const user_1 = new UserDto('1', 'sebastian@squidex.io', 'Sebastian', 'picture', true); + const user_2 = user_1.unlock(); + + expect(user_2.isLocked).toBeFalsy(); + }); +}); + describe('UsersService', () => { beforeEach(() => { TestBed.configureTestingModule({