Skip to content

Commit b555dc7

Browse files
authored
Merge pull request #19 from requestly/ENGG-1804-release
feat: Release templating support in mock server
2 parents a0a9238 + 9f096a1 commit b555dc7

File tree

6 files changed

+38
-14
lines changed

6 files changed

+38
-14
lines changed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
{
22
"name": "@requestly/mock-server",
3-
"version": "0.2.11",
3+
"version": "0.2.12",
44
"description": "- Methods: GET, POST, PUT, OPTIONS - Description - Endpoint (can be full path) (/api/v1/users) - Multiple Responses - Shuffle Response - Sequential Response - Rules in Response - Status (Any status code 2xx, 4xx) - Latency - Body - Templating - Faker js - Headers",
55
"main": "build/index.js",
66
"scripts": {
77
"test": "echo \"Error: no test specified\" && exit 1",
88
"start": "npm run build && node build/test/index.js",
99
"start:dev": "npx nodemon",
10-
"build": "rimraf ./build && tsc"
10+
"build": "rimraf ./build && tsc",
11+
"prepack": "npm run build"
1112
},
1213
"author": "",
1314
"license": "ISC",

src/core/common/mockProcessor.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,20 +64,14 @@ class MockProcessor {
6464
};
6565

6666
// TODO: Pass extra params here required for rendering
67-
// TODO: Do template rendering here
6867
static renderBody = (
6968
responseTemplate: Response,
7069
mockContextParams: MockContextParams
7170
) => {
7271
let finalBody = null;
7372
let bodyTemplate: string = responseTemplate.body;
74-
return bodyTemplate;
75-
/**
76-
* Commenting Templating for now due to a bug
77-
* https://linear.app/requestly/issue/ENGG-1804
78-
*/
79-
// finalBody = renderTemplate(bodyTemplate, mockContextParams);
80-
// return finalBody;
73+
finalBody = renderTemplate(bodyTemplate, mockContextParams);
74+
return finalBody;
8175
};
8276

8377
// Time in ms

src/core/utils/templating/helpers/requestHelpers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const requestHelpers = (params: MockContextParams) => {
2222
return defaultValue
2323
}
2424

25-
return params.headers[param] || defaultValue;
25+
return params.headers[param?.toLowerCase()] || defaultValue;
2626
},
2727
};
2828
return helpers;

src/test/dummy/mock1.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,27 @@ export const dummyMock3: Mock = {
6262
]
6363
}
6464

65+
export const dummyMock4: Mock = {
66+
id: "4",
67+
desc: "Mock 4 : Password protected",
68+
method: RequestMethod.GET,
69+
endpoint: "users4/:id/:name",
70+
responses: [
71+
{
72+
id: "1",
73+
desc: "Mock 4 Response 1",
74+
latency: 0,
75+
statusCode: 200,
76+
headers: {
77+
"x-foo": "bar",
78+
"content-type": "text/plain",
79+
},
80+
body: `the id is {{urlParam 'id'}} . the url is {{url}} . not passing param to url param {{urlParam}}. Content type is {{header 'Content-Type'}}. giberish ahead: {{random values}} {{}} {{color: "something"}} {{url 'http://localhost:3000'}} {{urlParam 'id'}} {{ color: "red", display: flex}}`
81+
}
82+
]
83+
84+
}
85+
6586
export const getSelectorMap = (): any => {
6687
let selectorMap: any = {}
6788
selectorMap[dummyMock1.id] = {
@@ -79,5 +100,10 @@ export const getSelectorMap = (): any => {
79100
endpoint: dummyMock3.endpoint
80101
};
81102

103+
selectorMap[dummyMock4.id] = {
104+
method: dummyMock4.method,
105+
endpoint: dummyMock4.endpoint
106+
};
107+
82108
return selectorMap;
83109
}

src/test/firebaseConfigFetcher.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { dummyMock1, dummyMock2, dummyMock3, getSelectorMap } from "./dummy/mock1";
1+
import { dummyMock1, dummyMock2, dummyMock3, dummyMock4, getSelectorMap } from "./dummy/mock1";
22
import IConfigFetcher from "../interfaces/configFetcherInterface";
33

44

@@ -18,6 +18,9 @@ class FirebaseConfigFetcher implements IConfigFetcher {
1818
else if(id === "3") {
1919
return dummyMock3;
2020
}
21+
else if(id === "4") {
22+
return dummyMock4;
23+
}
2124

2225
return null;
2326
}

0 commit comments

Comments
 (0)