Browse Source

Tests fixed and state for preview urls.

pull/337/head
Sebastian Stehle 8 years ago
parent
commit
f5c48da923
  1. 24
      src/Squidex/app/shared/services/schemas.service.spec.ts
  2. 13
      src/Squidex/app/shared/services/schemas.service.ts
  3. 2
      src/Squidex/app/shared/state/comments.state.spec.ts
  4. 21
      src/Squidex/app/shared/state/schemas.state.spec.ts
  5. 17
      src/Squidex/app/shared/state/schemas.state.ts

24
src/Squidex/app/shared/services/schemas.service.spec.ts

@ -147,6 +147,9 @@ describe('SchemasService', () => {
label: 'label1', label: 'label1',
hints: 'hints1' hints: 'hints1'
}, },
previewUrls: {
'Default': 'url'
},
fields: [ fields: [
{ {
fieldId: 11, fieldId: 11,
@ -312,6 +315,9 @@ describe('SchemasService', () => {
new RootFieldDto(19, 'field19', createProperties('String'), 'language', true, true, true), new RootFieldDto(19, 'field19', createProperties('String'), 'language', true, true, true),
new RootFieldDto(20, 'field20', createProperties('Tags'), 'language', true, true, true) new RootFieldDto(20, 'field20', createProperties('Tags'), 'language', true, true, true)
], ],
{
'Default': 'url'
},
'<script-query>', '<script-query>',
'<script-create>', '<script-create>',
'<script-update>', '<script-update>',
@ -343,8 +349,7 @@ describe('SchemasService', () => {
} }
}); });
expect(schema!).toEqual( expect(schema!).toEqual(new SchemaDetailsDto('1', dto.name, '', new SchemaPropertiesDto(), true, false, now, user, now, user, new Version('2'), [], {}));
new SchemaDetailsDto('1', dto.name, '', new SchemaPropertiesDto(), true, false, now, user, now, user, new Version('2'), []));
})); }));
it('should make put request to update schema', it('should make put request to update schema',
@ -392,6 +397,21 @@ describe('SchemasService', () => {
req.flush({}); req.flush({});
})); }));
it('should make put request to update preview urls',
inject([SchemasService, HttpTestingController], (schemasService: SchemasService, httpMock: HttpTestingController) => {
const dto = {};
schemasService.putPreviewUrls('my-app', 'my-schema', dto, version).subscribe();
const req = httpMock.expectOne('http://service/p/api/apps/my-app/schemas/my-schema/preview-urls');
expect(req.request.method).toEqual('PUT');
expect(req.request.headers.get('If-Match')).toBe(version.value);
req.flush({});
}));
it('should make post request to add field', it('should make post request to add field',
inject([SchemasService, HttpTestingController], (schemasService: SchemasService, httpMock: HttpTestingController) => { inject([SchemasService, HttpTestingController], (schemasService: SchemasService, httpMock: HttpTestingController) => {

13
src/Squidex/app/shared/services/schemas.service.ts

@ -64,6 +64,7 @@ export class SchemaDetailsDto extends SchemaDto {
lastModifiedBy: string, lastModifiedBy: string,
version: Version, version: Version,
public readonly fields: RootFieldDto[], public readonly fields: RootFieldDto[],
public readonly previewUrls: { [name: string]: string },
public readonly scriptQuery?: string, public readonly scriptQuery?: string,
public readonly scriptCreate?: string, public readonly scriptCreate?: string,
public readonly scriptUpdate?: string, public readonly scriptUpdate?: string,
@ -317,6 +318,7 @@ export class SchemasService {
DateTime.parseISO_UTC(body.lastModified), body.lastModifiedBy, DateTime.parseISO_UTC(body.lastModified), body.lastModifiedBy,
response.version, response.version,
fields, fields,
body.previewUrls || {},
body.scriptQuery, body.scriptQuery,
body.scriptCreate, body.scriptCreate,
body.scriptUpdate, body.scriptUpdate,
@ -346,6 +348,7 @@ export class SchemasService {
now, user, now, user,
response.version, response.version,
dto.fields || [], dto.fields || [],
{},
body.scriptQuery, body.scriptQuery,
body.scriptCreate, body.scriptCreate,
body.scriptUpdate, body.scriptUpdate,
@ -418,6 +421,16 @@ export class SchemasService {
pretifyError('Failed to change category. Please reload.')); pretifyError('Failed to change category. Please reload.'));
} }
public putPreviewUrls(appName: string, schemaName: string, dto: { [name: string]: string }, version: Version): Observable<Versioned<any>> {
const url = this.apiUrl.buildUrl(`api/apps/${appName}/schemas/${schemaName}/preview-urls`);
return HTTP.putVersioned(this.http, url, dto, version).pipe(
tap(() => {
this.analytics.trackEvent('Schema', 'PreviewUrlsConfigured', appName);
}),
pretifyError('Failed to configure preview urls. Please reload.'));
}
public postField(appName: string, schemaName: string, dto: AddFieldDto, parentId: number | undefined, version: Version): Observable<Versioned<RootFieldDto | NestedFieldDto>> { public postField(appName: string, schemaName: string, dto: AddFieldDto, parentId: number | undefined, version: Version): Observable<Versioned<RootFieldDto | NestedFieldDto>> {
const url = this.buildUrl(appName, schemaName, parentId, ''); const url = this.buildUrl(appName, schemaName, parentId, '');

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

@ -47,7 +47,7 @@ describe('CommentsState', () => {
commentsService = Mock.ofType<CommentsService>(); commentsService = Mock.ofType<CommentsService>();
commentsService.setup(x => x.getComments(app, commentsId, new Version(''))) commentsService.setup(x => x.getComments(app, commentsId, new Version('-1')))
.returns(() => of(oldComments)); .returns(() => of(oldComments));
commentsState = new CommentsState(appsState.object, commentsId, commentsService.object, dialogs.object); commentsState = new CommentsState(appsState.object, commentsId, commentsService.object, dialogs.object);

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

@ -56,7 +56,8 @@ describe('SchemasState', () => {
creation, creator, creation, creator,
creation, creator, creation, creator,
version, version,
[field1, field2]); [field1, field2],
{});
let dialogs: IMock<DialogService>; let dialogs: IMock<DialogService>;
let appsState: IMock<AppsState>; let appsState: IMock<AppsState>;
@ -263,6 +264,22 @@ describe('SchemasState', () => {
expectToBeModified(schema_1); expectToBeModified(schema_1);
}); });
it('should update script properties and update user info when preview urls configured', () => {
const request = {
'Default': 'url'
};
schemasService.setup(x => x.putPreviewUrls(app, schema.name, It.isAny(), version))
.returns(() => of(new Versioned<any>(newVersion, {})));
schemasState.configurePreviewUrls(schema, request, modified).subscribe();
const schema_1 = <SchemaDetailsDto>schemasState.snapshot.schemas.at(1);
expect(schema_1.previewUrls).toEqual(request);
expectToBeModified(schema_1);
});
it('should update script properties and update user info when scripts configured', () => { 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');
@ -284,7 +301,7 @@ describe('SchemasState', () => {
it('should add schema to snapshot 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, false, modified, modifier, modified, modifier, version, []); const result = new SchemaDetailsDto('id4', 'newName', '', {}, false, false, modified, modifier, modified, modifier, version, [], {});
schemasService.setup(x => x.postSchema(app, request, modifier, modified)) schemasService.setup(x => x.postSchema(app, request, modifier, modified))
.returns(() => of(result)); .returns(() => of(result));

17
src/Squidex/app/shared/state/schemas.state.ts

@ -191,6 +191,14 @@ export class SchemasState extends State<Snapshot> {
notify(this.dialogs)); notify(this.dialogs));
} }
public configurePreviewUrls(schema: SchemaDetailsDto, request: { [name: string]: string }, now?: DateTime): Observable<any> {
return this.schemasService.putPreviewUrls(this.appName, schema.name, request, schema.version).pipe(
tap(dto => {
this.replaceSchema(configurePreviewUrls(schema, request, this.user, dto.version, now));
}),
notify(this.dialogs));
}
public configureScripts(schema: SchemaDetailsDto, request: UpdateSchemaScriptsDto, now?: DateTime): Observable<any> { public configureScripts(schema: SchemaDetailsDto, request: UpdateSchemaScriptsDto, now?: DateTime): Observable<any> {
return this.schemasService.putScripts(this.appName, schema.name, request, schema.version).pipe( return this.schemasService.putScripts(this.appName, schema.name, request, schema.version).pipe(
tap(dto => { tap(dto => {
@ -370,7 +378,6 @@ const setPublished = <T extends SchemaDto>(schema: T, isPublished: boolean, user
version version
}); });
const changeCategory = <T extends SchemaDto>(schema: T, category: string, user: string, version: Version, now?: DateTime) => const changeCategory = <T extends SchemaDto>(schema: T, category: string, user: string, version: Version, now?: DateTime) =>
<T>schema.with({ <T>schema.with({
category, category,
@ -379,6 +386,14 @@ const changeCategory = <T extends SchemaDto>(schema: T, category: string, user:
version version
}); });
const configurePreviewUrls = (schema: SchemaDetailsDto, previewUrls: { [name: string]: string }, user: string, version: Version, now?: DateTime) =>
schema.with({
previewUrls,
lastModified: now || DateTime.now(),
lastModifiedBy: user,
version
});
const configureScripts = (schema: SchemaDetailsDto, scripts: UpdateSchemaScriptsDto, user: string, version: Version, now?: DateTime) => const configureScripts = (schema: SchemaDetailsDto, scripts: UpdateSchemaScriptsDto, user: string, version: Version, now?: DateTime) =>
schema.with({ schema.with({
...scripts, ...scripts,

Loading…
Cancel
Save