Browse Source

Rules state

pull/282/head
Sebastian Stehle 8 years ago
parent
commit
c0c296cca3
  1. 8
      src/Squidex/app/features/administration/state/event-consumers.state.spec.ts
  2. 12
      src/Squidex/app/features/administration/state/users.state.spec.ts
  3. 10
      src/Squidex/app/features/rules/pages/rules/rule-wizard.component.html
  4. 60
      src/Squidex/app/features/rules/pages/rules/rule-wizard.component.ts
  5. 22
      src/Squidex/app/features/rules/pages/rules/rules-page.component.html
  6. 92
      src/Squidex/app/features/rules/pages/rules/rules-page.component.ts
  7. 1
      src/Squidex/app/shared/internal.ts
  8. 2
      src/Squidex/app/shared/module.ts
  9. 77
      src/Squidex/app/shared/state/apps.state.spec.ts
  10. 32
      src/Squidex/app/shared/state/assets.state.spec.ts
  11. 6
      src/Squidex/app/shared/state/clients.state.spec.ts
  12. 6
      src/Squidex/app/shared/state/contributors.state.spec.ts
  13. 6
      src/Squidex/app/shared/state/patterns.state.spec.ts
  14. 159
      src/Squidex/app/shared/state/rules.state.spec.ts
  15. 184
      src/Squidex/app/shared/state/rules.state.ts
  16. 40
      src/Squidex/app/shared/state/schemas.state.spec.ts

8
src/Squidex/app/features/administration/state/event-consumers.state.spec.ts

@ -37,6 +37,8 @@ describe('EventConsumersState', () => {
it('should load event consumers', () => { it('should load event consumers', () => {
expect(eventConsumersState.snapshot.eventConsumers.values).toEqual(oldConsumers); expect(eventConsumersState.snapshot.eventConsumers.values).toEqual(oldConsumers);
dialogs.verify(x => x.notifyInfo(It.isAnyString()), Times.never());
}); });
it('should show notification on load when flag is true', () => { it('should show notification on load when flag is true', () => {
@ -63,7 +65,7 @@ describe('EventConsumersState', () => {
dialogs.verify(x => x.notifyError(It.isAny()), Times.never()); dialogs.verify(x => x.notifyError(It.isAny()), Times.never());
}); });
it('should mark consumer as started', () => { it('should unmark as stopped when started', () => {
eventConsumersService.setup(x => x.putStart(oldConsumers[1].name)) eventConsumersService.setup(x => x.putStart(oldConsumers[1].name))
.returns(() => Observable.of({})); .returns(() => Observable.of({}));
@ -74,7 +76,7 @@ describe('EventConsumersState', () => {
expect(es_1.isStopped).toBeFalsy(); expect(es_1.isStopped).toBeFalsy();
}); });
it('should mark consumer as stopped', () => { it('should mark as stopped when stopped', () => {
eventConsumersService.setup(x => x.putStop(oldConsumers[0].name)) eventConsumersService.setup(x => x.putStop(oldConsumers[0].name))
.returns(() => Observable.of({})); .returns(() => Observable.of({}));
@ -85,7 +87,7 @@ describe('EventConsumersState', () => {
expect(es_1.isStopped).toBeTruthy(); expect(es_1.isStopped).toBeTruthy();
}); });
it('should mark consumer as resetting', () => { it('should mark as resetting when reset', () => {
eventConsumersService.setup(x => x.putReset(oldConsumers[0].name)) eventConsumersService.setup(x => x.putReset(oldConsumers[0].name))
.returns(() => Observable.of({})); .returns(() => Observable.of({}));

12
src/Squidex/app/features/administration/state/users.state.spec.ts

@ -54,7 +54,7 @@ describe('UsersState', () => {
expect(usersState.snapshot.users.values).toEqual(oldUsers.map(x => u(x))); expect(usersState.snapshot.users.values).toEqual(oldUsers.map(x => u(x)));
expect(usersState.snapshot.usersPager.numberOfItems).toEqual(200); expect(usersState.snapshot.usersPager.numberOfItems).toEqual(200);
usersService.verifyAll(); dialogs.verify(x => x.notifyInfo(It.isAnyString()), Times.never());
}); });
it('should show notification on load when flag is true', () => { it('should show notification on load when flag is true', () => {
@ -79,7 +79,7 @@ describe('UsersState', () => {
expect(usersState.snapshot.selectedUser).toEqual(u(newUsers[0])); expect(usersState.snapshot.selectedUser).toEqual(u(newUsers[0]));
}); });
it('should not load user on select when already loaded', () => { it('should return user on select and not load when already loaded', () => {
let selectedUser: UserDto; let selectedUser: UserDto;
usersState.select('id1').subscribe(x => { usersState.select('id1').subscribe(x => {
@ -92,7 +92,7 @@ describe('UsersState', () => {
usersService.verify(x => x.getUser(It.isAnyString()), Times.never()); usersService.verify(x => x.getUser(It.isAnyString()), Times.never());
}); });
it('should load user on select when not loaded', () => { it('should return user on select and load when not loaded', () => {
usersService.setup(x => x.getUser('id3')) usersService.setup(x => x.getUser('id3'))
.returns(() => Observable.of(newUser)); .returns(() => Observable.of(newUser));
@ -135,7 +135,7 @@ describe('UsersState', () => {
expect(usersState.snapshot.selectedUser).toBeNull(); expect(usersState.snapshot.selectedUser).toBeNull();
}); });
it('should mark user as locked', () => { it('should mark as locked when locked', () => {
usersService.setup(x => x.lockUser('id1')) usersService.setup(x => x.lockUser('id1'))
.returns(() => Observable.of({})); .returns(() => Observable.of({}));
@ -148,7 +148,7 @@ describe('UsersState', () => {
expect(user_1).toBe(usersState.snapshot.selectedUser); expect(user_1).toBe(usersState.snapshot.selectedUser);
}); });
it('should unmark user as locked', () => { it('should unmark as locked when unlocked', () => {
usersService.setup(x => x.unlockUser('id2')) usersService.setup(x => x.unlockUser('id2'))
.returns(() => Observable.of({})); .returns(() => Observable.of({}));
@ -161,7 +161,7 @@ describe('UsersState', () => {
expect(user_1).toBe(usersState.snapshot.selectedUser); expect(user_1).toBe(usersState.snapshot.selectedUser);
}); });
it('should update user on update', () => { it('should update user properties when updated', () => {
const request = new UpdateUserDto('new@mail.com', 'New'); const request = new UpdateUserDto('new@mail.com', 'New');
usersService.setup(x => x.putUser('id1', request)) usersService.setup(x => x.putUser('id1', request))

10
src/Squidex/app/features/rules/pages/rules/rule-wizard.component.html

@ -1,4 +1,4 @@
<sqx-modal-dialog large="true" fullHeight="true" (closed)="cancel()"> <sqx-modal-dialog large="true" fullHeight="true" (closed)="complete()">
<ng-container title> <ng-container title>
<ng-container *ngIf="mode === 'EditTrigger'"> <ng-container *ngIf="mode === 'EditTrigger'">
Edit Trigger Edit Trigger
@ -44,7 +44,7 @@
</ng-container> </ng-container>
<ng-container *ngSwitchCase="'ContentChanged'"> <ng-container *ngSwitchCase="'ContentChanged'">
<sqx-content-changed-trigger <sqx-content-changed-trigger
[schemas]="schemas" [schemas]="schemas.values"
[trigger]="trigger" [trigger]="trigger"
[triggerForm]="triggerForm.form" [triggerForm]="triggerForm.form"
[triggerFormSubmitted]="triggerForm.submitted | async"> [triggerFormSubmitted]="triggerForm.submitted | async">
@ -118,17 +118,17 @@
<ng-container footer> <ng-container footer>
<div> <div>
<ng-container *ngIf="mode === 'Wizard' && step === 2"> <ng-container *ngIf="mode === 'Wizard' && step === 2">
<button type="reset" class="float-left btn btn-secondary" (click)="cancel()">Cancel</button> <button type="reset" class="float-left btn btn-secondary" (click)="complete()">Cancel</button>
<button type="submit" class="float-right btn btn-primary" (click)="saveTrigger()">Next</button> <button type="submit" class="float-right btn btn-primary" (click)="saveTrigger()">Next</button>
</ng-container> </ng-container>
<ng-container *ngIf="mode !== 'Wizard' && step === 2"> <ng-container *ngIf="mode !== 'Wizard' && step === 2">
<button type="reset" class="float-left btn btn-secondary" (click)="cancel()">Cancel</button> <button type="reset" class="float-left btn btn-secondary" (click)="complete()">Cancel</button>
<button type="submit" class="float-right btn btn-primary" (click)="saveTrigger()">Save</button> <button type="submit" class="float-right btn btn-primary" (click)="saveTrigger()">Save</button>
</ng-container> </ng-container>
<ng-container *ngIf="step === 4"> <ng-container *ngIf="step === 4">
<button type="reset" class="float-left btn btn-secondary" (click)="cancel()">Cancel</button> <button type="reset" class="float-left btn btn-secondary" (click)="complete()">Cancel</button>
<button type="submit" class="float-right btn btn-primary" (click)="saveAction()">Save</button> <button type="submit" class="float-right btn btn-primary" (click)="saveAction()">Save</button>
</ng-container> </ng-container>
</div> </div>

60
src/Squidex/app/features/rules/pages/rules/rule-wizard.component.ts

@ -9,16 +9,14 @@ import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core';
import { FormGroup } from '@angular/forms'; import { FormGroup } from '@angular/forms';
import { import {
AppContext,
CreateRuleDto, CreateRuleDto,
DateTime,
Form, Form,
ImmutableArray,
ruleActions, ruleActions,
ruleTriggers, ruleTriggers,
RuleDto, RuleDto,
RulesService, RulesState,
SchemaDto, SchemaDto
UpdateRuleDto
} from '@app/shared'; } from '@app/shared';
export const MODE_WIZARD = 'Wizard'; export const MODE_WIZARD = 'Wizard';
@ -28,10 +26,7 @@ export const MODE_EDIT_ACTION = 'EditAction';
@Component({ @Component({
selector: 'sqx-rule-wizard', selector: 'sqx-rule-wizard',
styleUrls: ['./rule-wizard.component.scss'], styleUrls: ['./rule-wizard.component.scss'],
templateUrl: './rule-wizard.component.html', templateUrl: './rule-wizard.component.html'
providers: [
AppContext
]
}) })
export class RuleWizardComponent implements OnInit { export class RuleWizardComponent implements OnInit {
public ruleActions = ruleActions; public ruleActions = ruleActions;
@ -48,16 +43,10 @@ export class RuleWizardComponent implements OnInit {
public step = 1; public step = 1;
@Output() @Output()
public cancelled = new EventEmitter(); public completed = new EventEmitter();
@Output()
public created = new EventEmitter<RuleDto>();
@Output()
public updated = new EventEmitter<RuleDto>();
@Input() @Input()
public schemas: SchemaDto[]; public schemas: ImmutableArray<SchemaDto>;
@Input() @Input()
public rule: RuleDto; public rule: RuleDto;
@ -65,8 +54,8 @@ export class RuleWizardComponent implements OnInit {
@Input() @Input()
public mode = MODE_WIZARD; public mode = MODE_WIZARD;
constructor(public readonly ctx: AppContext, constructor(
private readonly rulesService: RulesService private readonly rulesState: RulesState
) { ) {
} }
@ -84,6 +73,10 @@ export class RuleWizardComponent implements OnInit {
} }
} }
public complete() {
this.completed.emit();
}
public selectTriggerType(type: string) { public selectTriggerType(type: string) {
this.triggerType = type; this.triggerType = type;
this.step++; this.step++;
@ -125,40 +118,23 @@ export class RuleWizardComponent implements OnInit {
private createRule() { private createRule() {
const requestDto = new CreateRuleDto(this.trigger, this.action); const requestDto = new CreateRuleDto(this.trigger, this.action);
this.rulesService.postRule(this.ctx.appName, requestDto, this.ctx.userToken, DateTime.now()) this.rulesState.create(requestDto)
.subscribe(dto => { .subscribe(dto => {
this.created.emit(dto); this.complete();
}, error => {
this.ctx.notifyError(error);
}); });
} }
private updateTrigger() { private updateTrigger() {
const requestDto = new UpdateRuleDto(this.trigger, null); this.rulesState.updateTrigger(this.rule, this.trigger)
this.rulesService.putRule(this.ctx.appName, this.rule.id, requestDto, this.rule.version)
.subscribe(dto => { .subscribe(dto => {
const rule = this.rule.updateTrigger(this.trigger, this.ctx.userToken, dto.version, DateTime.now()); this.complete();
this.updated.emit(rule);
}, error => {
this.ctx.notifyError(error);
}); });
} }
private updateAction() { private updateAction() {
const requestDto = new UpdateRuleDto(null, this.action); this.rulesState.updateAction(this.rule, this.action)
this.rulesService.putRule(this.ctx.appName, this.rule.id, requestDto, this.rule.version)
.subscribe(dto => { .subscribe(dto => {
const rule = this.rule.updateAction(this.action, this.ctx.userToken, dto.version, DateTime.now()); this.complete();
this.updated.emit(rule);
}, error => {
this.ctx.notifyError(error);
}); });
} }
public cancel() {
this.cancelled.emit();
}
} }

22
src/Squidex/app/features/rules/pages/rules/rules-page.component.html

@ -1,4 +1,4 @@
<sqx-title message="{app} | Rules" parameter1="app" [value1]="ctx.appName"></sqx-title> <sqx-title message="{app} | Rules" parameter1="app" [value1]="appsState.appName"></sqx-title>
<sqx-panel desiredWidth="54rem" showSidebar="true"> <sqx-panel desiredWidth="54rem" showSidebar="true">
<ng-container title> <ng-container title>
@ -6,11 +6,11 @@
</ng-container> </ng-container>
<ng-container menu> <ng-container menu>
<button class="btn btn-link btn-secondary" (click)="load(true)" title="Refresh Assets (CTRL + SHIFT + R)"> <button class="btn btn-link btn-secondary" (click)="reload()" title="Refresh Assets (CTRL + SHIFT + R)">
<i class="icon-reset"></i> Refresh <i class="icon-reset"></i> Refresh
</button> </button>
<sqx-shortcut keys="ctrl+shift+r" (trigger)="load(true)"></sqx-shortcut> <sqx-shortcut keys="ctrl+shift+r" (trigger)="reload()"></sqx-shortcut>
<sqx-shortcut keys="ctrl+shift+g" (trigger)="buttonNew.click()"></sqx-shortcut> <sqx-shortcut keys="ctrl+shift+g" (trigger)="buttonNew.click()"></sqx-shortcut>
<button class="btn btn-success" #buttonNew (click)="createNew()" title="New Rule (CTRL + M)"> <button class="btn btn-success" #buttonNew (click)="createNew()" title="New Rule (CTRL + M)">
@ -19,7 +19,8 @@
</ng-container> </ng-container>
<ng-container content> <ng-container content>
<div class="table-items-row table-items-row-empty" *ngIf="rules && rules.length === 0"> <ng-container *ngIf="rulesState.rules | async; let rules">
<div class="table-items-row table-items-row-empty" *ngIf="rules.length === 0">
No Rule created yet. No Rule created yet.
<button class="btn btn-success btn-sm ml-2" (click)="createNew()"> <button class="btn btn-success btn-sm ml-2" (click)="createNew()">
@ -27,7 +28,7 @@
</button> </button>
</div> </div>
<table class="table table-items table-fixed" *ngIf="rules && rules.length > 0"> <table class="table table-items table-fixed" *ngIf="rules.length > 0">
<tbody> <tbody>
<ng-template ngFor let-rule [ngForOf]="rules"> <ng-template ngFor let-rule [ngForOf]="rules">
<tr> <tr>
@ -58,11 +59,11 @@
</span> </span>
</td> </td>
<td class="cell-actions"> <td class="cell-actions">
<sqx-toggle [ngModel]="rule.isEnabled" (ngModelChange)="toggleRule(rule)"></sqx-toggle> <sqx-toggle [ngModel]="rule.isEnabled" (ngModelChange)="toggle(rule)"></sqx-toggle>
</td> </td>
<td class="cell-actions"> <td class="cell-actions">
<button type="button" class="btn btn-link btn-danger" <button type="button" class="btn btn-link btn-danger"
(sqxConfirmClick)="deleteRule(rule)" (sqxConfirmClick)="delete(rule)"
confirmTitle="Delete rule" confirmTitle="Delete rule"
confirmText="Do you really want to delete the rule?"> confirmText="Do you really want to delete the rule?">
<i class="icon-bin2"></i> <i class="icon-bin2"></i>
@ -74,6 +75,7 @@
</tbody> </tbody>
</table> </table>
</ng-container> </ng-container>
</ng-container>
<ng-container sidebar> <ng-container sidebar>
<a class="panel-link" routerLink="events" routerLinkActive="active" #linkHistory> <a class="panel-link" routerLink="events" routerLinkActive="active" #linkHistory>
@ -91,10 +93,8 @@
</sqx-panel> </sqx-panel>
<ng-container *sqxModalView="addRuleDialog;onRoot:true;closeAuto:false"> <ng-container *sqxModalView="addRuleDialog;onRoot:true;closeAuto:false">
<sqx-rule-wizard [schemas]="schemas" [rule]="wizardRule" [mode]="wizardMode" <sqx-rule-wizard [schemas]="schemasState.schemas | async" [rule]="wizardRule" [mode]="wizardMode"
(updated)="onRuleUpdated($event)" (completed)="addRuleDialog.hide()">
(cancelled)="addRuleDialog.hide()"
(created)="onRuleCreated($event)">
</sqx-rule-wizard> </sqx-rule-wizard>
</ng-container> </ng-container>

92
src/Squidex/app/features/rules/pages/rules/rules-page.component.ts

@ -8,25 +8,19 @@
import { Component, OnInit } from '@angular/core'; import { Component, OnInit } from '@angular/core';
import { import {
AppContext, AppsState,
DateTime,
ImmutableArray,
ModalView, ModalView,
ruleActions, ruleActions,
ruleTriggers,
RuleDto, RuleDto,
RulesService, RulesState,
SchemaDto, ruleTriggers,
SchemasService SchemasState
} from '@app/shared'; } from '@app/shared';
@Component({ @Component({
selector: 'sqx-rules-page', selector: 'sqx-rules-page',
styleUrls: ['./rules-page.component.scss'], styleUrls: ['./rules-page.component.scss'],
templateUrl: './rules-page.component.html', templateUrl: './rules-page.component.html'
providers: [
AppContext
]
}) })
export class RulesPageComponent implements OnInit { export class RulesPageComponent implements OnInit {
public ruleActions = ruleActions; public ruleActions = ruleActions;
@ -34,35 +28,36 @@ export class RulesPageComponent implements OnInit {
public addRuleDialog = new ModalView(); public addRuleDialog = new ModalView();
public rules: ImmutableArray<RuleDto>;
public schemas: SchemaDto[];
public wizardMode = 'Wizard'; public wizardMode = 'Wizard';
public wizardRule: RuleDto | null; public wizardRule: RuleDto | null;
constructor(public readonly ctx: AppContext, constructor(
private readonly schemasService: SchemasService, public readonly appsState: AppsState,
private readonly rulesService: RulesService public readonly rulesState: RulesState,
public readonly schemasState: SchemasState
) { ) {
} }
public ngOnInit() { public ngOnInit() {
this.load(); this.schemasState.load().onErrorResumeNext().subscribe();
this.rulesState.load().onErrorResumeNext().subscribe();
} }
public load(notifyLoad = false) { public reload() {
this.schemasService.getSchemas(this.ctx.appName) this.rulesState.load(true).onErrorResumeNext().subscribe();
.combineLatest(this.rulesService.getRules(this.ctx.appName), (s, w) => { return { rules: w, schemas: s }; }) }
.subscribe(dtos => {
this.schemas = dtos.schemas;
this.rules = ImmutableArray.of(dtos.rules);
if (notifyLoad) { public delete(rule: RuleDto) {
this.ctx.notifyInfo('Rules reloaded.'); this.rulesState.delete(rule).onErrorResumeNext().subscribe();
}
public toggle(rule: RuleDto) {
if (rule.isEnabled) {
this.rulesState.disable(rule).onErrorResumeNext().subscribe();
} else {
this.rulesState.enable(rule).onErrorResumeNext().subscribe();
} }
}, error => {
this.ctx.notifyError(error);
});
} }
public createNew() { public createNew() {
@ -85,43 +80,4 @@ export class RulesPageComponent implements OnInit {
this.addRuleDialog.show(); this.addRuleDialog.show();
} }
public onRuleUpdated(rule: RuleDto) {
this.rules = this.rules.replaceBy('id', rule);
this.addRuleDialog.hide();
}
public onRuleCreated(rule: RuleDto) {
this.rules = this.rules.push(rule);
this.addRuleDialog.hide();
}
public toggleRule(rule: RuleDto) {
if (rule.isEnabled) {
this.rulesService.disableRule(this.ctx.appName, rule.id, rule.version)
.subscribe(dto => {
this.rules = this.rules.replace(rule, rule.disable(this.ctx.userToken, dto.version, DateTime.now()));
}, error => {
this.ctx.notifyError(error);
});
} else {
this.rulesService.enableRule(this.ctx.appName, rule.id, rule.version)
.subscribe(dto => {
this.rules = this.rules.replace(rule, rule.enable(this.ctx.userToken, dto.version, DateTime.now()));
}, error => {
this.ctx.notifyError(error);
});
}
}
public deleteRule(rule: RuleDto) {
this.rulesService.deleteRule(this.ctx.appName, rule.id, rule.version)
.subscribe(dto => {
this.rules = this.rules.remove(rule);
}, error => {
this.ctx.notifyError(error);
});
}
} }

1
src/Squidex/app/shared/internal.ts

@ -44,6 +44,7 @@ export * from './state/backups.state';
export * from './state/clients.state'; export * from './state/clients.state';
export * from './state/contributors.state'; export * from './state/contributors.state';
export * from './state/patterns.state'; export * from './state/patterns.state';
export * from './state/rules.state';
export * from './state/schemas.state'; export * from './state/schemas.state';
export * from './utils/messages'; export * from './utils/messages';

2
src/Squidex/app/shared/module.ts

@ -55,6 +55,7 @@ import {
ResolveContentGuard, ResolveContentGuard,
RichEditorComponent, RichEditorComponent,
RulesService, RulesService,
RulesState,
SchemaMustExistGuard, SchemaMustExistGuard,
SchemaMustExistPublishedGuard, SchemaMustExistPublishedGuard,
SchemasService, SchemasService,
@ -157,6 +158,7 @@ export class SqxSharedModule {
ResolveAppLanguagesGuard, ResolveAppLanguagesGuard,
ResolveContentGuard, ResolveContentGuard,
RulesService, RulesService,
RulesState,
SchemaMustExistGuard, SchemaMustExistGuard,
SchemaMustExistPublishedGuard, SchemaMustExistPublishedGuard,
SchemasService, SchemasService,

77
src/Squidex/app/shared/state/apps.state.spec.ts

@ -46,47 +46,6 @@ describe('AppsState', () => {
it('should load apps', () => { it('should load apps', () => {
expect(appsState.snapshot.apps.values).toEqual(oldApps); expect(appsState.snapshot.apps.values).toEqual(oldApps);
appsService.verifyAll();
});
it('should add app to state when created', () => {
const request = new CreateAppDto(newApp.name);
appsService.setup(x => x.postApp(request))
.returns(() => Observable.of(newApp))
.verifiable(Times.once());
appsState.create(request, now).subscribe();
expect(appsState.snapshot.apps.values).toEqual([newApp, ...oldApps]);
appsService.verifyAll();
});
it('should remove app from state when archived', () => {
const request = new CreateAppDto(newApp.name);
appsService.setup(x => x.postApp(request))
.returns(() => Observable.of(newApp))
.verifiable(Times.once());
appsService.setup(x => x.deleteApp(newApp.name))
.returns(() => Observable.of({}))
.verifiable(Times.once());
appsState.create(request, now).subscribe();
const appsAfterCreate = appsState.snapshot.apps.values;
appsState.delete(newApp.name).subscribe();
const appsAfterDelete = appsState.snapshot.apps.values;
expect(appsAfterCreate).toEqual([newApp, ...oldApps]);
expect(appsAfterDelete).toEqual(oldApps);
appsService.verifyAll();
}); });
it('should select app', () => { it('should select app', () => {
@ -100,7 +59,7 @@ describe('AppsState', () => {
expect(appsState.snapshot.selectedApp).toBe(oldApps[0]); expect(appsState.snapshot.selectedApp).toBe(oldApps[0]);
}); });
it('should return null when unselecting app', () => { it('should return null on select when unselecting user', () => {
let selectedApp: AppDto; let selectedApp: AppDto;
appsState.select(null).subscribe(x => { appsState.select(null).subscribe(x => {
@ -111,7 +70,7 @@ describe('AppsState', () => {
expect(appsState.snapshot.selectedApp).toBeNull(); expect(appsState.snapshot.selectedApp).toBeNull();
}); });
it('should return null when app to select is not found', () => { it('should return null on select when apps is not found', () => {
let selectedApp: AppDto; let selectedApp: AppDto;
appsState.select('unknown').subscribe(x => { appsState.select('unknown').subscribe(x => {
@ -121,4 +80,36 @@ describe('AppsState', () => {
expect(selectedApp!).toBeNull(); expect(selectedApp!).toBeNull();
expect(appsState.snapshot.selectedApp).toBeNull(); expect(appsState.snapshot.selectedApp).toBeNull();
}); });
it('should add app to snapshot when created', () => {
const request = new CreateAppDto(newApp.name);
appsService.setup(x => x.postApp(request))
.returns(() => Observable.of(newApp));
appsState.create(request, now).subscribe();
expect(appsState.snapshot.apps.values).toEqual([newApp, ...oldApps]);
});
it('should remove app from snashot when archived', () => {
const request = new CreateAppDto(newApp.name);
appsService.setup(x => x.postApp(request))
.returns(() => Observable.of(newApp));
appsService.setup(x => x.deleteApp(newApp.name))
.returns(() => Observable.of({}));
appsState.create(request, now).subscribe();
const appsAfterCreate = appsState.snapshot.apps.values;
appsState.delete(newApp.name).subscribe();
const appsAfterDelete = appsState.snapshot.apps.values;
expect(appsAfterCreate).toEqual([newApp, ...oldApps]);
expect(appsAfterDelete).toEqual(oldApps);
});
}); });

32
src/Squidex/app/shared/state/assets.state.spec.ts

@ -63,24 +63,28 @@ describe('AssetsState', () => {
expect(assetsState.snapshot.assetsPager.numberOfItems).toEqual(200); expect(assetsState.snapshot.assetsPager.numberOfItems).toEqual(200);
assetsService.verify(x => x.getAssets(app, 30, 0, undefined), Times.exactly(2)); assetsService.verify(x => x.getAssets(app, 30, 0, undefined), Times.exactly(2));
dialogs.verify(x => x.notifyInfo(It.isAnyString()), Times.never());
}); });
it('should not reload when assets assets already loaded', () => { it('should not reload when assets already loaded', () => {
assetsState.load(false, true).subscribe(); assetsState.load(false, true).subscribe();
expect(assetsState.snapshot.assets.values).toEqual(oldAssets); expect(assetsState.snapshot.assets.values).toEqual(oldAssets);
expect(assetsState.snapshot.assetsPager.numberOfItems).toEqual(200); expect(assetsState.snapshot.assetsPager.numberOfItems).toEqual(200);
assetsService.verify(x => x.getAssets(app, 30, 0, undefined), Times.once()); assetsService.verify(x => x.getAssets(app, 30, 0, undefined), Times.once());
dialogs.verify(x => x.notifyInfo(It.isAnyString()), Times.never());
}); });
it('should raise notification on load when notify is true', () => { it('should show notification on load when flag is true', () => {
assetsState.load(true).subscribe(); assetsState.load(true).subscribe();
dialogs.verify(x => x.notifyInfo(It.isAnyString()), Times.once()); dialogs.verify(x => x.notifyInfo(It.isAnyString()), Times.once());
}); });
it('should add asset to snapshot', () => { it('should add asset to snapshot when created', () => {
const newAsset = new AssetDto('id3', creator, creator, creation, creation, 'name3', 'type3', 3, 3, 'mime3', true, 0, 0, 'url3', version); const newAsset = new AssetDto('id3', creator, creator, creation, creation, 'name3', 'type3', 3, 3, 'mime3', true, 0, 0, 'url3', version);
assetsState.add(newAsset); assetsState.add(newAsset);
@ -89,7 +93,7 @@ describe('AssetsState', () => {
expect(assetsState.snapshot.assetsPager.numberOfItems).toBe(201); expect(assetsState.snapshot.assetsPager.numberOfItems).toBe(201);
}); });
it('should update asset in snapshot', () => { it('should update properties when updated', () => {
const newAsset = new AssetDto('id1', modifier, modifier, modified, modified, 'name3', 'type3', 3, 3, 'mime3', true, 0, 0, 'url3', version); const newAsset = new AssetDto('id1', modifier, modifier, modified, modified, 'name3', 'type3', 3, 3, 'mime3', true, 0, 0, 'url3', version);
assetsState.update(newAsset); assetsState.update(newAsset);
@ -99,6 +103,16 @@ describe('AssetsState', () => {
expect(asset_1).toBe(newAsset); expect(asset_1).toBe(newAsset);
}); });
it('should remove asset from snapshot when deleted', () => {
assetsService.setup(x => x.deleteAsset(app, oldAssets[0].id, version))
.returns(() => Observable.of(new Versioned<any>(newVersion, {})));
assetsState.delete(oldAssets[0]).subscribe();
expect(assetsState.snapshot.assets.values.length).toBe(1);
expect(assetsState.snapshot.assetsPager.numberOfItems).toBe(199);
});
it('should load next page and prev page when paging', () => { it('should load next page and prev page when paging', () => {
assetsService.setup(x => x.getAssets(app, 30, 30, undefined)) assetsService.setup(x => x.getAssets(app, 30, 30, undefined))
.returns(() => Observable.of(new AssetsDto(200, []))); .returns(() => Observable.of(new AssetsDto(200, [])));
@ -120,14 +134,4 @@ describe('AssetsState', () => {
assetsService.verify(x => x.getAssets(app, 30, 0, 'my-query'), Times.once()); assetsService.verify(x => x.getAssets(app, 30, 0, 'my-query'), Times.once());
}); });
it('should remove asset when deleted', () => {
assetsService.setup(x => x.deleteAsset(app, oldAssets[0].id, version))
.returns(() => Observable.of(new Versioned<any>(newVersion, {})));
assetsState.delete(oldAssets[0]).subscribe();
expect(assetsState.snapshot.assets.values.length).toBe(1);
expect(assetsState.snapshot.assetsPager.numberOfItems).toBe(199);
});
}); });

6
src/Squidex/app/shared/state/clients.state.spec.ts

@ -59,7 +59,7 @@ describe('ClientsState', () => {
expect(clientsState.snapshot.version).toEqual(version); expect(clientsState.snapshot.version).toEqual(version);
}); });
it('should add client to snapshot', () => { it('should add client to snapshot when created', () => {
const newClient = new AppClientDto('id3', 'name3', 'secret3', 'Developer'); const newClient = new AppClientDto('id3', 'name3', 'secret3', 'Developer');
const request = new CreateAppClientDto('id3'); const request = new CreateAppClientDto('id3');
@ -73,7 +73,7 @@ describe('ClientsState', () => {
expect(clientsState.snapshot.version).toEqual(newVersion); expect(clientsState.snapshot.version).toEqual(newVersion);
}); });
it('should update client in snapshot', () => { it('should update properties when updated', () => {
const request = new UpdateAppClientDto('NewName', 'NewPermission'); const request = new UpdateAppClientDto('NewName', 'NewPermission');
clientsService.setup(x => x.putClient(app, oldClients[0].id, request, version)) clientsService.setup(x => x.putClient(app, oldClients[0].id, request, version))
@ -88,7 +88,7 @@ describe('ClientsState', () => {
expect(clientsState.snapshot.version).toEqual(newVersion); expect(clientsState.snapshot.version).toEqual(newVersion);
}); });
it('should remove client from snapshot', () => { it('should remove client from snapshot when revoked', () => {
clientsService.setup(x => x.deleteClient(app, oldClients[0].id, version)) clientsService.setup(x => x.deleteClient(app, oldClients[0].id, version))
.returns(() => Observable.of(new Versioned<any>(newVersion, {}))); .returns(() => Observable.of(new Versioned<any>(newVersion, {})));

6
src/Squidex/app/shared/state/contributors.state.spec.ts

@ -66,7 +66,7 @@ describe('ContributorsState', () => {
expect(contributorsState.snapshot.version).toEqual(version); expect(contributorsState.snapshot.version).toEqual(version);
}); });
it('should add contributor to snapshot', () => { it('should add contributor to snapshot when assigned', () => {
const newContributor = new AppContributorDto('id3', 'Developer'); const newContributor = new AppContributorDto('id3', 'Developer');
const request = new AppContributorDto('mail2stehle@gmail.com', 'Developer'); const request = new AppContributorDto('mail2stehle@gmail.com', 'Developer');
@ -83,7 +83,7 @@ describe('ContributorsState', () => {
expect(contributorsState.snapshot.version).toEqual(newVersion); expect(contributorsState.snapshot.version).toEqual(newVersion);
}); });
it('should update contributor in snapshot', () => { it('should update contributor in snapshot when assigned and already added', () => {
const newContributor = new AppContributorDto('id2', 'Owner'); const newContributor = new AppContributorDto('id2', 'Owner');
const request = new AppContributorDto('mail2stehle@gmail.com', 'Owner'); const request = new AppContributorDto('mail2stehle@gmail.com', 'Owner');
@ -100,7 +100,7 @@ describe('ContributorsState', () => {
expect(contributorsState.snapshot.version).toEqual(newVersion); expect(contributorsState.snapshot.version).toEqual(newVersion);
}); });
it('should remove contributor from snapshot', () => { it('should remove contributor from snapshot when revoked', () => {
contributorsService.setup(x => x.deleteContributor(app, oldContributors[0].contributorId, version)) contributorsService.setup(x => x.deleteContributor(app, oldContributors[0].contributorId, version))
.returns(() => Observable.of(new Versioned<any>(newVersion, {}))); .returns(() => Observable.of(new Versioned<any>(newVersion, {})));

6
src/Squidex/app/shared/state/patterns.state.spec.ts

@ -57,7 +57,7 @@ describe('PatternsState', () => {
expect(patternsState.snapshot.version).toEqual(version); expect(patternsState.snapshot.version).toEqual(version);
}); });
it('should add pattern to snapshot', () => { it('should add pattern to snapshot when created', () => {
const newPattern = new AppPatternDto('id3', 'name3', 'pattern3', ''); const newPattern = new AppPatternDto('id3', 'name3', 'pattern3', '');
const request = new EditAppPatternDto('name3', 'pattern3', ''); const request = new EditAppPatternDto('name3', 'pattern3', '');
@ -71,7 +71,7 @@ describe('PatternsState', () => {
expect(patternsState.snapshot.version).toEqual(newVersion); expect(patternsState.snapshot.version).toEqual(newVersion);
}); });
it('should update pattern in snapshot', () => { it('should update properties when updated', () => {
const request = new EditAppPatternDto('a_name2', 'a_pattern2', 'a_message2'); const request = new EditAppPatternDto('a_name2', 'a_pattern2', 'a_message2');
patternsService.setup(x => x.putPattern(app, oldPatterns[1].id, request, version)) patternsService.setup(x => x.putPattern(app, oldPatterns[1].id, request, version))
@ -87,7 +87,7 @@ describe('PatternsState', () => {
expect(patternsState.snapshot.version).toEqual(newVersion); expect(patternsState.snapshot.version).toEqual(newVersion);
}); });
it('should remove pattern from snapshot', () => { it('should remove pattern from snapshot when deleted', () => {
patternsService.setup(x => x.deletePattern(app, oldPatterns[0].id, version)) patternsService.setup(x => x.deletePattern(app, oldPatterns[0].id, version))
.returns(() => Observable.of(new Versioned<any>(newVersion, {}))); .returns(() => Observable.of(new Versioned<any>(newVersion, {})));

159
src/Squidex/app/shared/state/rules.state.spec.ts

@ -0,0 +1,159 @@
/*
* Squidex Headless CMS
*
* @license
* Copyright (c) Squidex UG (haftungsbeschränkt). All rights reserved.
*/
import { Observable } from 'rxjs';
import { IMock, It, Mock, Times } from 'typemoq';
import { RulesState } from './rules.state';
import {
AppsState,
AuthService,
DialogService,
DateTime,
RuleDto,
RulesService,
Version,
Versioned,
CreateRuleDto,
UpdateRuleDto
} from '@app/shared';
describe('RulesState', () => {
const app = 'my-app';
const creation = DateTime.today();
const creator = 'not-me';
const modified = DateTime.now();
const modifier = 'me';
const version = new Version('1');
const newVersion = new Version('2');
const oldRules = [
new RuleDto('id1', creator, creator, creation, creation, version, false, {}, 'trigger1', {}, 'action1'),
new RuleDto('id2', creator, creator, creation, creation, version, true, {}, 'trigger2', {}, 'action2')
];
let dialogs: IMock<DialogService>;
let appsState: IMock<AppsState>;
let authService: IMock<AuthService>;
let rulesService: IMock<RulesService>;
let rulesState: RulesState;
beforeEach(() => {
dialogs = Mock.ofType<DialogService>();
authService = Mock.ofType<AuthService>();
authService.setup(x => x.user)
.returns(() => <any>{ id: '1', token: modifier });
appsState = Mock.ofType<AppsState>();
appsState.setup(x => x.appName)
.returns(() => app);
rulesService = Mock.ofType<RulesService>();
rulesService.setup(x => x.getRules(app))
.returns(() => Observable.of(oldRules));
rulesState = new RulesState(appsState.object, authService.object, dialogs.object, rulesService.object);
rulesState.load().subscribe();
});
it('should load rules', () => {
expect(rulesState.snapshot.rules.values).toEqual(oldRules);
dialogs.verify(x => x.notifyInfo(It.isAnyString()), Times.never());
});
it('should show notification on load when flag is true', () => {
rulesState.load(true).subscribe();
dialogs.verify(x => x.notifyInfo(It.isAnyString()), Times.once());
});
it('should add rule to snapshot when created', () => {
const newRule = new RuleDto('id3', creator, creator, creation, creation, version, false, {}, 'trigger3', {}, 'action3');
const request = new CreateRuleDto({}, {});
rulesService.setup(x => x.postRule(app, request, modifier, creation))
.returns(() => Observable.of(newRule));
rulesState.create(request, creation).subscribe();
expect(rulesState.snapshot.rules.values).toEqual([...oldRules, newRule]);
});
it('should update action and update and user info when updated action', () => {
const newAction = {};
rulesService.setup(x => x.putRule(app, oldRules[0].id, It.is<UpdateRuleDto>(i => true), version))
.returns(() => Observable.of(new Versioned<any>(newVersion, {})));
rulesState.updateAction(oldRules[0], newAction, modified).subscribe();
const rule_1 = rulesState.snapshot.rules.at(0);
expect(rule_1.action).toBe(newAction);
expectToBeModified(rule_1);
});
it('should update trigger and update and user info when updated trigger', () => {
const newTrigger = {};
rulesService.setup(x => x.putRule(app, oldRules[0].id, It.is<UpdateRuleDto>(i => true), version))
.returns(() => Observable.of(new Versioned<any>(newVersion, {})));
rulesState.updateTrigger(oldRules[0], newTrigger, modified).subscribe();
const rule_1 = rulesState.snapshot.rules.at(0);
expect(rule_1.trigger).toBe(newTrigger);
expectToBeModified(rule_1);
});
it('should mark as enabled and update and user info when enabled', () => {
rulesService.setup(x => x.enableRule(app, oldRules[0].id, version))
.returns(() => Observable.of(new Versioned<any>(newVersion, {})));
rulesState.enable(oldRules[0], modified).subscribe();
const rule_1 = rulesState.snapshot.rules.at(0);
expect(rule_1.isEnabled).toBeTruthy();
expectToBeModified(rule_1);
});
it('should mark as disabled and update and user info when disabled', () => {
rulesService.setup(x => x.disableRule(app, oldRules[1].id, version))
.returns(() => Observable.of(new Versioned<any>(newVersion, {})));
rulesState.disable(oldRules[1], modified).subscribe();
const rule_1 = rulesState.snapshot.rules.at(1);
expect(rule_1.isEnabled).toBeFalsy();
expectToBeModified(rule_1);
});
it('should remove rule from snapshot when deleted', () => {
rulesService.setup(x => x.deleteRule(app, oldRules[0].id, version))
.returns(() => Observable.of(new Versioned<any>(newVersion, {})));
rulesState.delete(oldRules[0]).subscribe();
expect(rulesState.snapshot.rules.values).toEqual([oldRules[1]]);
});
function expectToBeModified(rule_1: RuleDto) {
expect(rule_1.lastModified).toEqual(modified);
expect(rule_1.lastModifiedBy).toEqual(modifier);
expect(rule_1.version).toEqual(newVersion);
}
});

184
src/Squidex/app/shared/state/rules.state.ts

@ -0,0 +1,184 @@
/*
* Squidex Headless CMS
*
* @license
* Copyright (c) Squidex UG (haftungsbeschränkt). All rights reserved.
*/
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';
import '@app/framework/utils/rxjs-extensions';
import {
DialogService,
ImmutableArray,
State,
Version,
DateTime
} from '@app/framework';
import { AppsState } from './apps.state';
import { AuthService} from './../services/auth.service';
import {
CreateRuleDto,
RuleDto,
RulesService,
UpdateRuleDto
} from './../services/rules.service';
interface Snapshot {
rules: ImmutableArray<RuleDto>;
}
@Injectable()
export class RulesState extends State<Snapshot> {
public rules =
this.changes.map(x => x.rules);
constructor(
private readonly appsState: AppsState,
private readonly authState: AuthService,
private readonly dialogs: DialogService,
private readonly rulesService: RulesService
) {
super({ rules: ImmutableArray.empty() });
}
public load(notifyLoad = false): Observable<any> {
return this.rulesService.getRules(this.appName)
.do(dtos => {
if (notifyLoad) {
this.dialogs.notifyInfo('Rules reloaded.');
}
this.next(s => {
const rules = ImmutableArray.of(dtos);
return { ...s, rules };
});
})
.notify(this.dialogs);
}
public create(request: CreateRuleDto, now?: DateTime): Observable<any> {
return this.rulesService.postRule(this.appName, request, this.user, now || DateTime.now())
.do(dto => {
this.next(s => {
const rules = s.rules.push(dto);
return { ...s, rules };
});
})
.notify(this.dialogs);
}
public delete(rule: RuleDto): Observable<any> {
return this.rulesService.deleteRule(this.appName, rule.id, rule.version)
.do(dto => {
this.next(s => {
const rules = s.rules.removeAll(x => x.id === rule.id);
return { ...s, rules };
});
})
.notify(this.dialogs);
}
public updateAction(rule: RuleDto, action: any, now?: DateTime): Observable<any> {
return this.rulesService.putRule(this.appName, rule.id, new UpdateRuleDto(null, action), rule.version)
.do(dto => {
this.replaceRule(updateAction(rule, action, this.user, dto.version, now));
})
.notify(this.dialogs);
}
public updateTrigger(rule: RuleDto, trigger: any, now?: DateTime): Observable<any> {
return this.rulesService.putRule(this.appName, rule.id, new UpdateRuleDto(trigger, null), rule.version)
.do(dto => {
this.replaceRule(updateTrigger(rule, trigger, this.user, dto.version, now));
})
.notify(this.dialogs);
}
public enable(rule: RuleDto, now?: DateTime): Observable<any> {
return this.rulesService.enableRule(this.appName, rule.id, rule.version)
.do(dto => {
this.replaceRule(enable(rule, this.user, dto.version, now));
})
.notify(this.dialogs);
}
public disable(rule: RuleDto, now?: DateTime): Observable<any> {
return this.rulesService.disableRule(this.appName, rule.id, rule.version)
.do(dto => {
this.replaceRule(disable(rule, this.user, dto.version, now));
})
.notify(this.dialogs);
}
private replaceRule(rule: RuleDto) {
this.next(s => {
const rules = s.rules.replaceBy('id', rule);
return { ...s, rules };
});
}
private get appName() {
return this.appsState.appName;
}
private get user() {
return this.authState.user!.token;
}
}
const updateTrigger = (rule: RuleDto, trigger: any, user: string, version: Version, now?: DateTime) =>
new RuleDto(
rule.id,
rule.createdBy, user,
rule.created, now || DateTime.now(),
version,
rule.isEnabled,
trigger,
trigger.triggerType,
rule.action,
rule.action.actionType);
const updateAction = (rule: RuleDto, action: any, user: string, version: Version, now?: DateTime) =>
new RuleDto(
rule.id,
rule.createdBy, user,
rule.created, now || DateTime.now(),
version,
rule.isEnabled,
rule.trigger,
rule.trigger.triggerType,
action,
action.actionType);
const enable = (rule: RuleDto, user: string, version: Version, now?: DateTime) =>
new RuleDto(
rule.id,
rule.createdBy, user,
rule.created, now || DateTime.now(),
version,
true,
rule.trigger,
rule.triggerType,
rule.action,
rule.actionType);
const disable = (rule: RuleDto, user: string, version: Version, now?: DateTime) =>
new RuleDto(
rule.id,
rule.createdBy, user,
rule.created, now || DateTime.now(),
version,
false,
rule.trigger,
rule.triggerType,
rule.action,
rule.actionType);

40
src/Squidex/app/shared/state/schemas.state.spec.ts

@ -93,14 +93,14 @@ describe('SchemasState', () => {
schemasService.verifyAll(); schemasService.verifyAll();
}); });
it('should reload schema when already loaded', () => { it('should return schema on select and reload when already loaded', () => {
schemasState.select('name2').subscribe(); schemasState.select('name2').subscribe();
schemasState.select('name2').subscribe(); schemasState.select('name2').subscribe();
schemasService.verify(x => x.getSchema(app, 'name2'), Times.exactly(2)); schemasService.verify(x => x.getSchema(app, 'name2'), Times.exactly(2));
}); });
it('should load selected schema when not loaded', () => { it('should return schema on select and load when not loaded', () => {
let selectedSchema: SchemaDetailsDto; let selectedSchema: SchemaDetailsDto;
schemasState.select('name2').subscribe(x => { schemasState.select('name2').subscribe(x => {
@ -112,7 +112,7 @@ describe('SchemasState', () => {
expect(schemasState.snapshot.selectedSchema).toBe(schemasState.snapshot.schemas.at(1)); expect(schemasState.snapshot.selectedSchema).toBe(schemasState.snapshot.schemas.at(1));
}); });
it('should return null when loading failed', () => { it('should return null on select when loading failed', () => {
schemasService.setup(x => x.getSchema(app, 'failed')) schemasService.setup(x => x.getSchema(app, 'failed'))
.returns(() => Observable.throw({})); .returns(() => Observable.throw({}));
@ -126,7 +126,7 @@ describe('SchemasState', () => {
expect(schemasState.snapshot.selectedSchema).toBeNull(); expect(schemasState.snapshot.selectedSchema).toBeNull();
}); });
it('should return null when unselecting schema', () => { it('should return null on select when unselecting schema', () => {
let selectedSchema: SchemaDetailsDto; let selectedSchema: SchemaDetailsDto;
schemasState.select(null).subscribe(x => { schemasState.select(null).subscribe(x => {
@ -139,7 +139,7 @@ describe('SchemasState', () => {
schemasService.verify(x => x.getSchema(app, It.isAnyString()), Times.never()); schemasService.verify(x => x.getSchema(app, It.isAnyString()), Times.never());
}); });
it('should update isPublished property and user info when publishing', () => { it('should mark published and update user info when published', () => {
schemasService.setup(x => x.publishSchema(app, oldSchemas[0].name, version)) schemasService.setup(x => x.publishSchema(app, oldSchemas[0].name, version))
.returns(() => Observable.of(new Versioned<any>(newVersion, {}))); .returns(() => Observable.of(new Versioned<any>(newVersion, {})));
@ -151,7 +151,7 @@ describe('SchemasState', () => {
expectToBeModified(schema_1); expectToBeModified(schema_1);
}); });
it('should update isPublished property and user info when unpublishing', () => { it('should unmark published and update user info when unpublished', () => {
schemasService.setup(x => x.unpublishSchema(app, oldSchemas[1].name, version)) schemasService.setup(x => x.unpublishSchema(app, oldSchemas[1].name, version))
.returns(() => Observable.of(new Versioned<any>(newVersion, {}))); .returns(() => Observable.of(new Versioned<any>(newVersion, {})));
@ -168,7 +168,7 @@ describe('SchemasState', () => {
schemasState.select(schema.name).subscribe(); schemasState.select(schema.name).subscribe();
}); });
it('should update isPublished property and user info when publishing selected schema', () => { it('should unmark published and update user info when published selected schema', () => {
schemasService.setup(x => x.publishSchema(app, schema.name, version)) schemasService.setup(x => x.publishSchema(app, schema.name, version))
.returns(() => Observable.of(new Versioned<any>(newVersion, {}))); .returns(() => Observable.of(new Versioned<any>(newVersion, {})));
@ -180,7 +180,7 @@ describe('SchemasState', () => {
expectToBeModified(schema_1); expectToBeModified(schema_1);
}); });
it('should update properties property and user info when updating', () => { it('should update properties and update user info when updated', () => {
const request = new UpdateSchemaDto('name2_label', 'name2_hints'); const request = new UpdateSchemaDto('name2_label', 'name2_hints');
schemasService.setup(x => x.putSchema(app, schema.name, It.isAny(), version)) schemasService.setup(x => x.putSchema(app, schema.name, It.isAny(), version))
@ -195,7 +195,7 @@ describe('SchemasState', () => {
expectToBeModified(schema_1); expectToBeModified(schema_1);
}); });
it('should update script properties and user info when updating', () => { it('should update script properties and update user info when scripts configured', () => {
const request = new UpdateSchemaScriptsDto('query', 'create', 'update', 'delete', 'change'); const request = new UpdateSchemaScriptsDto('query', 'create', 'update', 'delete', 'change');
schemasService.setup(x => x.putSchemaScripts(app, schema.name, It.isAny(), version)) schemasService.setup(x => x.putSchemaScripts(app, schema.name, It.isAny(), version))
@ -213,7 +213,7 @@ describe('SchemasState', () => {
expectToBeModified(schema_1); expectToBeModified(schema_1);
}); });
it('should add schema when created', () => { it('should add schema to snapshot when created', () => {
const request = new CreateSchemaDto('newName'); const request = new CreateSchemaDto('newName');
const result = new SchemaDetailsDto('id4', 'newName', {}, false, modifier, modifier, modified, modified, version, []); const result = new SchemaDetailsDto('id4', 'newName', {}, false, modifier, modifier, modified, modified, version, []);
@ -227,7 +227,7 @@ describe('SchemasState', () => {
expect(schemasState.snapshot.schemas.at(2)).toBe(result); expect(schemasState.snapshot.schemas.at(2)).toBe(result);
}); });
it('should remove schema when deleted', () => { it('should remove schema from snapshot when deleted', () => {
schemasService.setup(x => x.deleteSchema(app, schema.name, version)) schemasService.setup(x => x.deleteSchema(app, schema.name, version))
.returns(() => Observable.of(new Versioned<any>(newVersion, {}))); .returns(() => Observable.of(new Versioned<any>(newVersion, {})));
@ -237,7 +237,7 @@ describe('SchemasState', () => {
expect(schemasState.snapshot.selectedSchema).toBeNull(); expect(schemasState.snapshot.selectedSchema).toBeNull();
}); });
it('should update fields property and user info when adding field', () => { it('should add field and update user info when field added', () => {
const request = new AddFieldDto(field1.name, field1.partitioning, field1.properties); const request = new AddFieldDto(field1.name, field1.partitioning, field1.properties);
const newField = new FieldDto(3, '3', false, false, false, 'l', createProperties('String')); const newField = new FieldDto(3, '3', false, false, false, 'l', createProperties('String'));
@ -253,7 +253,7 @@ describe('SchemasState', () => {
expectToBeModified(schema_1); expectToBeModified(schema_1);
}); });
it('should update fields property and user info when removing field', () => { it('should remove field and update user info when field removed', () => {
schemasService.setup(x => x.deleteField(app, schema.name, field1.fieldId, version)) schemasService.setup(x => x.deleteField(app, schema.name, field1.fieldId, version))
.returns(() => Observable.of(new Versioned<any>(newVersion, {}))); .returns(() => Observable.of(new Versioned<any>(newVersion, {})));
@ -265,7 +265,7 @@ describe('SchemasState', () => {
expectToBeModified(schema_1); expectToBeModified(schema_1);
}); });
it('should update fields property and user info when sorting fields', () => { it('should sort fields and update user info when fields sorted', () => {
schemasService.setup(x => x.putFieldOrdering(app, schema.name, [field2.fieldId, field1.fieldId], version)) schemasService.setup(x => x.putFieldOrdering(app, schema.name, [field2.fieldId, field1.fieldId], version))
.returns(() => Observable.of(new Versioned<any>(newVersion, {}))); .returns(() => Observable.of(new Versioned<any>(newVersion, {})));
@ -277,7 +277,7 @@ describe('SchemasState', () => {
expectToBeModified(schema_1); expectToBeModified(schema_1);
}); });
it('should update fields property and user info when updating field', () => { it('should update field properties and update user info when field updated', () => {
const request = new UpdateFieldDto(createProperties('String')); const request = new UpdateFieldDto(createProperties('String'));
schemasService.setup(x => x.putField(app, schema.name, field1.fieldId, request, version)) schemasService.setup(x => x.putField(app, schema.name, field1.fieldId, request, version))
@ -291,7 +291,7 @@ describe('SchemasState', () => {
expectToBeModified(schema_1); expectToBeModified(schema_1);
}); });
it('should update fields property and user info when hiding field', () => { it('should mark field hidden and update user info when field hidden', () => {
schemasService.setup(x => x.hideField(app, schema.name, field1.fieldId, version)) schemasService.setup(x => x.hideField(app, schema.name, field1.fieldId, version))
.returns(() => Observable.of(new Versioned<any>(newVersion, {}))); .returns(() => Observable.of(new Versioned<any>(newVersion, {})));
@ -303,7 +303,7 @@ describe('SchemasState', () => {
expectToBeModified(schema_1); expectToBeModified(schema_1);
}); });
it('should update fields property and user info when disabling field', () => { it('should mark field disabled and update user info when field disabled', () => {
schemasService.setup(x => x.disableField(app, schema.name, field1.fieldId, version)) schemasService.setup(x => x.disableField(app, schema.name, field1.fieldId, version))
.returns(() => Observable.of(new Versioned<any>(newVersion, {}))); .returns(() => Observable.of(new Versioned<any>(newVersion, {})));
@ -315,7 +315,7 @@ describe('SchemasState', () => {
expectToBeModified(schema_1); expectToBeModified(schema_1);
}); });
it('should update fields property and user info when locking field', () => { it('should mark field locked and update user info when field locked', () => {
schemasService.setup(x => x.lockField(app, schema.name, field1.fieldId, version)) schemasService.setup(x => x.lockField(app, schema.name, field1.fieldId, version))
.returns(() => Observable.of(new Versioned<any>(newVersion, {}))); .returns(() => Observable.of(new Versioned<any>(newVersion, {})));
@ -327,7 +327,7 @@ describe('SchemasState', () => {
expectToBeModified(schema_1); expectToBeModified(schema_1);
}); });
it('should update fields property and user info when showing field', () => { it('should unmark field hidden and update user info when field shown', () => {
schemasService.setup(x => x.showField(app, schema.name, field2.fieldId, version)) schemasService.setup(x => x.showField(app, schema.name, field2.fieldId, version))
.returns(() => Observable.of(new Versioned<any>(newVersion, {}))); .returns(() => Observable.of(new Versioned<any>(newVersion, {})));
@ -339,7 +339,7 @@ describe('SchemasState', () => {
expectToBeModified(schema_1); expectToBeModified(schema_1);
}); });
it('should update fields property and user info when enabling field', () => { it('should unmark field disabled and update user info when field enabled', () => {
schemasService.setup(x => x.enableField(app, schema.name, field2.fieldId, version)) schemasService.setup(x => x.enableField(app, schema.name, field2.fieldId, version))
.returns(() => Observable.of(new Versioned<any>(newVersion, {}))); .returns(() => Observable.of(new Versioned<any>(newVersion, {})));

Loading…
Cancel
Save