-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathCQLLibraryDelete.cy.ts
More file actions
256 lines (216 loc) · 10.2 KB
/
Copy pathCQLLibraryDelete.cy.ts
File metadata and controls
256 lines (216 loc) · 10.2 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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
import { CQLLibraryPage } from "../../../Shared/CQLLibraryPage"
import { SupportedModels } from "../../../Shared/CreateMeasurePage"
import { MeasureCQL } from "../../../Shared/MeasureCQL"
import { OktaLogin } from "../../../Shared/OktaLogin"
import { CqlLibraryBody, TestData } from "../../../Shared/TestData"
let CQLLibraryName = ''
const CQLLibraryPublisher = 'SemanticBits'
let measureCQLAlt = MeasureCQL.ICFCleanTestQICore
const versionNumber = '1.0.000'
const deleteCurrentCqlLibrary = (
options: Partial<Cypress.RequestOptions> = {}
): Cypress.Chainable<Cypress.Response<CqlLibraryBody>> => {
return TestData.readCqlLibraryId().then((libraryId) => {
return TestData.requestCqlLibraryById<CqlLibraryBody>('DELETE', libraryId, options)
})
}
const transferCurrentCqlLibrary = (
harpId: string
): Cypress.Chainable<Cypress.Response<CqlLibraryBody>> => {
return TestData.readCqlLibraryId().then((libraryId) => {
return TestData.requestWithAccessToken<CqlLibraryBody>({
url: '/api/cql-libraries/transfer?retainShareAccess=false',
method: 'PUT',
headers: {
harpid: harpId
},
body: [libraryId]
})
})
}
const draftCurrentCqlLibrary = (): Cypress.Chainable<Cypress.Response<CqlLibraryBody>> => {
return TestData.draftCqlLibrary<CqlLibraryBody>((libraryId) => ({
id: libraryId,
cqlLibraryName: CQLLibraryName,
model: 'QI-Core v4.1.1'
}))
}
const createSecondVersion = (): Cypress.Chainable<{
historicalLibraryId: string
latestLibraryId: string
}> => {
return TestData.versionCqlLibrary<CqlLibraryBody>(versionNumber).then((historicalResponse) => {
const historicalLibraryId = historicalResponse.body.id
expect(historicalLibraryId, 'historical library id').to.be.a('string').and.not.be.empty
return draftCurrentCqlLibrary().then((draftResponse) => {
expect(draftResponse.status).to.eq(201)
expect(draftResponse.body.draft).to.eq(true)
TestData.writeCqlLibraryId(draftResponse.body.id, 1)
return TestData.versionCqlLibrary<CqlLibraryBody>('2.0.000', 1).then((latestResponse) => {
const latestLibraryId = latestResponse.body.id
expect(latestLibraryId, 'latest library id').to.be.a('string').and.not.be.empty
return cy.wrap({ historicalLibraryId, latestLibraryId })
})
})
})
}
const deleteAllCqlLibraryVersions = (
harpId: string,
options: Partial<Cypress.RequestOptions> = {}
): Cypress.Chainable<Cypress.Response<string | { message: string }>> => {
return TestData.requestWithAccessToken<string | { message: string }>({
...options,
url: '/api/cql-libraries/admin/' + CQLLibraryName + '/delete-all-versions',
method: 'DELETE',
headers: {
harpId
}
})
}
describe('Delete CQL Library', () => {
beforeEach('Set Access Token', () => {
CQLLibraryName = 'DeleteCqlLibrary' + Date.now()
measureCQLAlt = measureCQLAlt.replace('SimpleFhirLibrary', CQLLibraryName)
CQLLibraryPage.createLibraryAPI(CQLLibraryName, SupportedModels.qiCore4, { publisher: CQLLibraryPublisher, cql: measureCQLAlt })
})
it('Delete CQL Library - Draft Library - user does not own nor has Library been shared with user', () => {
// this is altUser, since we are looking for a failure
OktaLogin.setupUserSession(true)
deleteCurrentCqlLibrary({ failOnStatusCode: false }).then((response) => {
expect(response.status).to.eql(403)
})
})
it('Delete CQL Library - Draft Library - user is the owner of the Library', () => {
OktaLogin.setupUserSession(false)
deleteCurrentCqlLibrary().then((response) => {
expect(response.status).to.eql(200)
})
})
it('Delete CQL Library - Draft Library - user has had the Library transferred to them', () => {
const harpUserALT = OktaLogin.getUser(true)
OktaLogin.setupUserSession(false)
transferCurrentCqlLibrary(harpUserALT).then((response) => {
expect(response.status).to.eql(200)
}).then(() => {
OktaLogin.setupUserSession(true)
deleteCurrentCqlLibrary().then((response) => {
expect(response.status).to.eql(200)
})
})
})
it('Delete CQL Library - Versioned Library - user does not own nor has Library been shared with user', () => {
OktaLogin.setupUserSession(false)
CQLLibraryPage.versionLibraryAPI(versionNumber)
// switch to altUser
OktaLogin.setupUserSession(true)
deleteCurrentCqlLibrary({ failOnStatusCode: false }).then((response) => {
expect(response.status).to.eql(403)
})
})
it('Delete CQL Library - Versioned Library - user is the owner of the Library', () => {
OktaLogin.setupUserSession(false)
CQLLibraryPage.versionLibraryAPI(versionNumber)
OktaLogin.setupUserSession(false)
deleteCurrentCqlLibrary({ failOnStatusCode: false }).then((response) => {
expect(response.status).to.eql(409)
})
})
it('Delete CQL Library - Versioned Library - user has had the Library transferred to them', () => {
const harpUserALT = OktaLogin.getUser(true)
OktaLogin.setupUserSession(false)
transferCurrentCqlLibrary(harpUserALT).then((response) => {
expect(response.status).to.eql(200)
}).then(() => {
OktaLogin.setupUserSession(true)
CQLLibraryPage.versionLibraryAPI(versionNumber)
deleteCurrentCqlLibrary({ failOnStatusCode: false }).then((response) => {
expect(response.status).to.eql(409)
})
})
})
// MAT-9892: Proven in DEV on 2026-08-06. Keep as regression coverage without rerunning by default.
it.skip('Admin deletes only the selected latest CQL Library version by document ID', () => {
const harpUser = OktaLogin.setupUserSession(false)
createSecondVersion().then(({ historicalLibraryId, latestLibraryId }) => {
OktaLogin.setupAdminSession()
TestData.requestAdminCqlLibraryDeleteById<CqlLibraryBody>(
latestLibraryId,
harpUser
).then((response) => {
expect(response.status).to.eq(200)
expect(response.body.id).to.eq(latestLibraryId)
expect(response.body.version).to.eq('2.0.000')
})
OktaLogin.setupUserSession(false)
TestData.requestCqlLibraryById<CqlLibraryBody>('GET', latestLibraryId, {
failOnStatusCode: false
}).then((response) => {
expect(response.status).to.eq(404)
})
TestData.requestCqlLibraryById<CqlLibraryBody>('GET', historicalLibraryId).then(
(response) => {
expect(response.status).to.eq(200)
expect(response.body.id).to.eq(historicalLibraryId)
expect(response.body.version).to.eq(versionNumber)
}
)
})
})
// MAT-9892: Proven in DEV on 2026-08-06. Keep as regression coverage without rerunning by default.
it.skip('Admin cannot delete a CQL Library version when harpId does not match the owner', () => {
const harpUserALT = OktaLogin.getUser(true)
OktaLogin.setupUserSession(false)
TestData.versionCqlLibrary<CqlLibraryBody>(versionNumber).then((versionResponse) => {
const libraryId = versionResponse.body.id
OktaLogin.setupAdminSession()
TestData.requestAdminCqlLibraryDeleteById<CqlLibraryBody>(libraryId, harpUserALT, {
failOnStatusCode: false
}).then((response) => {
expect(response.status).to.eq(409)
expect(response.body).to.have.property('message').and.contain(harpUserALT)
expect(response.body).to.have.property('message').and.contain(libraryId)
})
OktaLogin.setupUserSession(false)
TestData.requestCqlLibraryById<CqlLibraryBody>('GET', libraryId).then((response) => {
expect(response.status).to.eq(200)
expect(response.body.id).to.eq(libraryId)
})
})
})
it('Delete all Versions of the CQL Library - user is the owner of the Library', () => {
const harpUser = OktaLogin.setupUserSession(false)
CQLLibraryPage.versionLibraryAPI(versionNumber)
//Draft Versioned Library
draftCurrentCqlLibrary().then((response) => {
expect(response.status).to.eql(201)
expect(response.body.draft).to.eql(true)
})
OktaLogin.setupAdminSession()
deleteAllCqlLibraryVersions(harpUser).then((response) => {
expect(response.status).to.eql(200)
expect(response.body).to.eql('The library and all its associated versions have been removed successfully.')
})
OktaLogin.setupUserSession(false)
TestData.readCqlLibrary<CqlLibraryBody>(0, { failOnStatusCode: false }).then((response) => {
expect(response.status).to.eql(404)
})
})
it('Delete all Versions of the CQL Library - user does not own nor has Library been shared with user', () => {
const harpUser = OktaLogin.setupUserSession(false)
const harpUserALT = OktaLogin.getUser(true)
OktaLogin.setupAdminSession()
TestData.readCqlLibraryId().then((cqlLibraryId) => {
deleteAllCqlLibraryVersions(harpUserALT, { failOnStatusCode: false }).then((response) => {
expect(response.status).to.eql(409)
expect(response.body).to.have.property(
'message',
'Response could not be completed because the HARP id of ' + harpUserALT + ' passed in does not match the owner of the library with the library id of ' + cqlLibraryId + '. The owner of the library is ' + harpUser
)
})
})
OktaLogin.setupUserSession(false)
TestData.readCqlLibrary<CqlLibraryBody>().then((response) => {
expect(response.status).to.eql(200)
})
})
})