-
Notifications
You must be signed in to change notification settings - Fork 371
Expand file tree
/
Copy pathapi.project.fixture.ts
More file actions
81 lines (75 loc) · 2.53 KB
/
Copy pathapi.project.fixture.ts
File metadata and controls
81 lines (75 loc) · 2.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import streamConsumers from 'stream/consumers';
import _ from 'lodash';
import { expect } from 'e2e/fixtures/global-fixtures';
import { safeName } from 'e2e/utils/naming';
import { ProjectsApi, V1PostProjectRequest, V1PostProjectResponse } from 'services/api-ts-sdk/api';
import { apiFixture } from './api';
export class ApiProjectFixture extends apiFixture(ProjectsApi) {
new({ projectProps = {}, projectPrefix = 'test-project' } = {}): V1PostProjectRequest {
const defaults = {
name: safeName(projectPrefix),
workspaceId: 0,
};
return {
...defaults,
...projectProps,
};
}
/**
* Creates a project with the given parameters via the API.
* @param {number} workspaceId workspace id to create the project in.
* @param {V1PostProjectRequest} req the project request with the config for the new project.
* See apiProject.newRandom() for the default config.
* @returns {Promise<V1PostProjectRequest>} Representation of the created project. The request is returned since the
* password is not stored on the V1Project object and it is not returned in the response. However the Request is a
* strict superset of the Response, so no info is lost.
*/
async createProject(
workspaceId: number,
req: V1PostProjectRequest,
): Promise<V1PostProjectResponse> {
const projectResp = await this.api
.postProject(workspaceId, req, {})
.catch(async function (error) {
const respBody = await streamConsumers.text(error.body);
throw new Error(
`Create Project Request failed. Status: ${error.status} Request: ${JSON.stringify(
req,
)} Response: ${respBody}`,
);
});
return _.merge(req, projectResp);
}
/**
*
* @summary Delete a project.
* @param {number} id The id of the project.
*/
async deleteProject(id: number): Promise<void> {
try {
await this.api.deleteProject(id);
} catch (error) {
if (error instanceof Response && error.body) {
const bodyText = error.text();
throw new Error(
`Delete Project Request failed. Status: ${error.status} Request: ${JSON.stringify({
id,
})} Response: ${bodyText}`,
);
}
}
await expect
.poll(
() =>
this.api
.getProject(id)
.then(() => false)
.catch((res) => res.status === 404),
{
message: `Delete Project Request failed ${JSON.stringify(id)}`,
timeout: 15_000,
},
)
.toBe(true);
}
}