Browse Source

More refactorings.

pull/356/head
Sebastian Stehle 7 years ago
parent
commit
57eaab592a
  1. 32
      src/Squidex/app/features/administration/state/event-consumers.state.spec.ts
  2. 8
      src/Squidex/app/features/administration/state/event-consumers.state.ts
  3. 58
      src/Squidex/app/features/administration/state/users.state.spec.ts
  4. 10
      src/Squidex/app/features/administration/state/users.state.ts
  5. 64
      src/Squidex/app/features/settings/pages/clients/client.component.ts
  6. 7
      src/Squidex/app/features/settings/pages/clients/clients-page.component.ts
  7. 12
      src/Squidex/app/features/settings/pages/contributors/contributors-page.component.ts
  8. 2
      src/Squidex/app/framework/angular/forms/forms-helper.ts
  9. 8
      src/Squidex/app/framework/state.ts
  10. 2
      src/Squidex/app/framework/utils/version.spec.ts
  11. 2
      src/Squidex/app/shared/interceptors/auth.interceptor.ts
  12. 2
      src/Squidex/app/shared/services/help.service.ts
  13. 4
      src/Squidex/app/shared/services/ui.service.ts
  14. 2
      src/Squidex/app/shared/state/assets.state.spec.ts
  15. 12
      src/Squidex/app/shared/state/clients.state.spec.ts
  16. 100
      src/Squidex/app/shared/state/clients.state.ts
  17. 22
      src/Squidex/app/shared/state/comments.state.spec.ts
  18. 124
      src/Squidex/app/shared/state/comments.state.ts
  19. 14
      src/Squidex/app/shared/state/contributors.state.spec.ts
  20. 85
      src/Squidex/app/shared/state/contributors.state.ts
  21. 6
      src/Squidex/app/shared/state/languages.state.spec.ts
  22. 6
      src/Squidex/app/shared/state/patterns.state.spec.ts
  23. 5
      src/Squidex/app/shared/state/plans.state.spec.ts
  24. 6
      src/Squidex/app/shared/state/roles.state.spec.ts
  25. 10
      src/Squidex/app/shared/state/rules.state.spec.ts
  26. 54
      src/Squidex/app/shared/state/schemas.state.spec.ts

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

@ -6,6 +6,7 @@
*/
import { of, throwError } from 'rxjs';
import { onErrorResumeNext } from 'rxjs/operators';
import { IMock, It, Mock, Times } from 'typemoq';
import { DialogService } from '@app/shared';
@ -15,8 +16,8 @@ import { EventConsumersState } from './event-consumers.state';
describe('EventConsumersState', () => {
const oldConsumers = [
new EventConsumerDto('name1', false),
new EventConsumerDto('name2', true)
new EventConsumerDto('name1', false, false, 'error', '1'),
new EventConsumerDto('name2', true, true, 'error', '2')
];
let dialogs: IMock<DialogService>;
@ -29,12 +30,16 @@ describe('EventConsumersState', () => {
eventConsumersService = Mock.ofType<EventConsumersService>();
eventConsumersService.setup(x => x.getEventConsumers())
.returns(() => of(oldConsumers));
.returns(() => of(oldConsumers)).verifiable(Times.atLeastOnce());
eventConsumersState = new EventConsumersState(dialogs.object, eventConsumersService.object);
eventConsumersState.load().subscribe();
});
afterEach(() => {
eventConsumersService.verifyAll();
});
it('should load event consumers', () => {
expect(eventConsumersState.snapshot.eventConsumers.values).toEqual(oldConsumers);
expect(eventConsumersState.snapshot.isLoaded).toBeTruthy();
@ -45,7 +50,10 @@ describe('EventConsumersState', () => {
});
it('should show notification on load when reload is true', () => {
eventConsumersState.load(true);
eventConsumersService.setup(x => x.getEventConsumers())
.returns(() => of(oldConsumers));
eventConsumersState.load(true).subscribe();
expect().nothing();
@ -56,7 +64,7 @@ describe('EventConsumersState', () => {
eventConsumersService.setup(x => x.getEventConsumers())
.returns(() => throwError({}));
eventConsumersState.load(true, false);
eventConsumersState.load(true, false).pipe(onErrorResumeNext()).subscribe();
expect().nothing();
@ -67,7 +75,7 @@ describe('EventConsumersState', () => {
eventConsumersService.setup(x => x.getEventConsumers())
.returns(() => throwError({}));
eventConsumersState.load(true, true);
eventConsumersState.load(true, true).pipe(onErrorResumeNext()).subscribe();
expect().nothing();
@ -76,9 +84,9 @@ describe('EventConsumersState', () => {
it('should unmark as stopped when started', () => {
eventConsumersService.setup(x => x.putStart(oldConsumers[1].name))
.returns(() => of({}));
.returns(() => of({})).verifiable();
eventConsumersState.start(oldConsumers[1]);
eventConsumersState.start(oldConsumers[1]).subscribe();
const es_1 = eventConsumersState.snapshot.eventConsumers.at(1);
@ -87,9 +95,9 @@ describe('EventConsumersState', () => {
it('should mark as stopped when stopped', () => {
eventConsumersService.setup(x => x.putStop(oldConsumers[0].name))
.returns(() => of({}));
.returns(() => of({})).verifiable();
eventConsumersState.stop(oldConsumers[0]);
eventConsumersState.stop(oldConsumers[0]).subscribe();
const es_1 = eventConsumersState.snapshot.eventConsumers.at(0);
@ -98,9 +106,9 @@ describe('EventConsumersState', () => {
it('should mark as resetting when reset', () => {
eventConsumersService.setup(x => x.putReset(oldConsumers[0].name))
.returns(() => of({}));
.returns(() => of({})).verifiable();
eventConsumersState.reset(oldConsumers[0]);
eventConsumersState.reset(oldConsumers[0]).subscribe();
const es_1 = eventConsumersState.snapshot.eventConsumers.at(0);

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

@ -45,7 +45,7 @@ export class EventConsumersState extends State<Snapshot> {
super({ eventConsumers: ImmutableArray.empty() });
}
public load(isReload = false, silent = false): Observable<EventConsumersList> {
public load(isReload = false, silent = false): Observable<any> {
if (!isReload) {
this.resetState();
}
@ -75,7 +75,7 @@ export class EventConsumersState extends State<Snapshot> {
public start(eventConsumer: EventConsumerDto): Observable<any> {
const stream =
this.eventConsumersService.putStart(eventConsumer.name).pipe(
map(_ => setStopped(eventConsumer, false), share()));
map(() => setStopped(eventConsumer, false), share()));
this.updateState(stream);
@ -85,7 +85,7 @@ export class EventConsumersState extends State<Snapshot> {
public stop(eventConsumer: EventConsumerDto): Observable<EventConsumerDto> {
const stream =
this.eventConsumersService.putStop(eventConsumer.name).pipe(
map(_ => setStopped(eventConsumer, true), share()));
map(() => setStopped(eventConsumer, true), share()));
this.updateState(stream);
@ -95,7 +95,7 @@ export class EventConsumersState extends State<Snapshot> {
public reset(eventConsumer: EventConsumerDto): Observable<any> {
const stream =
this.eventConsumersService.putReset(eventConsumer.name).pipe(
map(_ => reset(eventConsumer), share()));
map(() => reset(eventConsumer), share()));
this.updateState(stream);

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

@ -42,10 +42,14 @@ describe('UsersState', () => {
usersService = Mock.ofType<UsersService>();
usersService.setup(x => x.getUsers(10, 0, undefined))
.returns(() => of(new UsersDto(200, oldUsers)));
.returns(() => of(new UsersDto(200, oldUsers))).verifiable(Times.atLeastOnce());
usersState = new UsersState(authService.object, dialogs.object, usersService.object);
usersState.load();
usersState.load().subscribe();
});
afterEach(() => {
usersService.verifyAll();
});
it('should load users', () => {
@ -60,7 +64,7 @@ describe('UsersState', () => {
});
it('should show notification on load when reload is true', () => {
usersState.load(true);
usersState.load(true).subscribe();
expect().nothing();
@ -68,7 +72,7 @@ describe('UsersState', () => {
});
it('should replace selected user when reloading', () => {
usersState.select('id1');
usersState.select('id1').subscribe();
const newUsers = [
new UserDto('id1', 'mail1@mail.de_new', 'name1_new', ['Permission1_New'], false),
@ -78,7 +82,7 @@ describe('UsersState', () => {
usersService.setup(x => x.getUsers(10, 0, undefined))
.returns(() => of(new UsersDto(200, newUsers)));
usersState.load();
usersState.load().subscribe();
expect(usersState.snapshot.selectedUser).toEqual({ isCurrentUser: false, user: newUsers[0] });
});
@ -92,8 +96,6 @@ describe('UsersState', () => {
expect(selectedUser!.user).toEqual(oldUsers[0]);
expect(usersState.snapshot.selectedUser).toEqual({ isCurrentUser: false, user: oldUsers[0] });
usersService.verify(x => x.getUser(It.isAnyString()), Times.never());
});
it('should return user on select and load when not loaded', () => {
@ -108,8 +110,6 @@ describe('UsersState', () => {
expect(selectedUser!.user).toEqual(newUser);
expect(usersState.snapshot.selectedUser).toEqual({ isCurrentUser: false, user: newUser });
usersService.verify(x => x.getUser('id3'), Times.once());
});
it('should return null on select when unselecting user', () => {
@ -121,19 +121,17 @@ describe('UsersState', () => {
expect(selectedUser!).toBeNull();
expect(usersState.snapshot.selectedUser).toBeNull();
usersService.verify(x => x.getUser(It.isAnyString()), Times.never());
});
it('should return null on select when user is not found', () => {
usersService.setup(x => x.getUser('unknown'))
.returns(() => throwError({}));
.returns(() => throwError({})).verifiable();
let selectedUser: SnapshotUser;
usersState.select('unknown').subscribe(x => {
selectedUser = x!;
});
}).unsubscribe();
expect(selectedUser!).toBeNull();
expect(usersState.snapshot.selectedUser).toBeNull();
@ -141,10 +139,10 @@ describe('UsersState', () => {
it('should mark as locked when locked', () => {
usersService.setup(x => x.lockUser('id1'))
.returns(() => of({}));
.returns(() => of({})).verifiable();
usersState.select('id1');
usersState.lock(oldUsers[0]);
usersState.select('id1').subscribe();
usersState.lock(oldUsers[0]).subscribe();
const user_1 = usersState.snapshot.users.at(0);
@ -154,10 +152,10 @@ describe('UsersState', () => {
it('should unmark as locked when unlocked', () => {
usersService.setup(x => x.unlockUser('id2'))
.returns(() => of({}));
.returns(() => of({})).verifiable();
usersState.select('id2');
usersState.unlock(oldUsers[1]);
usersState.select('id2').subscribe();
usersState.unlock(oldUsers[1]).subscribe();
const user_1 = usersState.snapshot.users.at(1);
@ -169,10 +167,10 @@ describe('UsersState', () => {
const request = { email: 'new@mail.com', displayName: 'New', permissions: ['Permission1'] };
usersService.setup(x => x.putUser('id1', request))
.returns(() => of({}));
.returns(() => of({})).verifiable();
usersState.select('id1');
usersState.update(oldUsers[0], request);
usersState.select('id1').subscribe();
usersState.update(oldUsers[0], request).subscribe();
const user_1 = usersState.snapshot.users.at(0);
@ -186,9 +184,9 @@ describe('UsersState', () => {
const request = { ...newUser, password: 'password' };
usersService.setup(x => x.postUser(request))
.returns(() => of(newUser));
.returns(() => of(newUser)).verifiable();
usersState.create(request);
usersState.create(request).subscribe();
expect(usersState.snapshot.users.values).toEqual([
{ isCurrentUser: false, user: newUser },
@ -200,10 +198,10 @@ describe('UsersState', () => {
it('should load next page and prev page when paging', () => {
usersService.setup(x => x.getUsers(10, 10, undefined))
.returns(() => of(new UsersDto(200, [])));
.returns(() => of(new UsersDto(200, []))).verifiable();
usersState.goNext();
usersState.goPrev();
usersState.goNext().subscribe();
usersState.goPrev().subscribe();
expect().nothing();
@ -213,12 +211,10 @@ describe('UsersState', () => {
it('should load with query when searching', () => {
usersService.setup(x => x.getUsers(10, 0, 'my-query'))
.returns(() => of(new UsersDto(0, [])));
.returns(() => of(new UsersDto(0, []))).verifiable();
usersState.search('my-query');
usersState.search('my-query').subscribe();
expect(usersState.snapshot.usersQuery).toEqual('my-query');
usersService.verify(x => x.getUsers(10, 0, 'my-query'), Times.once());
});
});

10
src/Squidex/app/features/administration/state/users.state.ts

@ -7,7 +7,7 @@
import { Injectable } from '@angular/core';
import { Observable, of } from 'rxjs';
import { catchError, distinctUntilChanged, map, share, switchMap } from 'rxjs/operators';
import { catchError, distinctUntilChanged, map, share } from 'rxjs/operators';
import '@app/framework/utils/rxjs-extensions';
@ -113,7 +113,7 @@ export class UsersState extends State<Snapshot> {
return this.loadInternal(isReload);
}
private loadInternal(isReload = false): Observable<UsersResult> {
private loadInternal(isReload = false): Observable<any> {
const stream =
this.usersService.getUsers(
this.snapshot.usersPager.pageSize,
@ -163,7 +163,7 @@ export class UsersState extends State<Snapshot> {
public update(user: UserDto, request: UpdateUserDto): Observable<UserDto> {
const stream =
this.usersService.putUser(user.id, request).pipe(
map(_ => update(user, request)), share());
map(() => update(user, request)), share());
this.updateState(stream, false);
@ -173,7 +173,7 @@ export class UsersState extends State<Snapshot> {
public lock(user: UserDto): Observable<UserDto> {
const stream =
this.usersService.lockUser(user.id).pipe(
map(_ => setLocked(user, true)), share());
map(() => setLocked(user, true)), share());
this.updateState(stream, true);
@ -183,7 +183,7 @@ export class UsersState extends State<Snapshot> {
public unlock(user: UserDto): Observable<UserDto> {
const stream =
this.usersService.unlockUser(user.id).pipe(
map(_ => setLocked(user, false)), share());
map(() => setLocked(user, false)), share());
this.updateState(stream, true);

64
src/Squidex/app/features/settings/pages/clients/client.component.ts

@ -7,7 +7,6 @@
import { Component, Input, OnChanges } from '@angular/core';
import { FormBuilder } from '@angular/forms';
import { onErrorResumeNext } from 'rxjs/operators';
import {
AccessTokenDto,
@ -24,36 +23,6 @@ import {
const ESCAPE_KEY = 27;
function connectHttpText(apiUrl: ApiUrlConfig, app: string, client: { id: string, secret: string }) {
const url = apiUrl.buildUrl('identity-server/connect/token');
return `$ curl
-X POST '${url}'
-H 'Content-Type: application/x-www-form-urlencoded'
-d 'grant_type=client_credentials&
client_id=${app}:${client.id}&
client_secret=${client.secret}&
scope=squidex-api`;
}
function connectCLIWinText(app: string, client: { id: string, secret: string }) {
return `.\\sq.exe config add ${app} ${app}:${client.id} ${client.secret};.\\sq.exe config use ${app}`;
}
function connectCLINixText(app: string, client: { id: string, secret: string }) {
return `sq config add ${app} ${app}:${client.id} ${client.secret} && sq config use ${app}`;
}
function connectLibrary(apiUrl: ApiUrlConfig, app: string, client: { id: string, secret: string }) {
const url = apiUrl.value;
return `var clientManager = new SquidexClientManager(
"${url}",
"${app}",
"${app}:${client.id}",
"${client.secret}")`;
}
@Component({
selector: 'sqx-client',
styleUrls: ['./client.component.scss'],
@ -100,11 +69,11 @@ export class ClientComponent implements OnChanges {
}
public revoke() {
this.clientsState.revoke(this.client).pipe(onErrorResumeNext()).subscribe();
this.clientsState.revoke(this.client);
}
public update(role: string) {
this.clientsState.update(this.client, { role }).pipe(onErrorResumeNext()).subscribe();
this.clientsState.update(this.client, { role });
}
public toggleRename() {
@ -144,3 +113,32 @@ export class ClientComponent implements OnChanges {
}
}
function connectHttpText(apiUrl: ApiUrlConfig, app: string, client: { id: string, secret: string }) {
const url = apiUrl.buildUrl('identity-server/connect/token');
return `$ curl
-X POST '${url}'
-H 'Content-Type: application/x-www-form-urlencoded'
-d 'grant_type=client_credentials&
client_id=${app}:${client.id}&
client_secret=${client.secret}&
scope=squidex-api`;
}
function connectCLIWinText(app: string, client: { id: string, secret: string }) {
return `.\\sq.exe config add ${app} ${app}:${client.id} ${client.secret};.\\sq.exe config use ${app}`;
}
function connectCLINixText(app: string, client: { id: string, secret: string }) {
return `sq config add ${app} ${app}:${client.id} ${client.secret} && sq config use ${app}`;
}
function connectLibrary(apiUrl: ApiUrlConfig, app: string, client: { id: string, secret: string }) {
const url = apiUrl.value;
return `var clientManager = new SquidexClientManager(
"${url}",
"${app}",
"${app}:${client.id}",
"${client.secret}")`;
}

7
src/Squidex/app/features/settings/pages/clients/clients-page.component.ts

@ -7,7 +7,6 @@
import { Component, OnInit } from '@angular/core';
import { FormBuilder } from '@angular/forms';
import { onErrorResumeNext } from 'rxjs/operators';
import {
AppsState,
@ -34,13 +33,13 @@ export class ClientsPageComponent implements OnInit {
}
public ngOnInit() {
this.rolesState.load().pipe(onErrorResumeNext()).subscribe();
this.rolesState.load();
this.clientsState.load().pipe(onErrorResumeNext()).subscribe();
this.clientsState.load();
}
public reload() {
this.clientsState.load(true).pipe(onErrorResumeNext()).subscribe();
this.clientsState.load(true);
}
public attachClient() {

12
src/Squidex/app/features/settings/pages/contributors/contributors-page.component.ts

@ -8,7 +8,7 @@
import { Component, Injectable, OnInit } from '@angular/core';
import { FormBuilder } from '@angular/forms';
import { Observable } from 'rxjs';
import { onErrorResumeNext, withLatestFrom } from 'rxjs/operators';
import { withLatestFrom } from 'rxjs/operators';
import {
AppsState,
@ -68,21 +68,21 @@ export class ContributorsPageComponent implements OnInit {
}
public ngOnInit() {
this.rolesState.load().pipe(onErrorResumeNext()).subscribe();
this.rolesState.load();
this.contributorsState.load().pipe(onErrorResumeNext()).subscribe();
this.contributorsState.load();
}
public reload() {
this.contributorsState.load(true).pipe(onErrorResumeNext()).subscribe();
this.contributorsState.load(true);
}
public remove(contributor: ContributorDto) {
this.contributorsState.revoke(contributor).pipe(onErrorResumeNext()).subscribe();
this.contributorsState.revoke(contributor);
}
public changeRole(contributor: ContributorDto, role: string) {
this.contributorsState.assign({ contributorId: contributor.contributorId, role }).pipe(onErrorResumeNext()).subscribe();
this.contributorsState.assign({ contributorId: contributor.contributorId, role });
}
public assignContributor() {

2
src/Squidex/app/framework/angular/forms/forms-helper.ts

@ -22,7 +22,7 @@ export function formControls(form: AbstractControl): AbstractControl[] {
}
export function invalid$(form: AbstractControl): Observable<boolean> {
return form.statusChanges.pipe(map(_ => form.invalid), startWith(form.invalid));
return form.statusChanges.pipe(map(() => form.invalid), startWith(form.invalid));
}
export function value$<T = any>(form: AbstractControl): Observable<T> {

8
src/Squidex/app/framework/state.ts

@ -59,13 +59,13 @@ export class Form<T extends AbstractControl, V> {
}
public load(value: V | undefined) {
this.state.next(_ => ({ submitted: false, error: null }));
this.state.next(() => ({ submitted: false, error: null }));
this.setValue(value);
}
public submit(): V | null {
this.state.next(_ => ({ submitted: true }));
this.state.next(() => ({ submitted: true }));
if (this.form.valid) {
const value = this.transformSubmit(fullValue(this.form));
@ -79,14 +79,14 @@ export class Form<T extends AbstractControl, V> {
}
public submitCompleted(newValue?: V) {
this.state.next(_ => ({ submitted: false, error: null }));
this.state.next(() => ({ submitted: false, error: null }));
this.enable();
this.setValue(newValue);
}
public submitFailed(error?: string | ErrorDto) {
this.state.next(_ => ({ submitted: false, error: this.getError(error) }));
this.state.next(() => ({ submitted: false, error: this.getError(error) }));
this.enable();
}

2
src/Squidex/app/framework/utils/version.spec.ts

@ -24,7 +24,7 @@ describe('Version', () => {
describe('Versioned', () => {
it('should initialize with version and payload', () => {
const versioned = new Versioned<number>(new Version('1.0'), 123);
const versioned = new Versioned(new Version('1.0'), 123);
expect(versioned.version.value).toBe('1.0');
expect(versioned.payload).toBe(123);

2
src/Squidex/app/shared/interceptors/auth.interceptor.ts

@ -50,7 +50,7 @@ export class AuthInterceptor implements HttpInterceptor {
catchError((error: HttpErrorResponse) => {
if (error.status === 401 && renew) {
return this.authService.loginSilent().pipe(
catchError(_ => {
catchError(() => {
this.authService.logoutRedirect();
return empty();

2
src/Squidex/app/shared/services/help.service.ts

@ -21,6 +21,6 @@ export class HelpService {
const url = `https://raw.githubusercontent.com/Squidex/squidex-docs/master/${helpPage}.md`;
return this.http.get(url, { responseType: 'text' }).pipe(
catchError(_ => of('')));
catchError(() => of('')));
}
}

4
src/Squidex/app/shared/services/ui.service.ts

@ -31,7 +31,7 @@ export class UIService {
const url = this.apiUrl.buildUrl(`api/ui/settings`);
return this.http.get<UISettingsDto>(url).pipe(
catchError(_ => {
catchError(() => {
return of({ mapType: 'OSM', mapKey: '', canCreateApps: true });
}));
}
@ -40,7 +40,7 @@ export class UIService {
const url = this.apiUrl.buildUrl(`api/apps/${appName}/ui/settings`);
return this.http.get<object>(url).pipe(
catchError(_ => {
catchError(() => {
return of({ });
}));
}

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

@ -90,7 +90,7 @@ describe('AssetsState', () => {
it('should remove asset from snapshot when deleted', () => {
assetsService.setup(x => x.deleteAsset(app, oldAssets[0].id, version))
.returns(() => of(new Versioned<any>(newVersion, {})));
.returns(() => of(new Versioned(newVersion, {})));
assetsState.delete(oldAssets[0]).subscribe();

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

@ -42,12 +42,16 @@ describe('ClientsState', () => {
clientsService = Mock.ofType<ClientsService>();
clientsService.setup(x => x.getClients(app))
.returns(() => of(new ClientsDto(oldClients, version)));
.returns(() => of(new ClientsDto(oldClients, version))).verifiable(Times.atLeastOnce());
clientsState = new ClientsState(clientsService.object, appsState.object, dialogs.object);
clientsState.load().subscribe();
});
afterEach(() => {
clientsService.verifyAll();
});
it('should load clients', () => {
expect(clientsState.snapshot.clients.values).toEqual(oldClients);
expect(clientsState.snapshot.version).toEqual(version);
@ -70,7 +74,7 @@ describe('ClientsState', () => {
const request = { id: 'id3' };
clientsService.setup(x => x.postClient(app, request, version))
.returns(() => of(new Versioned<ClientDto>(newVersion, newClient)));
.returns(() => of(new Versioned(newVersion, newClient))).verifiable();
clientsState.attach(request).subscribe();
@ -82,7 +86,7 @@ describe('ClientsState', () => {
const request = { name: 'NewName', role: 'NewRole' };
clientsService.setup(x => x.putClient(app, oldClients[0].id, request, version))
.returns(() => of(new Versioned<any>(newVersion, {})));
.returns(() => of(new Versioned(newVersion, {}))).verifiable();
clientsState.update(oldClients[0], request).subscribe();
@ -95,7 +99,7 @@ describe('ClientsState', () => {
it('should remove client from snapshot when revoked', () => {
clientsService.setup(x => x.deleteClient(app, oldClients[0].id, version))
.returns(() => of(new Versioned<any>(newVersion, {})));
.returns(() => of(new Versioned(newVersion, {}))).verifiable();
clientsState.revoke(oldClients[0]).subscribe();

100
src/Squidex/app/shared/state/clients.state.ts

@ -5,14 +5,16 @@
* Copyright (c) Squidex UG (haftungsbeschränkt). All rights reserved.
*/
// tslint:disable: no-shadowed-variable
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';
import { distinctUntilChanged, map, tap } from 'rxjs/operators';
import { distinctUntilChanged, map, share } from 'rxjs/operators';
import {
array,
DialogService,
ImmutableArray,
notify,
State,
Version
} from '@app/framework';
@ -28,7 +30,7 @@ import {
interface Snapshot {
// The current clients.
clients: ImmutableArray<ClientDto>;
clients: ClientsList;
// The app version.
version: Version;
@ -37,6 +39,8 @@ interface Snapshot {
isLoaded?: boolean;
}
type ClientsList = ImmutableArray<ClientDto>;
@Injectable()
export class ClientsState extends State<Snapshot> {
public clients =
@ -60,55 +64,69 @@ export class ClientsState extends State<Snapshot> {
this.resetState();
}
return this.clientsService.getClients(this.appName).pipe(
tap(dtos => {
if (isReload) {
this.dialogs.notifyInfo('Clients reloaded.');
}
const stream =
this.clientsService.getClients(this.appName).pipe(
map(({ version, clients }) => ({ version, clients: array(clients) })), share());
stream.subscribe(({ version, clients }) => {
if (isReload) {
this.dialogs.notifyInfo('Clients reloaded.');
}
this.next(s => {
const clients = ImmutableArray.of(dtos.clients);
this.next(s => {
return { ...s, clients, isLoaded: true, version };
});
});
return { ...s, clients, isLoaded: true, version: dtos.version };
});
}),
notify(this.dialogs));
return stream;
}
public attach(request: CreateClientDto): Observable<any> {
return this.clientsService.postClient(this.appName, request, this.version).pipe(
tap(dto => {
this.next(s => {
const clients = s.clients.push(dto.payload);
public attach(request: CreateClientDto): Observable<ClientDto> {
const stream =
this.clientsService.postClient(this.appName, request, this.version).pipe(
share());
stream.subscribe(dto => {
this.next(s => {
const clients = s.clients.push(dto.payload);
return { ...s, clients, version: dto.version };
});
});
return { ...s, clients, version: dto.version };
});
}),
notify(this.dialogs));
return stream.pipe(map(x => x.payload));
}
public revoke(client: ClientDto): Observable<any> {
return this.clientsService.deleteClient(this.appName, client.id, this.version).pipe(
tap(dto => {
this.next(s => {
const clients = s.clients.filter(c => c.id !== client.id);
return { ...s, clients, version: dto.version };
});
}),
notify(this.dialogs));
const stream =
this.clientsService.deleteClient(this.appName, client.id, this.version).pipe(
share());
stream.subscribe(({ version }) => {
this.next(s => {
const clients = s.clients.filter(c => c.id !== client.id);
return { ...s, clients, version };
});
});
return stream;
}
public update(client: ClientDto, request: UpdateClientDto): Observable<any> {
return this.clientsService.putClient(this.appName, client.id, request, this.version).pipe(
tap(dto => {
this.next(s => {
const clients = s.clients.replaceBy('id', update(client, request));
public update(client: ClientDto, request: UpdateClientDto): Observable<ClientDto> {
const stream =
this.clientsService.putClient(this.appName, client.id, request, this.version).pipe(
map(({ version }) => ({ version, client: update(client, request) })), share());
stream.subscribe(({ version, client }) => {
this.next(s => {
const clients = s.clients.replaceBy('id', client);
return { ...s, clients, version };
});
});
return { ...s, clients, version: dto.version };
});
}),
notify(this.dialogs));
return stream.pipe(map(x => x.client));
}
private get appName() {

22
src/Squidex/app/shared/state/comments.state.spec.ts

@ -45,12 +45,16 @@ describe('CommentsState', () => {
commentsService = Mock.ofType<CommentsService>();
commentsService.setup(x => x.getComments(app, commentsId, new Version('-1')))
.returns(() => of(oldComments));
.returns(() => of(oldComments)).verifiable(Times.atLeastOnce());
commentsState = new CommentsState(appsState.object, commentsId, commentsService.object, dialogs.object);
commentsState.load().subscribe();
});
beforeEach(() => {
commentsService.verifyAll();
});
it('should load and merge comments', () => {
const newComments = new CommentsDto([
new CommentDto('3', now, 'text3', creator)
@ -59,7 +63,7 @@ describe('CommentsState', () => {
], ['1'], new Version('2'));
commentsService.setup(x => x.getComments(app, commentsId, new Version('1')))
.returns(() => of(newComments));
.returns(() => of(newComments)).verifiable();
commentsState.load().subscribe();
@ -78,7 +82,7 @@ describe('CommentsState', () => {
const request = { text: 'text3' };
commentsService.setup(x => x.postComment(app, commentsId, request))
.returns(() => of(newComment));
.returns(() => of(newComment)).verifiable();
commentsState.create('text3').subscribe();
@ -93,28 +97,24 @@ describe('CommentsState', () => {
const request = { text: 'text2_2' };
commentsService.setup(x => x.putComment(app, commentsId, '2', request))
.returns(() => of({}));
.returns(() => of({})).verifiable();
commentsState.update('2', 'text2_2', now).subscribe();
commentsState.update(oldComments.createdComments[1], 'text2_2', now).subscribe();
expect(commentsState.snapshot.comments).toEqual(ImmutableArray.of([
new CommentDto('1', now, 'text1', creator),
new CommentDto('2', now, 'text2_2', creator)
]));
commentsService.verify(x => x.putComment(app, commentsId, '2', request), Times.once());
});
it('should remove comment from snapshot when deleted', () => {
commentsService.setup(x => x.deleteComment(app, commentsId, '2'))
.returns(() => of({}));
.returns(() => of({})).verifiable();
commentsState.delete('2').subscribe();
commentsState.delete(oldComments.createdComments[1]).subscribe();
expect(commentsState.snapshot.comments).toEqual(ImmutableArray.of([
new CommentDto('1', now, 'text1', creator)
]));
commentsService.verify(x => x.deleteComment(app, commentsId, '2'), Times.once());
});
});

124
src/Squidex/app/shared/state/comments.state.ts

@ -6,7 +6,7 @@
*/
import { Observable } from 'rxjs';
import { distinctUntilChanged, map, tap } from 'rxjs/operators';
import { distinctUntilChanged, map, share } from 'rxjs/operators';
import {
DateTime,
@ -17,12 +17,12 @@ import {
Version
} from '@app/framework';
import { CommentDto, CommentsService } from './../services/comments.service';
import { CommentDto, CommentsDto, CommentsService } from './../services/comments.service';
import { AppsState } from './apps.state';
interface Snapshot {
// The current comments.
comments: ImmutableArray<CommentDto>;
comments: CommentsList;
// The version of the comments state.
version: Version;
@ -31,6 +31,8 @@ interface Snapshot {
isLoaded?: boolean;
}
type CommentsList = ImmutableArray<CommentDto>;
export class CommentsState extends State<Snapshot> {
public comments =
this.changes.pipe(map(x => x.comments),
@ -49,66 +51,90 @@ export class CommentsState extends State<Snapshot> {
super({ comments: ImmutableArray.empty(), version: new Version('-1') });
}
public load(): Observable<any> {
return this.commentsService.getComments(this.appName, this.commentsId, this.version).pipe(
tap(dtos => {
this.next(s => {
let comments = s.comments;
public load(): Observable<CommentsDto> {
const stream =
this.commentsService.getComments(this.appName, this.commentsId, this.version).pipe(
share());
for (let created of dtos.createdComments) {
if (!comments.find(x => x.id === created.id)) {
comments = comments.push(created);
}
}
stream.subscribe(response => {
this.next(s => {
let comments = s.comments;
for (let updated of dtos.updatedComments) {
comments = comments.replaceBy('id', updated);
for (let created of response.createdComments) {
if (!comments.find(x => x.id === created.id)) {
comments = comments.push(created);
}
}
for (let deleted of dtos.deletedComments) {
comments = comments.filter(x => x.id !== deleted);
}
for (let updated of response.updatedComments) {
comments = comments.replaceBy('id', updated);
}
return { ...s, comments, isLoaded: true, version: dtos.version };
});
}),
notify(this.dialogs));
for (let deleted of response.deletedComments) {
comments = comments.filter(x => x.id !== deleted);
}
return { ...s, comments, isLoaded: true, version: response.version };
});
}, error => {
this.dialogs.notifyError(error);
});
return stream;
}
public create(text: string): Observable<any> {
return this.commentsService.postComment(this.appName, this.commentsId, { text }).pipe(
tap(dto => {
this.next(s => {
const comments = s.comments.push(dto);
public create(text: string): Observable<CommentDto> {
const stream =
this.commentsService.postComment(this.appName, this.commentsId, { text }).pipe(
share());
stream.subscribe(comment => {
this.next(s => {
const comments = s.comments.push(comment);
return { ...s, comments };
});
}),
notify(this.dialogs));
return { ...s, comments };
});
}, error => {
this.dialogs.notifyError(error);
});
return stream;
}
public update(commentId: string, text: string, now?: DateTime): Observable<any> {
return this.commentsService.putComment(this.appName, this.commentsId, commentId, { text }).pipe(
tap(() => {
this.next(s => {
const comments = s.comments.map(c => c.id === commentId ? update(c, text, now || DateTime.now()) : c);
public update(comment: CommentDto, text: string, now?: DateTime): Observable<CommentDto> {
const stream =
this.commentsService.putComment(this.appName, this.commentsId, comment.id, { text }).pipe(
map(() => update(comment, text, now || DateTime.now())), share());
stream.subscribe(updated => {
this.next(s => {
const comments = s.comments.replaceBy('id', updated);
return { ...s, comments };
});
}, error => {
this.dialogs.notifyError(error);
});
return { ...s, comments };
});
}),
notify(this.dialogs));
return stream;
}
public delete(commentId: string): Observable<any> {
return this.commentsService.deleteComment(this.appName, this.commentsId, commentId).pipe(
tap(() => {
this.next(s => {
const comments = s.comments.filter(c => c.id !== commentId);
public delete(comment: CommentDto): Observable<any> {
const stream =
this.commentsService.deleteComment(this.appName, this.commentsId, comment.id).pipe(
share());
stream.subscribe(() => {
this.next(s => {
const comments = s.comments.removeBy('id', comment);
return { ...s, comments };
});
}, error => {
this.dialogs.notifyError(error);
});
return { ...s, comments };
});
}),
notify(this.dialogs));
return stream;
}
private get version() {

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

@ -9,7 +9,6 @@ import { of } from 'rxjs';
import { IMock, It, Mock, Times } from 'typemoq';
import {
ContributorAssignedDto,
ContributorDto,
ContributorsDto,
ContributorsService,
@ -43,13 +42,18 @@ describe('ContributorsState', () => {
dialogs = Mock.ofType<DialogService>();
contributorsService = Mock.ofType<ContributorsService>();
contributorsService.setup(x => x.getContributors(app))
.returns(() => of(new ContributorsDto(oldContributors, 3, version)));
.returns(() => of(new ContributorsDto(oldContributors, 3, version))).verifiable(Times.atLeastOnce());
contributorsState = new ContributorsState(contributorsService.object, appsState.object, authService.object, dialogs.object);
contributorsState.load().subscribe();
});
afterEach(() => {
contributorsService.verifyAll();
});
it('should load contributors', () => {
expect(contributorsState.snapshot.contributors.values).toEqual([
{ isCurrentUser: false, contributor: oldContributors[0] },
@ -78,7 +82,7 @@ describe('ContributorsState', () => {
const response = { contributorId: newContributor.contributorId, isCreated: true };
contributorsService.setup(x => x.postContributor(app, request, version))
.returns(() => of(new Versioned<ContributorAssignedDto>(newVersion, response)));
.returns(() => of(new Versioned(newVersion, response))).verifiable();
contributorsState.assign(request).subscribe();
@ -99,7 +103,7 @@ describe('ContributorsState', () => {
const response = { contributorId: newContributor.contributorId, isCreated: true };
contributorsService.setup(x => x.postContributor(app, request, version))
.returns(() => of(new Versioned<ContributorAssignedDto>(newVersion, response)));
.returns(() => of(new Versioned(newVersion, response))).verifiable();
contributorsState.assign(request).subscribe();
@ -114,7 +118,7 @@ describe('ContributorsState', () => {
it('should remove contributor from snapshot when revoked', () => {
contributorsService.setup(x => x.deleteContributor(app, oldContributors[0].contributorId, version))
.returns(() => of(new Versioned<any>(newVersion, {})));
.returns(() => of(new Versioned(newVersion, {}))).verifiable();
contributorsState.revoke(oldContributors[0]).subscribe();

85
src/Squidex/app/shared/state/contributors.state.ts

@ -7,13 +7,13 @@
import { Injectable } from '@angular/core';
import { Observable, throwError } from 'rxjs';
import { catchError, distinctUntilChanged, map, tap } from 'rxjs/operators';
import { catchError, distinctUntilChanged, map, share } from 'rxjs/operators';
import {
array,
DialogService,
ErrorDto,
ImmutableArray,
notify,
State,
Types,
Version
@ -38,7 +38,7 @@ interface SnapshotContributor {
interface Snapshot {
// All loaded contributors.
contributors: ImmutableArray<SnapshotContributor>;
contributors: ContributorsList;
// Indicates if the maximum number of contributors are reached.
isMaxReached?: boolean;
@ -53,6 +53,8 @@ interface Snapshot {
version: Version;
}
type ContributorsList = ImmutableArray<SnapshotContributor>;
@Injectable()
export class ContributorsState extends State<Snapshot> {
public contributors =
@ -85,49 +87,62 @@ export class ContributorsState extends State<Snapshot> {
this.resetState();
}
return this.contributorsService.getContributors(this.appName).pipe(
tap(dtos => {
if (isReload) {
this.dialogs.notifyInfo('Contributors reloaded.');
}
const stream =
this.contributorsService.getContributors(this.appName).pipe(
map(({ contributors, ...other }) => ({ ...other, contributors: array(contributors.map(x => this.createContributor(x))) })), share());
stream.subscribe(({ version, contributors, maxContributors }) => {
if (isReload) {
this.dialogs.notifyInfo('Contributors reloaded.');
}
const contributors = ImmutableArray.of(dtos.contributors.map(x => this.createContributor(x)));
this.replaceContributors(contributors, version, maxContributors);
}, error => {
this.dialogs.notifyError(error);
});
this.replaceContributors(contributors, dtos.version, dtos.maxContributors);
}),
notify(this.dialogs));
return stream;
}
public revoke(contributor: ContributorDto): Observable<any> {
return this.contributorsService.deleteContributor(this.appName, contributor.contributorId, this.version).pipe(
tap(dto => {
const contributors = this.snapshot.contributors.filter(x => x.contributor.contributorId !== contributor.contributorId);
const stream =
this.contributorsService.deleteContributor(this.appName, contributor.contributorId, this.version).pipe(share());
stream.subscribe(({ version }) => {
const contributors = this.snapshot.contributors.filter(x => x.contributor.contributorId !== contributor.contributorId);
this.replaceContributors(contributors, dto.version);
}),
notify(this.dialogs));
this.replaceContributors(contributors, version);
}, error => {
this.dialogs.notifyError(error);
});
return stream;
}
public assign(request: AssignContributorDto): Observable<boolean | undefined> {
return this.contributorsService.postContributor(this.appName, request, this.version).pipe(
map(dto => {
const contributors = this.updateContributors(dto.payload.contributorId, request.role, dto.version);
this.replaceContributors(contributors, dto.version);
return dto.payload.isCreated;
}),
catchError(error => {
if (Types.is(error, ErrorDto) && error.statusCode === 404) {
return throwError(new ErrorDto(404, 'The user does not exist.'));
} else {
return throwError(error);
}
}),
notify(this.dialogs));
const stream =
this.contributorsService.postContributor(this.appName, request, this.version).pipe(
catchError(error => {
if (Types.is(error, ErrorDto) && error.statusCode === 404) {
return throwError(new ErrorDto(404, 'The user does not exist.'));
} else {
return throwError(error);
}
}),
share());
stream.subscribe(({ payload, version }) => {
const contributors = this.updateContributors(payload.contributorId, request.role);
this.replaceContributors(contributors, version);
}, error => {
this.dialogs.notifyError(error);
});
return stream.pipe(map(x => x.payload.isCreated));
}
private updateContributors(id: string, role: string, version: Version) {
private updateContributors(id: string, role: string) {
const contributor = new ContributorDto(id, role);
const contributors = this.snapshot.contributors;

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

@ -93,7 +93,7 @@ describe('LanguagesState', () => {
const newLanguage = new AppLanguageDto(languageIT.iso2Code, languageIT.englishName, false, false, []);
languagesService.setup(x => x.postLanguage(app, It.isAny(), version))
.returns(() => of(new Versioned<AppLanguageDto>(newVersion, newLanguage)));
.returns(() => of(new Versioned(newVersion, newLanguage)));
languagesState.add(languageIT).subscribe();
@ -120,7 +120,7 @@ describe('LanguagesState', () => {
const request = { isMaster: true, isOptional: false, fallback: [] };
languagesService.setup(x => x.putLanguage(app, oldLanguages[1].iso2Code, request, version))
.returns(() => of(new Versioned<any>(newVersion, {})));
.returns(() => of(new Versioned(newVersion, {})));
languagesState.update(oldLanguages[1], request).subscribe();
@ -144,7 +144,7 @@ describe('LanguagesState', () => {
it('should remove language from snapshot when deleted', () => {
languagesService.setup(x => x.deleteLanguage(app, oldLanguages[1].iso2Code, version))
.returns(() => of(new Versioned<any>(newVersion, {})));
.returns(() => of(new Versioned(newVersion, {})));
languagesState.remove(oldLanguages[1]).subscribe();

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

@ -69,7 +69,7 @@ describe('PatternsState', () => {
const request = { ...newPattern };
patternsService.setup(x => x.postPattern(app, request, version))
.returns(() => of(new Versioned<PatternDto>(newVersion, newPattern)));
.returns(() => of(new Versioned(newVersion, newPattern)));
patternsState.create(request).subscribe();
@ -81,7 +81,7 @@ describe('PatternsState', () => {
const request = { name: 'name2_1', pattern: 'pattern2_1', message: 'message2_1' };
patternsService.setup(x => x.putPattern(app, oldPatterns[1].id, request, version))
.returns(() => of(new Versioned<any>(newVersion, {})));
.returns(() => of(new Versioned(newVersion, {})));
patternsState.update(oldPatterns[1], request).subscribe();
@ -95,7 +95,7 @@ describe('PatternsState', () => {
it('should remove pattern from snapshot when deleted', () => {
patternsService.setup(x => x.deletePattern(app, oldPatterns[0].id, version))
.returns(() => of(new Versioned<any>(newVersion, {})));
.returns(() => of(new Versioned(newVersion, {})));
patternsState.delete(oldPatterns[0]).subscribe();

5
src/Squidex/app/shared/state/plans.state.spec.ts

@ -11,7 +11,6 @@ import { IMock, It, Mock, Times } from 'typemoq';
import {
DialogService,
PlanChangedDto,
PlanDto,
PlansDto,
PlansService,
@ -96,7 +95,7 @@ describe('PlansState', () => {
const result = { redirectUri: 'http://url' };
plansService.setup(x => x.putPlan(app, It.isAny(), version))
.returns(() => of(new Versioned<PlanChangedDto>(newVersion, result)));
.returns(() => of(new Versioned(newVersion, result)));
plansState.load().subscribe();
plansState.change('free').pipe(onErrorResumeNext()).subscribe();
@ -113,7 +112,7 @@ describe('PlansState', () => {
plansState.window = <any>{ location: {} };
plansService.setup(x => x.putPlan(app, It.isAny(), version))
.returns(() => of(new Versioned<PlanChangedDto>(newVersion, { redirectUri: '' })));
.returns(() => of(new Versioned(newVersion, { redirectUri: '' })));
plansState.load().subscribe();
plansState.change('id2_yearly').pipe(onErrorResumeNext()).subscribe();

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

@ -70,7 +70,7 @@ describe('RolesState', () => {
const request = { name: newRole.name };
rolesService.setup(x => x.postRole(app, request, version))
.returns(() => of(new Versioned<RoleDto>(newVersion, newRole)));
.returns(() => of(new Versioned(newVersion, newRole)));
rolesState.add(request).subscribe();
@ -82,7 +82,7 @@ describe('RolesState', () => {
const request = { permissions: ['P4', 'P5'] };
rolesService.setup(x => x.putRole(app, oldRoles[1].name, request, version))
.returns(() => of(new Versioned<any>(newVersion, {})));
.returns(() => of(new Versioned(newVersion, {})));
rolesState.update(oldRoles[1], request).subscribe();
@ -94,7 +94,7 @@ describe('RolesState', () => {
it('should remove role from snapshot when deleted', () => {
rolesService.setup(x => x.deleteRole(app, oldRoles[0].name, version))
.returns(() => of(new Versioned<any>(newVersion, {})));
.returns(() => of(new Versioned(newVersion, {})));
rolesState.delete(oldRoles[0]).subscribe();

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

@ -86,7 +86,7 @@ describe('RulesState', () => {
const newAction = {};
rulesService.setup(x => x.putRule(app, oldRules[0].id, It.is<UpdateRuleDto>(() => true), version))
.returns(() => of(new Versioned<any>(newVersion, {})));
.returns(() => of(new Versioned(newVersion, {})));
rulesState.updateAction(oldRules[0], newAction, modified).subscribe();
@ -100,7 +100,7 @@ describe('RulesState', () => {
const newTrigger = {};
rulesService.setup(x => x.putRule(app, oldRules[0].id, It.is<UpdateRuleDto>(() => true), version))
.returns(() => of(new Versioned<any>(newVersion, {})));
.returns(() => of(new Versioned(newVersion, {})));
rulesState.updateTrigger(oldRules[0], newTrigger, modified).subscribe();
@ -112,7 +112,7 @@ describe('RulesState', () => {
it('should mark as enabled and update and user info when enabled', () => {
rulesService.setup(x => x.enableRule(app, oldRules[0].id, version))
.returns(() => of(new Versioned<any>(newVersion, {})));
.returns(() => of(new Versioned(newVersion, {})));
rulesState.enable(oldRules[0], modified).subscribe();
@ -124,7 +124,7 @@ describe('RulesState', () => {
it('should mark as disabled and update and user info when disabled', () => {
rulesService.setup(x => x.disableRule(app, oldRules[1].id, version))
.returns(() => of(new Versioned<any>(newVersion, {})));
.returns(() => of(new Versioned(newVersion, {})));
rulesState.disable(oldRules[1], modified).subscribe();
@ -136,7 +136,7 @@ describe('RulesState', () => {
it('should remove rule from snapshot when deleted', () => {
rulesService.setup(x => x.deleteRule(app, oldRules[0].id, version))
.returns(() => of(new Versioned<any>(newVersion, {})));
.returns(() => of(new Versioned(newVersion, {})));
rulesState.delete(oldRules[0]).subscribe();

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

@ -168,7 +168,7 @@ describe('SchemasState', () => {
it('should mark published and update user info when published', () => {
schemasService.setup(x => x.publishSchema(app, oldSchemas[0].name, version))
.returns(() => of(new Versioned<any>(newVersion, {})));
.returns(() => of(new Versioned(newVersion, {})));
schemasState.publish(oldSchemas[0], modified).subscribe();
@ -180,7 +180,7 @@ describe('SchemasState', () => {
it('should unmark published and update user info when unpublished', () => {
schemasService.setup(x => x.unpublishSchema(app, oldSchemas[1].name, version))
.returns(() => of(new Versioned<any>(newVersion, {})));
.returns(() => of(new Versioned(newVersion, {})));
schemasState.unpublish(oldSchemas[1], modified).subscribe();
@ -194,7 +194,7 @@ describe('SchemasState', () => {
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<any>(newVersion, {})));
.returns(() => of(new Versioned(newVersion, {})));
schemasState.changeCategory(oldSchemas[0], category, modified).subscribe();
@ -211,7 +211,7 @@ describe('SchemasState', () => {
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<any>(newVersion, {})));
.returns(() => of(new Versioned(newVersion, {})));
schemasState.publish(schema, modified).subscribe();
@ -225,7 +225,7 @@ describe('SchemasState', () => {
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<any>(newVersion, {})));
.returns(() => of(new Versioned(newVersion, {})));
schemasState.changeCategory(oldSchemas[0], category, modified).subscribe();
@ -239,7 +239,7 @@ describe('SchemasState', () => {
const request = { label: 'name2_label', hints: 'name2_hints' };
schemasService.setup(x => x.putSchema(app, schema.name, It.isAny(), version))
.returns(() => of(new Versioned<any>(newVersion, {})));
.returns(() => of(new Versioned(newVersion, {})));
schemasState.update(schema, request, modified).subscribe();
@ -254,7 +254,7 @@ describe('SchemasState', () => {
const request = { query: '<query-script>' };
schemasService.setup(x => x.putScripts(app, schema.name, It.isAny(), version))
.returns(() => of(new Versioned<any>(newVersion, {})));
.returns(() => of(new Versioned(newVersion, {})));
schemasState.configureScripts(schema, request, modified).subscribe();
@ -268,7 +268,7 @@ describe('SchemasState', () => {
const request = { web: 'url' };
schemasService.setup(x => x.putPreviewUrls(app, schema.name, It.isAny(), version))
.returns(() => of(new Versioned<any>(newVersion, {})));
.returns(() => of(new Versioned(newVersion, {})));
schemasState.configurePreviewUrls(schema, request, modified).subscribe();
@ -294,7 +294,7 @@ describe('SchemasState', () => {
it('should remove schema from snapshot when deleted', () => {
schemasService.setup(x => x.deleteSchema(app, schema.name, version))
.returns(() => of(new Versioned<any>(newVersion, {})));
.returns(() => of(new Versioned(newVersion, {})));
schemasState.delete(schema).subscribe();
@ -308,7 +308,7 @@ describe('SchemasState', () => {
const newField = new RootFieldDto(3, '3', createProperties('String'), 'invariant');
schemasService.setup(x => x.postField(app, schema.name, It.isAny(), undefined, version))
.returns(() => of(new Versioned<RootFieldDto>(newVersion, newField)));
.returns(() => of(new Versioned(newVersion, newField)));
schemasState.addField(schema, request, undefined, modified).subscribe();
@ -324,7 +324,7 @@ describe('SchemasState', () => {
const newField = new NestedFieldDto(3, '3', createProperties('String'), 2);
schemasService.setup(x => x.postField(app, schema.name, It.isAny(), 2, version))
.returns(() => of(new Versioned<NestedFieldDto>(newVersion, newField)));
.returns(() => of(new Versioned(newVersion, newField)));
schemasState.addField(schema, request, field2, modified).subscribe();
@ -336,7 +336,7 @@ describe('SchemasState', () => {
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<any>(newVersion, {})));
.returns(() => of(new Versioned(newVersion, {})));
schemasState.deleteField(schema, field1, modified).subscribe();
@ -348,7 +348,7 @@ describe('SchemasState', () => {
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<any>(newVersion, {})));
.returns(() => of(new Versioned(newVersion, {})));
schemasState.deleteField(schema, nested1, modified).subscribe();
@ -360,7 +360,7 @@ describe('SchemasState', () => {
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<any>(newVersion, {})));
.returns(() => of(new Versioned(newVersion, {})));
schemasState.sortFields(schema, [field2, field1], undefined, modified).subscribe();
@ -372,7 +372,7 @@ describe('SchemasState', () => {
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<any>(newVersion, {})));
.returns(() => of(new Versioned(newVersion, {})));
schemasState.sortFields(schema, [nested2, nested1], field2, modified).subscribe();
@ -386,7 +386,7 @@ describe('SchemasState', () => {
const request = { properties: createProperties('String') };
schemasService.setup(x => x.putField(app, schema.name, field1.fieldId, request, undefined, version))
.returns(() => of(new Versioned<any>(newVersion, {})));
.returns(() => of(new Versioned(newVersion, {})));
schemasState.updateField(schema, field1, request, modified).subscribe();
@ -400,7 +400,7 @@ describe('SchemasState', () => {
const request = { properties: createProperties('String') };
schemasService.setup(x => x.putField(app, schema.name, nested1.fieldId, request, 2, version))
.returns(() => of(new Versioned<any>(newVersion, {})));
.returns(() => of(new Versioned(newVersion, {})));
schemasState.updateField(schema, nested1, request, modified).subscribe();
@ -412,7 +412,7 @@ describe('SchemasState', () => {
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<any>(newVersion, {})));
.returns(() => of(new Versioned(newVersion, {})));
schemasState.hideField(schema, field1, modified).subscribe();
@ -424,7 +424,7 @@ describe('SchemasState', () => {
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<any>(newVersion, {})));
.returns(() => of(new Versioned(newVersion, {})));
schemasState.hideField(schema, nested1, modified).subscribe();
@ -436,7 +436,7 @@ describe('SchemasState', () => {
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<any>(newVersion, {})));
.returns(() => of(new Versioned(newVersion, {})));
schemasState.disableField(schema, field1, modified).subscribe();
@ -448,7 +448,7 @@ describe('SchemasState', () => {
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<any>(newVersion, {})));
.returns(() => of(new Versioned(newVersion, {})));
schemasState.disableField(schema, nested1, modified).subscribe();
@ -460,7 +460,7 @@ describe('SchemasState', () => {
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<any>(newVersion, {})));
.returns(() => of(new Versioned(newVersion, {})));
schemasState.lockField(schema, field1, modified).subscribe();
@ -472,7 +472,7 @@ describe('SchemasState', () => {
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<any>(newVersion, {})));
.returns(() => of(new Versioned(newVersion, {})));
schemasState.lockField(schema, nested1, modified).subscribe();
@ -484,7 +484,7 @@ describe('SchemasState', () => {
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<any>(newVersion, {})));
.returns(() => of(new Versioned(newVersion, {})));
schemasState.showField(schema, field2, modified).subscribe();
@ -496,7 +496,7 @@ describe('SchemasState', () => {
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<any>(newVersion, {})));
.returns(() => of(new Versioned(newVersion, {})));
schemasState.showField(schema, nested2, modified).subscribe();
@ -508,7 +508,7 @@ describe('SchemasState', () => {
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<any>(newVersion, {})));
.returns(() => of(new Versioned(newVersion, {})));
schemasState.enableField(schema, field2, modified).subscribe();
@ -520,7 +520,7 @@ describe('SchemasState', () => {
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<any>(newVersion, {})));
.returns(() => of(new Versioned(newVersion, {})));
schemasState.enableField(schema, nested2, modified).subscribe();

Loading…
Cancel
Save