Skip to content

Commit

Permalink
Merge pull request #172 from holomekc/fix/serve-event-listeners
Browse files Browse the repository at this point in the history
fix: missing serve event listeners
  • Loading branch information
holomekc authored Apr 9, 2024
2 parents 5b1112c + ac0f1cb commit 764c755
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -145,4 +145,26 @@ export class MappingHelperService {
}
return undefined;
}

static helperAddWebhook(mapping?: StubMapping): StubMapping | undefined {
if (mapping) {
if (UtilService.isUndefined(mapping.serveEventListeners)) {
mapping.serveEventListeners = [];
}
mapping.serveEventListeners.push({
name: "webhook",
parameters: {
"method": "POST",
"url": "https://localhost",
"headers": {
"Content-Type": "application/json"
},
"body": "{}"
}
});
return mapping;
}

return undefined;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,22 @@
</div>
</div>

<div ngbDropdown class="btn-group" role="group">
<button
id="wmWebhooksDrop"
type="button"
class="btn btn-secondary dropdown-toggle"
ngbDropdownToggle>
Webhooks
</button>
<div ngbDropdownMenu class="dropdown-menu">
<button type="button" class="dropdown-item" (click)="helpersAddWebhook()">
<fa-icon icon="link"></fa-icon>
Add Webhook
</button>
</div>
</div>

<div ngbDropdown class="btn-group" role="group">
<button id="wmFileEditDrop" type="button" class="btn btn-secondary dropdown-toggle" ngbDropdownToggle>
File
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,10 @@ export class MappingsComponent implements OnInit, OnDestroy, WebSocketListener {
this.setMappingForHelper(MappingHelperService.helperAddResponseTemplatingTransformer(this.getMappingForHelper()));
}

helpersAddWebhook() {
this.setMappingForHelper(MappingHelperService.helperAddWebhook(this.getMappingForHelper()));
}

ngOnDestroy(): void {
this.ngUnsubscribe.next(true);
this.ngUnsubscribe.complete();
Expand Down
8 changes: 6 additions & 2 deletions webapp/wiremock/src/app/model/wiremock/logged-request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@ export class LoggedRequest extends Proxy implements Item {
queryParams: any;
body!: string;
bodyAsBase64!: string;
isBrowserProxyRequest!: boolean;
browserProxyRequest!: boolean;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
loggedDate: any;
date!: string;
protocol!: string;
multiparts!: any[];

constructor() {
super();
Expand Down Expand Up @@ -67,9 +69,11 @@ export class LoggedRequest extends Proxy implements Item {
this.queryParams = unchecked.queryParams;
this.body = unchecked.body;
this.bodyAsBase64 = unchecked.bodyAsBase64;
this.isBrowserProxyRequest = unchecked.isBrowserProxyRequest;
this.browserProxyRequest = unchecked.browserProxyRequest;
this.loggedDate = unchecked.loggedDate;
this.date = moment(this.loggedDate).format();
this.protocol = unchecked.protocol;
this.multiparts = unchecked.multiparts;

return this;
}
Expand Down
2 changes: 2 additions & 0 deletions webapp/wiremock/src/app/model/wiremock/response-definition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ export class ResponseDefinition {
headers!: any;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
additionalProxyRequestHeaders?: any;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
removeProxyRequestHeaders?: any[];
fixedDelayMilliseconds?: number;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
delayDistribution: any;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
export class ServeEventListenerDefinition {

/**
* This class is not deserialized explicitly yet. Therefore, the actual data is whatever the server says.
* Change that if it becomes relevant.
*/

name!: string;

// eslint-disable-next-line @typescript-eslint/no-explicit-any
requestPhases?: any[];

// eslint-disable-next-line @typescript-eslint/no-explicit-any
parameters!: any;
}
4 changes: 4 additions & 0 deletions webapp/wiremock/src/app/model/wiremock/stub-mapping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Item } from "./item";
import { UtilService } from "../../services/util.service";
import { Proxy } from "./proxy";
import { ProxyConfig } from "./proxy-config";
import {ServeEventListenerDefinition} from './serve-event-listener-definition';

export class StubMapping extends Proxy implements Item {
uuid!: string;
Expand All @@ -19,6 +20,8 @@ export class StubMapping extends Proxy implements Item {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
postServeActions!: Map<string, any>;

serveEventListeners!: ServeEventListenerDefinition[];

// eslint-disable-next-line @typescript-eslint/no-explicit-any
metadata: any;

Expand Down Expand Up @@ -57,6 +60,7 @@ export class StubMapping extends Proxy implements Item {
this.newScenarioState = unchecked.newScenarioState;
this.metadata = unchecked.metadata;
this.postServeActions = unchecked.postServeActions;
this.serveEventListeners = unchecked.serveEventListeners;

if (proxyConfig && (this.response.proxyBaseUrl || proxyConfig.proxyConfig.has(this.uuid))) {
this.setProxy(true);
Expand Down

0 comments on commit 764c755

Please sign in to comment.