Skip to content

Commit ac49cbd

Browse files
committed
change undo behavior
1 parent bb1d261 commit ac49cbd

File tree

3 files changed

+16
-5
lines changed

3 files changed

+16
-5
lines changed

features/step_definitions/request_steps.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,8 @@ When("the request is sent", async function (this: World) {
143143
this.apiVersion,
144144
undoAction,
145145
this.operationId,
146-
this.response
146+
this.response,
147+
this.opts,
147148
)
148149
);
149150
}

features/support/given.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ for (const apiVersion of Versions) {
121121
// register undo method
122122
if (undoAction.undo.type == "unsafe") {
123123
this.undo.push(
124-
buildUndoFor(apiVersion, undoAction, operationName, result)
124+
buildUndoFor(apiVersion, undoAction, operationName, result, opts)
125125
);
126126
}
127127

features/support/undo.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ logger.setLevel(process.env.DEBUG ? logger.levels.DEBUG : logger.levels.INFO);
1010

1111
interface iOperationParameter {
1212
name: string;
13+
origin: string;
1314
source: string;
1415
template: string;
1516
}
@@ -42,7 +43,8 @@ function buildUndoFor(
4243
apiVersion: string,
4344
operationUndo: iUndoAction,
4445
operationOrig: string,
45-
response: any
46+
response: any,
47+
request: any
4648
): { (): void } {
4749
return async function () {
4850
var apiName = operationUndo.tag.replace(/\s/g, "");
@@ -85,10 +87,18 @@ function buildUndoFor(
8587
// perform operation
8688
const opts: { [key: string]: any } = {};
8789
for (const p of operationUndo.undo.parameters) {
90+
var dataSource: { [key: string]: any; };
91+
if (p.origin == undefined) {
92+
dataSource = response;
93+
} else if (p.origin === "request") {
94+
dataSource =request.body;
95+
} else {
96+
dataSource = response;
97+
}
8898
if (p.source !== undefined) {
89-
opts[p.name.toAttributeName()] = pathLookup(response, p.source);
99+
opts[p.name.toAttributeName()] = pathLookup(dataSource, p.source);
90100
} else if (p.template !== undefined) {
91-
const data = JSON.parse(p.template.templated(response));
101+
const data = JSON.parse(p.template.templated(dataSource));
92102
const param: { [key: string]: any } = {};
93103
for (const [key, value] of Object.entries(data)) {
94104
param[key.toAttributeName()] = value;

0 commit comments

Comments
 (0)