-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: extract functionality to Workspace class
- Loading branch information
1 parent
b782504
commit 4443f6d
Showing
6 changed files
with
111 additions
and
108 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
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
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 |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import { CaseId, CustomFunction, WorkspaceId } from './types' | ||
import Api from './api' | ||
import Experiment from './experiment' | ||
import ExperimentDefinition from './experiment-definition' | ||
|
||
class Workspace { | ||
private api: Api | ||
id: WorkspaceId | ||
|
||
constructor({ api, id }: { api: Api; id: WorkspaceId }) { | ||
this.api = api | ||
this.id = id | ||
} | ||
|
||
private async createExperiment( | ||
experimentDefinition: ExperimentDefinition | ||
): Promise<Experiment> { | ||
const experimentId = await this.api.createExperiment({ | ||
experimentDefinition, | ||
workspaceId: this.id, | ||
}) | ||
return new Experiment({ | ||
api: this.api, | ||
id: experimentId, | ||
workspaceId: this.id, | ||
}) | ||
} | ||
|
||
async executeExperiment({ | ||
caseIds, | ||
experimentDefinition, | ||
}: { | ||
caseIds: CaseId[] | ||
experimentDefinition: ExperimentDefinition | ||
}): Promise<Experiment> { | ||
const experiment = await this.createExperiment(experimentDefinition) | ||
|
||
await this.api.runExperiment({ | ||
cases: caseIds, | ||
experimentId: experiment.id, | ||
workspaceId: this.id, | ||
}) | ||
|
||
return new Experiment({ | ||
api: this.api, | ||
id: experiment.id, | ||
workspaceId: this.id, | ||
}) | ||
} | ||
|
||
async executeExperimentSync({ | ||
caseIds, | ||
experimentDefinition, | ||
}: { | ||
caseIds: CaseId[] | ||
experimentDefinition: ExperimentDefinition | ||
}): Promise<Experiment> { | ||
const experiment = await this.createExperiment(experimentDefinition) | ||
|
||
await experiment.run(caseIds) | ||
await experiment.executionDone() | ||
|
||
return experiment | ||
} | ||
|
||
getCustomFunctions(): Promise<CustomFunction[]> { | ||
return this.api.getCustomFunctions(this.id) | ||
} | ||
} | ||
|
||
export default Workspace |
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