Browse Source

UI completed.

pull/98/head
Sebastian Stehle 8 years ago
parent
commit
86e21d688b
  1. 141
      src/Squidex/app/features/webhooks/pages/webhook.component.html
  2. 122
      src/Squidex/app/features/webhooks/pages/webhook.component.ts
  3. 2
      src/Squidex/app/features/webhooks/pages/webhooks-page.component.html
  4. 15
      src/Squidex/app/features/webhooks/pages/webhooks-page.component.ts
  5. 8
      src/Squidex/app/shared/services/app-clients.service.spec.ts
  6. 6
      src/Squidex/app/shared/services/app-contributors.service.spec.ts
  7. 8
      src/Squidex/app/shared/services/app-languages.service.spec.ts
  8. 6
      src/Squidex/app/shared/services/assets.service.spec.ts
  9. 2
      src/Squidex/app/shared/services/schemas.service.spec.ts
  10. 112
      src/Squidex/app/shared/services/webhooks.service.spec.ts
  11. 2
      src/Squidex/app/shared/services/webhooks.service.ts

141
src/Squidex/app/features/webhooks/pages/webhook.component.html

@ -1,50 +1,52 @@
<div class="table-items-row">
<table class="table table-middle table-sm table-borderless table-fixed">
<colgroup>
<col style="width: 120px; text-align: right;" />
<col style="width: 100%" />
<col style="width: 40px" />
</colgroup>
<form [formGroup]="webhookForm" (ngSubmit)="save()">
<table class="table table-middle table-sm table-borderless table-fixed">
<colgroup>
<col style="width: 120px; text-align: right;" />
<col style="width: 100%" />
<col style="width: 40px" />
</colgroup>
<tr>
<td class="text-right" colspan="2">
<button class="btn btn-primary" [disabled]="!hasUrl">Save</button>
</td>
<td class="client-delete">
<button type="button" class="btn btn-link btn-danger"
(sqxConfirmClick)="deleting.emit()"
confirmTitle="Delete webhook"
confirmText="Do you really want to delete the webhook?">
<i class="icon-bin2"></i>
</button>
</td>
</tr>
<tr>
<td>Url:</td>
<td>
<input class="form-control" [attr.value]="webhook.url" #inputUrl />
</td>
<td>
<button type="button" class="btn btn-primary btn-link" [sqxCopy]="inputUrl">
<i class="icon-copy"></i>
</button>
</td>
</tr>
<tr>
<td>Secret:</td>
<td>
<input readonly class="form-control" [attr.value]="webhook.sharedSecret" #inputSecret />
</td>
<td>
<button type="button" class="btn btn-primary btn-link" [sqxCopy]="inputSecret">
<i class="icon-copy"></i>
</button>
</td>
</tr>
</table>
<tr>
<td class="text-right" colspan="2">
<button type="submit" class="btn btn-primary" [disabled]="!hasUrl">Save</button>
</td>
<td class="client-delete">
<button type="button" class="btn btn-link btn-danger"
(sqxConfirmClick)="deleting.emit()"
confirmTitle="Delete webhook"
confirmText="Do you really want to delete the webhook?">
<i class="icon-bin2"></i>
</button>
</td>
</tr>
<tr>
<td>Url:</td>
<td>
<input class="form-control" formControlName="url" [attr.value]="webhook.url" #inputUrl />
</td>
<td>
<button type="button" class="btn btn-primary btn-link" [sqxCopy]="inputUrl">
<i class="icon-copy"></i>
</button>
</td>
</tr>
<tr>
<td>Secret:</td>
<td>
<input readonly class="form-control" [attr.value]="webhook.sharedSecret" #inputSecret />
</td>
<td>
<button type="button" class="btn btn-primary btn-link" [sqxCopy]="inputSecret">
<i class="icon-copy"></i>
</button>
</td>
</tr>
</table>
</form>
<div class="webhook-section">
<table *ngIf="schemas.length > 0" class="table table-middle table-sm table-fixed table-borderless">
<div class="webhook-section" *ngIf="schemas.length > 0">
<table class="table table-middle table-sm table-fixed table-borderless">
<colgroup>
<col style="width: 100%" />
<col style="width: 40px" />
@ -53,23 +55,29 @@
<col style="width: 40px" />
<col style="width: 40px" />
<col style="width: 40px" />
<col style="width: 40px" />
</colgroup>
<tr>
<th>Schema</th>
<th title="Created">
<th>
Schema
</th>
<th class="text-center" title="All">
All
</th>
<th class="text-center" title="Created">
C
</th>
<th title="Updated">
<th class="text-center" title="Updated">
U
</th>
<th title="Deleted">
<th class="text-center" title="Deleted">
D
</th>
<th title="Published">
<th class="text-center" title="Published">
P
</th>
<th title="Unpublished">
<th class="text-center" title="Unpublished">
U
</th>
<th></th>
@ -79,35 +87,40 @@
<td>
<span class="truncate">{{schema.schema.name}}</span>
</td>
<td title="Created">
<input type="checkbox" [(ngModel)]="schema.sendCreate" />
<td class="text-center" title="Created">
<input type="checkbox" [ngModel]="schema.sendAll" (ngModelChange)="toggleAll(schema)" />
</td>
<td title="Updated">
<input type="checkbox" [(ngModel)]="schema.sendUpdate" />
<td class="text-center" title="Created">
<input type="checkbox" [ngModel]="schema.sendCreate" (ngModelChange)="toggle(schema, 'sendCreate')" />
</td>
<td title="Deleted">
<input type="checkbox" [(ngModel)]="schema.sendDelete" />
<td class="text-center" title="Updated">
<input type="checkbox" [ngModel]="schema.sendUpdate" (ngModelChange)="toggle(schema, 'sendUpdate')" />
</td>
<td title="Published">
<input type="checkbox" [(ngModel)]="schema.sendPublish" />
<td class="text-center" title="Deleted">
<input type="checkbox" [ngModel]="schema.sendDelete" (ngModelChange)="toggle(schema, 'sendDelete')" />
</td>
<td title="Unpublished">
<input type="checkbox" [(ngModel)]="schema.sendUnpublish" />
<td class="text-center" title="Published">
<input type="checkbox" [ngModel]="schema.sendPublish" (ngModelChange)="toggle(schema, 'sendPublish')" />
</td>
<td class="text-center" title="Unpublished">
<input type="checkbox" [ngModel]="schema.sendUnpublish" (ngModelChange)="toggle(schema, 'sendUnpublish')" />
</td>
<td class="text-center">
<button type="button" class="btn btn-link btn-danger"
<button type="button" class="btn btn-link btn-secondary"
(sqxConfirmClick)="removeSchema(schema)"
confirmTitle="Remove schema"
confirmText="Do you really want to remove the schema?">
<i class="icon-bin2"></i>
<i class="icon-close"></i>
</button>
</td>
</tr>
</table>
</div>
<form class="form-inline" [formGroup]="addSchemaForm" (ngSubmit)="addSchema()">
<div class="webhook-section" *ngIf="schemasToAdd.length > 0">
<form class="form-inline" (ngSubmit)="addSchema()">
<div class="form-group mr-1">
<select class="form-control schemas-control" formControlName="schema">
<select class="form-control schemas-control" [(ngModel)]="schemaToAdd" name="schema">
<option *ngFor="let schema of schemasToAdd" [ngValue]="schema">{{schema.name}}</option>
</select>
</div>

122
src/Squidex/app/features/webhooks/pages/webhook.component.ts

@ -12,11 +12,13 @@ import {
ImmutableArray,
SchemaDto,
UpdateWebhookDto,
WebhookDto
WebhookDto,
WebhookSchemaDto
} from 'shared';
interface WebhookSchemaForm {
export interface WebhookSchemaForm {
schema: SchemaDto;
sendAll: boolean;
sendCreate: boolean;
sendUpdate: boolean;
sendDelete: boolean;
@ -44,9 +46,9 @@ export class WebhookComponent implements OnInit {
public schemas: ImmutableArray<WebhookSchemaForm>;
public schemaToAdd: SchemaDto;
public schemasToAdd: ImmutableArray<SchemaDto>;
public webhookFormSubmitted = false;
public webhookForm =
this.formBuilder.group({
url: ['',
@ -55,17 +57,12 @@ export class WebhookComponent implements OnInit {
]]
});
public addSchemaForm =
this.formBuilder.group({
schema: [null]
});
public get hasUrl() {
return this.webhookForm.controls['url'].value && this.webhookForm.controls['url'].value.length > 0;
}
public get hasSchema() {
return this.addSchemaForm.controls['schema'].value;
return !!this.schemaToAdd;
}
constructor(
@ -76,54 +73,109 @@ export class WebhookComponent implements OnInit {
public ngOnInit() {
this.webhookForm.controls['url'].setValue(this.webhook.url);
this.schemasToAdd =
ImmutableArray.of(
this.allSchemas.filter(schema =>
!this.webhook.schemas.find(w => w.schemaId === schema.id)))
.sortByStringAsc(x => x.name);
this.schemas =
ImmutableArray.of(
this.webhook.schemas.map(webhookSchema => {
const schema = this.allSchemas.find(s => s.id === webhookSchema.schemaId);
if (schema) {
return {
return this.updateSendAll({
schema: schema,
sendAll: false,
sendCreate: webhookSchema.sendCreate,
sendUpdate: webhookSchema.sendUpdate,
sendDelete: webhookSchema.sendDelete,
sendPublish: webhookSchema.sendPublish,
sendUnpublish: webhookSchema.sendUnpublish
};
});
} else {
return null;
}
}).filter(w => !!w)).sortByStringAsc(x => x.schema.name);
this.addSchemaForm.controls['schema'].setValue(this.schemasToAdd.find(x => true));
this.schemasToAdd =
ImmutableArray.of(
this.allSchemas.filter(schema =>
!this.webhook.schemas.find(w => w.schemaId === schema.id)))
.sortByStringAsc(x => x.name);
this.schemaToAdd = this.schemasToAdd.values[0];
}
public removeSchema(webhookSchema: WebhookSchemaForm) {
this.schemasToAdd = this.schemasToAdd.push(webhookSchema.schema).sortByStringAsc(x => x.name);
this.schemas = this.schemas.remove(webhookSchema);
public removeSchema(schemaForm: WebhookSchemaForm) {
this.schemas = this.schemas.remove(schemaForm);
this.addSchemaForm.controls['schema'].setValue(this.schemasToAdd.find(x => true));
this.schemasToAdd = this.schemasToAdd.push(schemaForm.schema).sortByStringAsc(x => x.name);
this.schemaToAdd = this.schemasToAdd.values[0];
}
public addSchema() {
const schema: SchemaDto = this.addSchemaForm.controls['schema'].value;
this.schemasToAdd = this.schemasToAdd.remove(schema).sortByStringAsc(x => x.name);
this.schemas = this.schemas.push({
schema: schema,
sendCreate: false,
sendUpdate: false,
sendDelete: false,
sendPublish: false,
sendUnpublish: false
}).sortByStringAsc(x => x.schema.name);
this.addSchemaForm.controls['schema'].setValue(this.schemasToAdd.find(x => true));
this.schemas =
this.schemas.push(
this.updateSendAll({
schema: this.schemaToAdd,
sendAll: false,
sendCreate: false,
sendUpdate: false,
sendDelete: false,
sendPublish: false,
sendUnpublish: false
})).sortByStringAsc(x => x.schema.name);
this.schemasToAdd = this.schemasToAdd.remove(this.schemaToAdd).sortByStringAsc(x => x.name);
this.schemaToAdd = this.schemasToAdd.values[0];
}
public save() {
const requestDto =
new UpdateWebhookDto(
this.webhookForm.controls['url'].value,
this.schemas.values.map(schema =>
new WebhookSchemaDto(
schema.schema.id,
schema.sendCreate,
schema.sendUpdate,
schema.sendDelete,
schema.sendPublish,
schema.sendUnpublish)));
this.emitUpdating(requestDto);
}
public toggle(schemaForm: WebhookSchemaForm, property: string) {
const newSchema = this.updateSendAll(Object.assign({}, schemaForm, { [property]: !schemaForm[property] }));
this.schemas = this.schemas.replace(schemaForm, newSchema);
}
public toggleAll(schemaForm: WebhookSchemaForm) {
const newSchema = this.updateAll(<any>{ schema: schemaForm.schema }, !schemaForm.sendAll);
this.schemas = this.schemas.replace(schemaForm, newSchema);
}
private emitUpdating(dto: UpdateWebhookDto) {
this.updating.emit(dto);
}
private updateAll(schemaForm: WebhookSchemaForm, value: boolean): WebhookSchemaForm {
schemaForm.sendAll = value;
schemaForm.sendCreate = value;
schemaForm.sendUpdate = value;
schemaForm.sendDelete = value;
schemaForm.sendPublish = value;
schemaForm.sendUnpublish = value;
return schemaForm;
}
private updateSendAll(schemaForm: WebhookSchemaForm): WebhookSchemaForm {
schemaForm.sendAll =
schemaForm.sendCreate &&
schemaForm.sendUpdate &&
schemaForm.sendDelete &&
schemaForm.sendPublish &&
schemaForm.sendUnpublish;
return schemaForm;
}
}

2
src/Squidex/app/features/webhooks/pages/webhooks-page.component.html

@ -27,7 +27,7 @@
<div *ngIf="webhooks">
<sqx-webhook *ngFor="let webhook of webhooks" [webhook]="webhook" [allSchemas]="schemas"
(updating)="deleteWebhook(webhook)"
(updating)="updateWebhook(webhook, $event)"
(deleting)="deleteWebhook(webhook)"></sqx-webhook>
<div class="table-items-footer">

15
src/Squidex/app/features/webhooks/pages/webhooks-page.component.ts

@ -20,7 +20,8 @@ import {
SchemasService,
Version,
WebhookDto,
WebhooksService
WebhooksService,
UpdateWebhookDto
} from 'shared';
@Component({
@ -86,6 +87,18 @@ export class WebhooksPageComponent extends AppComponentBase implements OnInit {
});
}
public updateWebhook(webhook: WebhookDto, requestDto: UpdateWebhookDto) {
this.appNameOnce()
.switchMap(app => this.webhooksService.putWebhook(app, webhook.id, requestDto, webhook.version))
.subscribe(dto => {
this.webhooks = this.webhooks.replace(webhook, webhook.update(requestDto, this.authService.user.token));
this.notifyInfo('Webhook saved.');
}, error => {
this.notifyError(error);
});
}
public addWebhook() {
this.addWebhookFormSubmitted = true;

8
src/Squidex/app/shared/services/app-clients.service.spec.ts

@ -65,7 +65,7 @@ describe('AppClientsService', () => {
const req = httpMock.expectOne('http://service/p/api/apps/my-app/clients');
expect(req.request.method).toEqual('GET');
expect(req.request.headers.get('If-Match')).toEqual('1');
expect(req.request.headers.get('If-Match')).toEqual(version.value);
req.flush([
{
@ -103,7 +103,7 @@ describe('AppClientsService', () => {
const req = httpMock.expectOne('http://service/p/api/apps/my-app/clients');
expect(req.request.method).toEqual('POST');
expect(req.request.headers.get('If-Match')).toEqual('1');
expect(req.request.headers.get('If-Match')).toEqual(version.value);
req.flush({ id: 'client1', name: 'Client 1', secret: 'secret1', isReader: true });
@ -121,7 +121,7 @@ describe('AppClientsService', () => {
const req = httpMock.expectOne('http://service/p/api/apps/my-app/clients/client1');
expect(req.request.method).toEqual('PUT');
expect(req.request.headers.get('If-Match')).toEqual('1');
expect(req.request.headers.get('If-Match')).toEqual(version.value);
req.flush({});
}));
@ -134,7 +134,7 @@ describe('AppClientsService', () => {
const req = httpMock.expectOne('http://service/p/api/apps/my-app/clients/client1');
expect(req.request.method).toEqual('DELETE');
expect(req.request.headers.get('If-Match')).toEqual('1');
expect(req.request.headers.get('If-Match')).toEqual(version.value);
req.flush({});
}));

6
src/Squidex/app/shared/services/app-contributors.service.spec.ts

@ -56,7 +56,7 @@ describe('AppContributorsService', () => {
const req = httpMock.expectOne('http://service/p/api/apps/my-app/contributors');
expect(req.request.method).toEqual('GET');
expect(req.request.headers.get('If-Match')).toEqual('1');
expect(req.request.headers.get('If-Match')).toEqual(version.value);
req.flush({
contributors: [
@ -89,7 +89,7 @@ describe('AppContributorsService', () => {
const req = httpMock.expectOne('http://service/p/api/apps/my-app/contributors');
expect(req.request.method).toEqual('POST');
expect(req.request.headers.get('If-Match')).toEqual('1');
expect(req.request.headers.get('If-Match')).toEqual(version.value);
req.flush({});
}));
@ -102,7 +102,7 @@ describe('AppContributorsService', () => {
const req = httpMock.expectOne('http://service/p/api/apps/my-app/contributors/123');
expect(req.request.method).toEqual('DELETE');
expect(req.request.headers.get('If-Match')).toEqual('1');
expect(req.request.headers.get('If-Match')).toEqual(version.value);
req.flush({});
}));

8
src/Squidex/app/shared/services/app-languages.service.spec.ts

@ -60,7 +60,7 @@ describe('AppLanguagesService', () => {
const req = httpMock.expectOne('http://service/p/api/apps/my-app/languages');
expect(req.request.method).toEqual('GET');
expect(req.request.headers.get('If-Match')).toEqual('1');
expect(req.request.headers.get('If-Match')).toEqual(version.value);
req.flush([
{
@ -99,7 +99,7 @@ describe('AppLanguagesService', () => {
const req = httpMock.expectOne('http://service/p/api/apps/my-app/languages');
expect(req.request.method).toEqual('POST');
expect(req.request.headers.get('If-Match')).toEqual('1');
expect(req.request.headers.get('If-Match')).toEqual(version.value);
req.flush({ iso2Code: 'de', englishName: 'German' });
@ -117,7 +117,7 @@ describe('AppLanguagesService', () => {
const req = httpMock.expectOne('http://service/p/api/apps/my-app/languages/de');
expect(req.request.method).toEqual('PUT');
expect(req.request.headers.get('If-Match')).toEqual('1');
expect(req.request.headers.get('If-Match')).toEqual(version.value);
req.flush({});
}));
@ -130,7 +130,7 @@ describe('AppLanguagesService', () => {
const req = httpMock.expectOne('http://service/p/api/apps/my-app/languages/de');
expect(req.request.method).toEqual('DELETE');
expect(req.request.headers.get('If-Match')).toEqual('1');
expect(req.request.headers.get('If-Match')).toEqual(version.value);
req.flush({});
}));

6
src/Squidex/app/shared/services/assets.service.spec.ts

@ -320,7 +320,7 @@ describe('AssetsService', () => {
const req = httpMock.expectOne('http://service/p/api/apps/my-app/assets/123/content');
expect(req.request.method).toEqual('PUT');
expect(req.request.headers.get('If-Match')).toEqual('1');
expect(req.request.headers.get('If-Match')).toEqual(version.value);
req.flush({
fileSize: 1024,
@ -352,7 +352,7 @@ describe('AssetsService', () => {
const req = httpMock.expectOne('http://service/p/api/apps/my-app/assets/123');
expect(req.request.method).toEqual('PUT');
expect(req.request.headers.get('If-Match')).toEqual('1');
expect(req.request.headers.get('If-Match')).toEqual(version.value);
req.flush({});
}));
@ -365,7 +365,7 @@ describe('AssetsService', () => {
const req = httpMock.expectOne('http://service/p/api/apps/my-app/assets/123');
expect(req.request.method).toEqual('DELETE');
expect(req.request.headers.get('If-Match')).toEqual('1');
expect(req.request.headers.get('If-Match')).toEqual(version.value);
req.flush({});
}));

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

@ -118,7 +118,7 @@ describe('SchemaDetailsDto', () => {
it('should update fields property and user info when removing field', () => {
const field1 = new FieldDto(1, '1', false, false, false, 'l', createProperties('String'));
const field2 = new FieldDto(2, '2',false, false, false, 'l', createProperties('Number'));
const field2 = new FieldDto(2, '2', false, false, false, 'l', createProperties('Number'));
const now = DateTime.now();

112
src/Squidex/app/shared/services/webhooks.service.spec.ts

@ -5,7 +5,7 @@
* Copyright (c) Sebastian Stehle. All rights reserved
*/
/*
import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing';
import { inject, TestBed } from '@angular/core/testing';
@ -13,14 +13,37 @@ import {
ApiUrlConfig,
CreateWebhookDto,
DateTime,
UpdateWebhookDto,
Version,
WebhookDto,
WebhookEventDto,
WebhookEventsDto,
WebhookSchemaDto,
WebhooksService
} from './../';
describe('WebhookDto', () => {
const now = DateTime.now();
const user = 'me';
const version = new Version('1');
it('should update url and schemas', () => {
const webhook_1 = new WebhookDto('id1', 'token1', user, user, now, now, version, [], 'http://squidex.io/hook', 1, 2, 3, 4);
const webhook_2 =
webhook_1.update(new UpdateWebhookDto('http://squidex.io/hook2',
[
new WebhookSchemaDto('1', true, true, true, true, true),
new WebhookSchemaDto('2', true, true, true, true, true)
]), user, now);
expect(webhook_2.url).toEqual('http://squidex.io/hook2');
expect(webhook_2.schemas.length).toEqual(2);
});
});
describe('WebhooksService', () => {
const now = DateTime.now();
const user = 'me';
const version = new Version('1');
beforeEach(() => {
@ -56,51 +79,94 @@ describe('WebhooksService', () => {
req.flush([
{
id: 'id1',
schemaId: 'schemaId1',
sharedSecret: 'token1',
url: 'http://squidex.io/1',
created: '2016-12-12T10:10',
createdBy: 'CreatedBy1',
lastModified: '2017-12-12T10:10',
lastModifiedBy: 'LastModifiedBy1',
url: 'http://squidex.io/hook',
version: '1',
totalSucceeded: 1,
totalFailed: 2,
totalTimedout: 3,
averageRequestTimeMs: 4
},
{
id: 'id2',
schemaId: 'schemaId2',
sharedSecret: 'token2',
url: 'http://squidex.io/2',
totalSucceeded: 5,
totalFailed: 6,
totalTimedout: 7,
averageRequestTimeMs: 8
averageRequestTimeMs: 4,
schemas: [{
schemaId: '1',
sendCreate: true,
sendUpdate: true,
sendDelete: true,
sendPublish: true,
sendUnpublish: true
}, {
schemaId: '2',
sendCreate: true,
sendUpdate: true,
sendDelete: true,
sendPublish: true,
sendUnpublish: true
}]
}
]);
expect(webhooks).toEqual([
new WebhookDto('id1', 'schemaId1', 'token1', 'http://squidex.io/1', 1, 2, 3, 4),
new WebhookDto('id2', 'schemaId2', 'token2', 'http://squidex.io/2', 5, 6, 7, 8)
new WebhookDto('id1', 'token1', 'CreatedBy1', 'LastModifiedBy1',
DateTime.parseISO_UTC('2016-12-12T10:10'),
DateTime.parseISO_UTC('2017-12-12T10:10'),
version,
[
new WebhookSchemaDto('1', true, true, true, true, true),
new WebhookSchemaDto('2', true, true, true, true, true)
],
'http://squidex.io/hook', 1, 2, 3, 4)
]);
}));
it('should make post request to create webhook',
inject([WebhooksService, HttpTestingController], (webhooksService: WebhooksService, httpMock: HttpTestingController) => {
const dto = new CreateWebhookDto('http://squidex.io/hook');
const dto = new CreateWebhookDto('http://squidex.io/hook', []);
let webhook: WebhookDto | null = null;
webhooksService.postWebhook('my-app', 'my-schema', dto, version).subscribe(result => {
webhooksService.postWebhook('my-app', dto, user, now, version).subscribe(result => {
webhook = result;
});
const req = httpMock.expectOne('http://service/p/api/apps/my-app/schemas/my-schema/webhooks');
const req = httpMock.expectOne('http://service/p/api/apps/my-app/webhooks');
expect(req.request.method).toEqual('POST');
expect(req.request.headers.get('If-Match')).toBe(version.value);
expect(req.request.headers.get('If-Match')).toEqual(version.value);
req.flush({ id: 'id1', sharedSecret: 'token1', schemaId: 'schema1' });
expect(webhook).toEqual(new WebhookDto('id1', 'schema1', 'token1', dto.url, 0, 0, 0, 0));
expect(webhook).toEqual(
new WebhookDto('id1', 'token1', user, user, now, now, version, [], 'http://squidex.io/hook', 0, 0, 0, 0));
}));
it('should make put request to update webhook',
inject([WebhooksService, HttpTestingController], (webhooksService: WebhooksService, httpMock: HttpTestingController) => {
const dto = new UpdateWebhookDto('http://squidex.io/hook', []);
webhooksService.putWebhook('my-app', '123', dto, version).subscribe();
const req = httpMock.expectOne('http://service/p/api/apps/my-app/webhooks/123');
expect(req.request.method).toEqual('PUT');
expect(req.request.headers.get('If-Match')).toEqual(version.value);
req.flush({});
}));
it('should make delete request to delete webhook',
inject([WebhooksService, HttpTestingController], (webhooksService: WebhooksService, httpMock: HttpTestingController) => {
webhooksService.deleteWebhook('my-app', '123', version).subscribe();
const req = httpMock.expectOne('http://service/p/api/apps/my-app/webhooks/123');
expect(req.request.method).toEqual('DELETE');
expect(req.request.headers.get('If-Match')).toEqual(version.value);
}));
it('should make get request to get app webhook events',
@ -157,7 +223,7 @@ describe('WebhooksService', () => {
]));
}));
it('should make delete request to enqueue webhook event',
it('should make put request to enqueue webhook event',
inject([WebhooksService, HttpTestingController], (webhooksService: WebhooksService, httpMock: HttpTestingController) => {
webhooksService.enqueueEvent('my-app', '123').subscribe();
@ -166,4 +232,4 @@ describe('WebhooksService', () => {
expect(req.request.method).toEqual('PUT');
}));
});*/
});

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

@ -150,7 +150,7 @@ export class WebhooksService {
public postWebhook(appName: string, dto: CreateWebhookDto, user: string, now?: DateTime, version?: Version): Observable<WebhookDto> {
const url = this.apiUrl.buildUrl(`api/apps/${appName}/webhooks`);
return HTTP.postVersioned(this.http, url, dto)
return HTTP.postVersioned(this.http, url, dto, version)
.map(response => {
return new WebhookDto(
response.id,

Loading…
Cancel
Save