Skip to content

Commit

Permalink
feat: expose get experiment from workspace
Browse files Browse the repository at this point in the history
  • Loading branch information
x-oflisback committed May 11, 2023
1 parent 197a16e commit f22079a
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 1 deletion.
35 changes: 35 additions & 0 deletions src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import ApiError, {
UnknownApiError,
} from './api-error'
import { Cookie, CookieJar } from 'tough-cookie'
import Experiment from './experiment'
import ExperimentDefinition from './experiment-definition'
import {
Case,
Expand Down Expand Up @@ -436,6 +437,40 @@ class Api {
})
}

getExperiment({
experimentId,
workspaceId,
}: {
experimentId: ExperimentId
workspaceId: WorkspaceId
}): Promise<Experiment | undefined> {
return new Promise((resolve, reject) => {
this.ensureImpactToken()
.then(() => {
this.axios
.get(
`${this.baseUrl}${this.jhUserPath}impact/api/workspaces/${workspaceId}/experiments/${experimentId}`,
{
headers: {
Accept: 'application/vnd.impact.experiment.v2+json',
},
}
)
.then(() =>
resolve(
new Experiment({
api: this,
id: experimentId,
workspaceId,
})
)
)
.catch((e) => reject(toApiError(e)))
})
.catch((e) => reject(toApiError(e)))
})
}

getCases({
experimentId,
workspaceId,
Expand Down
9 changes: 8 additions & 1 deletion src/workspace.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CaseId, CustomFunction, WorkspaceId } from './types'
import { CaseId, CustomFunction, ExperimentId, WorkspaceId } from './types'
import Api from './api'
import Experiment from './experiment'
import ExperimentDefinition from './experiment-definition'
Expand Down Expand Up @@ -76,6 +76,13 @@ class Workspace {
getCustomFunctions(): Promise<CustomFunction[]> {
return this.api.getCustomFunctions(this.id)
}

getExperiment(experimentId: ExperimentId): Promise<Experiment | undefined> {
return this.api.getExperiment({
experimentId,
workspaceId: this.id,
})
}
}

export default Workspace
5 changes: 5 additions & 0 deletions tests/integration/integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,11 @@ test(
expect(trajectories[1].items[0].trajectory.length).toBe(102)
expect(trajectories[1].items[0].trajectory.length).toBe(102)

const experimentAfterwards = await testWorkspace.getExperiment(
experiment.id
)
expect(experimentAfterwards).not.toBeUndefined()

await deleteTestWorkspace(client)
} catch (e) {
if (e instanceof Error) {
Expand Down

0 comments on commit f22079a

Please sign in to comment.