Skip to content

Commit

Permalink
Allow unmocked (#15)
Browse files Browse the repository at this point in the history
* added allowUnmocked in mockapi

* bumped version. upgraded mock-github
  • Loading branch information
shubhbapna authored Mar 3, 2023
1 parent 69ec29c commit 0e7634c
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 15 deletions.
18 changes: 9 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@kie/act-js",
"version": "2.0.2",
"version": "2.0.3",
"description": "nodejs wrapper for nektos/act",
"main": "build/src/index.js",
"types": "build/src/index.d.ts",
Expand Down Expand Up @@ -57,7 +57,7 @@
"typescript": "^4.7.4"
},
"dependencies": {
"@kie/mock-github": "^1.0.0",
"@kie/mock-github": "^1.0.1",
"ajv": "^8.12.0",
"express": "^4.18.1",
"yaml": "^2.1.3"
Expand Down
7 changes: 5 additions & 2 deletions src/mockapi/mockapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ import { MockapiRequestMocker } from "@aj/mockapi/request/request-mocker";
export class Mockapi {
private apiSchema: API;
private _mock: MockapiMethod;
private allowUnmocked: boolean;

constructor(apiSchema: string | API) {
constructor(apiSchema: string | API, allowUnmocked = false) {
this.apiSchema = this.validateAPISchema(apiSchema);
this._mock = this.apiSchemaToMethod();
this.allowUnmocked = allowUnmocked;
}

/**
Expand All @@ -37,7 +39,8 @@ export class Mockapi {
for (const methodName in this.apiSchema[apiName]["endpoints"][scope]) {
methods[apiName][scope][methodName] = new MockapiRequestMocker(
this.apiSchema[apiName]["baseUrl"],
this.apiSchema[apiName]["endpoints"][scope][methodName]
this.apiSchema[apiName]["endpoints"][scope][methodName],
this.allowUnmocked
).request;
}
}
Expand Down
5 changes: 3 additions & 2 deletions src/mockapi/request/request-mocker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { EndpointDetails, RequestMocker } from "@kie/mock-github";
import { MockapiResponseMocker } from "@aj/mockapi/response/response-mocker";

export class MockapiRequestMocker extends RequestMocker {
constructor(baseUrl: string, endpointDetails: EndpointDetails) {
constructor(baseUrl: string, endpointDetails: EndpointDetails, allowUnmocked = false) {
super(baseUrl, endpointDetails);

// need to bind the instance context to the function. otherwise it is lost during method generation
Expand All @@ -15,7 +15,8 @@ export class MockapiRequestMocker extends RequestMocker {
path,
this.endpointDetails.method,
query,
requestBody
requestBody,
this.allowUnmocked
);
}
}

0 comments on commit 0e7634c

Please sign in to comment.