Skip to content

Commit

Permalink
feat: add an abstract endpoint mocker that contains common methods fo…
Browse files Browse the repository at this point in the history
…r all implementations (#76)
  • Loading branch information
shubhbapna committed Aug 4, 2023
1 parent c26ddc0 commit e8161e9
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
13 changes: 13 additions & 0 deletions src/endpoint-mocker/abstract-endpoint-mocker.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import nock from "nock";

export abstract class EndpointMocker {
constructor(private _allowUnmocked: boolean) {}

get allowUnmocked() {
return this._allowUnmocked;
}

cleanAll() {
nock.cleanAll();
}
}
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { Input } from "@mg/github/action/input/input-mocker.types";
import { Response } from "@mg/endpoint-mocker/response/abstract-response-mocker.types";
import { ResponseMocker } from "@mg/endpoint-mocker/response/abstract-response-mocker";
import { RequestMocker } from "@mg/endpoint-mocker/request/abstract-request-mocker";
import { EndpointMocker } from "@mg/endpoint-mocker/abstract-endpoint-mocker";
import { EndpointDetails, EndpointMethod, Endpoints } from "@mg/endpoint-mocker/endpoint-mocker.types";
import { Repository, Repositories } from "@mg/github/repository/repository-mocker.types";

Expand All @@ -36,6 +37,7 @@ export {
Repositories,
Repository,
Response,
EndpointMocker,
ResponseMocker,
RequestMocker,
EndpointDetails,
Expand Down
11 changes: 4 additions & 7 deletions src/moctokit/moctokit.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
import { EndpointMocker } from "@mg/endpoint-mocker/abstract-endpoint-mocker";
import endpointToMethod from "@mg/moctokit/generated/endpoint-request";
import nock from "nock";

export class Moctokit {
export class Moctokit extends EndpointMocker {
private _rest;
constructor(baseUrl?: string, allowUnmocked = false) {
this._rest = endpointToMethod(baseUrl ?? "https://api.github.com", allowUnmocked);
super(allowUnmocked);
this._rest = endpointToMethod(baseUrl ?? "https://api.github.com", this.allowUnmocked);
}

get rest() {
return this._rest;
}

cleanAll() {
nock.cleanAll();
}
}

0 comments on commit e8161e9

Please sign in to comment.