-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add an abstract endpoint mocker that contains common methods fo…
…r all implementations (#76)
- Loading branch information
1 parent
c26ddc0
commit e8161e9
Showing
3 changed files
with
19 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |