Skip to content

Commit

Permalink
fix: file helper fix return statements #229
Browse files Browse the repository at this point in the history
  • Loading branch information
shubhendumadhukar committed Aug 5, 2023
1 parent ccfafbe commit 4337c22
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/parser/HttpParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,12 @@ export class HttpParser {
const fileResponse = responseBody.split(";")[1];
if (!fs.existsSync(fileResponse)) this.res.status(404);
await sleep(DELAY);
this.res.sendFile(fileResponse);
return {
...response,
body: JSON.stringify({
"camouflage_file_helper": fileResponse
})
};
} else {
responseBody = responseBody.replace(/\s+/g, " ").trim();
responseBody = responseBody.replace(/{{{/, "{ {{");
Expand Down
9 changes: 9 additions & 0 deletions src/routes/GlobalController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,15 @@ export default class GlobalController {
const parser = new HttpParser(req, res, this.mocksDir);
const mockFile = parser.getMatchedDir() + `/${verb}.mock`;
const response = await parser.getResponse(mockFile);
try {
const fileBody = JSON.parse(response.body)
if (fileBody.hasOwnProperty("camouflage_file_helper")) {

Check failure on line 45 in src/routes/GlobalController.ts

View workflow job for this annotation

GitHub Actions / Lint / Build / Test (14.x)

Do not access Object.prototype method 'hasOwnProperty' from target object
res.sendFile(fileBody["camouflage_file_helper"])
return
}
} catch (error) {
//do nothing
}
if (!res.headersSent) {
const responseValidation = validator.validateResponse(req, response);
if (responseValidation.valid) {
Expand Down

0 comments on commit 4337c22

Please sign in to comment.