Add mock GitHub API config listener (#1632)
This commit is contained in:
@@ -1,13 +1,28 @@
|
||||
import { MockGitHubApiConfigListener } from '../config';
|
||||
|
||||
/**
|
||||
* Enables mocking of the GitHub API server via HTTP interception, using msw.
|
||||
*/
|
||||
export class MockGitHubApiServer {
|
||||
private isListening: boolean;
|
||||
private config: MockGitHubApiConfigListener;
|
||||
|
||||
constructor() {
|
||||
this.isListening = false;
|
||||
this.config = new MockGitHubApiConfigListener();
|
||||
this.setupConfigListener();
|
||||
}
|
||||
|
||||
public startServer(): void {
|
||||
this.isListening = true;
|
||||
|
||||
// TODO: Enable HTTP interception.
|
||||
}
|
||||
|
||||
public stopServer(): void {
|
||||
// Disable HTTP interception.
|
||||
this.isListening = false;
|
||||
|
||||
// TODO: Disable HTTP interception.
|
||||
}
|
||||
|
||||
public loadScenario(): void {
|
||||
@@ -21,4 +36,14 @@ export class MockGitHubApiServer {
|
||||
public recordScenario(): void {
|
||||
// TODO: Implement logic to record a new scenario to a directory.
|
||||
}
|
||||
|
||||
private setupConfigListener(): void {
|
||||
this.config.onDidChangeConfiguration(() => {
|
||||
if (this.config.mockServerEnabled && !this.isListening) {
|
||||
this.startServer();
|
||||
} else if (!this.config.mockServerEnabled && this.isListening) {
|
||||
this.stopServer();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user