-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathapi.ts
More file actions
116 lines (101 loc) · 2.72 KB
/
Copy pathapi.ts
File metadata and controls
116 lines (101 loc) · 2.72 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
import { APIRequestContext, expect } from '@playwright/test';
type Configuration = {
id: string;
name: string;
};
type CodedConcept = {
code: string;
display: string;
};
type Condition = {
id: string;
display_name: string;
rsg_codes: CodedConcept[];
};
type CustomCode = {
code: string;
system_key: string;
system_display_name: string;
name: string;
};
export class Api {
constructor(private request: APIRequestContext) {}
async getCondition(conditionName: string): Promise<Condition> {
const conditionsReq = await this.request.get('/api/v1/conditions/');
expect(conditionsReq.ok()).toBeTruthy();
const json = await conditionsReq.json();
expect(json).toContainEqual(
expect.objectContaining({
display_name: conditionName,
})
);
const condition = (json as [Condition]).find(
(c) => c.display_name === conditionName
);
expect(condition).toBeTruthy();
if (!condition) {
throw new Error(`Condition ${conditionName} could not be found.`);
}
return condition;
}
async createConfiguration(conditionName: string): Promise<Configuration> {
const condition = await this.getCondition(conditionName);
const configReq = await this.request.post('/api/v1/configurations/', {
data: {
condition_id: condition.id,
},
});
expect(configReq.ok()).toBeTruthy();
const json = await configReq.json();
expect(json).toEqual(
expect.objectContaining({
name: conditionName,
})
);
if (!json) {
throw new Error(
`Configuration for condition ${conditionName} could not be created.`
);
}
return json as Configuration;
}
async uploadCustomCodeCsv(configId: string, codes: CustomCode[]) {
const payload = [];
let row = 2;
for (const c of codes) {
payload.push({ ...c, row });
row++;
}
const uploadCsvReq = await this.request.post(
`/api/v1/configurations/${configId}/custom-codes/confirm`,
{
data: {
custom_codes: payload,
},
}
);
expect(uploadCsvReq.ok()).toBeTruthy();
const json = await uploadCsvReq.json();
expect(json).toEqual(
expect.objectContaining({
errors: null,
})
);
}
async updateConfigurationStatus(
configId: string,
status: 'active' | 'inactive'
): Promise<void> {
const urlStatus = status === 'active' ? 'activate' : 'deactivate';
const statusUpdateReq = await this.request.patch(
`/api/v1/configurations/${configId}/${urlStatus}`
);
expect(statusUpdateReq.ok()).toBeTruthy();
const json = await statusUpdateReq.json();
expect(json).toEqual(
expect.objectContaining({
status: status,
})
);
}
}