in lib/apiScenario/gen/testRecordingApiScenarioGenerator.ts [278:349]
private async generateTestStepRestCall(
records: SingleRequestTracking[],
ctx: TestScenarioGenContext
): Promise<any | undefined | null> {
const record = records.shift()!;
const armInfo = this.armUrlParser.parseArmApiInfo(record.path, record.method);
if (ctx.lastUpdatedResource === armInfo.resourceUri && record.method === "GET") {
return undefined;
}
const responseAssertion = {} as StepResponseAssertion;
if (record.responseCode >= 400) {
responseAssertion[record.responseCode] = {};
}
const parseResult = this.parseRecord(record);
if (parseResult === undefined) {
console.warn(`Skip unknown request:\t${record.method}\t${record.url}`);
return await this.handleUnknownPath(record, records);
}
const { operation, requestParameters } = parseResult;
if (operation.operationId === "ResourceGroups_CreateOrUpdate") {
// todo check scope
return undefined;
}
const variables: Scenario["variables"] = {};
for (const paramKey of Object.keys(requestParameters)) {
const value = requestParameters[paramKey];
if (unwantedParams.has(paramKey) || ctx.variables[paramKey]?.value === value) {
continue;
}
let v: Variable;
if (typeof value === "string") {
v = { type: "string", value };
} else if (typeof value === "object") {
if (Array.isArray(value)) {
v = { type: "array", value: value };
} else {
v = { type: "object", value: value };
}
} else if (typeof value === "boolean") {
v = { type: "bool", value };
} else if (typeof value === "number") {
v = { type: "int", value };
} else {
console.warn(
`unknown type of value: ${typeof value}, key: ${paramKey}, method: ${record.method}`
);
continue;
}
variables[paramKey] = v;
}
const step = {
operationId: operation.operationId!,
variables: Object.keys(variables).length > 0 ? variables : undefined,
responses: Object.keys(responseAssertion).length > 0 ? responseAssertion : undefined,
operation,
};
await this.skipLroPoll(records, operation, record, armInfo);
if (["PUT", "PATCH", "DELETE"].includes(record.method)) {
// eslint-disable-next-line require-atomic-updates
ctx.lastUpdatedResource = armInfo.resourceUri;
}
return step;
}