Skip to content

Commit defc6bd

Browse files
fetch job to check it was updated correctly
1 parent e822d15 commit defc6bd

1 file changed

Lines changed: 60 additions & 21 deletions

File tree

  • x-pack/test/api_integration/apis/ml/data_frame_analytics

x-pack/test/api_integration/apis/ml/data_frame_analytics/update.ts

Lines changed: 60 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,23 @@ export default ({ getService }: FtrProviderContext) => {
5959
};
6060
});
6161

62+
const editedDescription = 'Edited description';
63+
6264
async function createJobs(mockJobConfigs: Array<DeepPartial<DataFrameAnalyticsConfig>>) {
6365
for (const jobConfig of mockJobConfigs) {
6466
await ml.api.createDataFrameAnalyticsJob(jobConfig as DataFrameAnalyticsConfig);
6567
}
6668
}
6769

70+
async function getDFAJob(id: string) {
71+
const { body } = await supertest
72+
.get(`/api/ml/data_frame/analytics/${id}`)
73+
.auth(USER.ML_VIEWER, ml.securityCommon.getPasswordForUser(USER.ML_VIEWER))
74+
.set(COMMON_REQUEST_HEADERS);
75+
76+
return body.data_frame_analytics[0];
77+
}
78+
6879
describe('UPDATE data_frame/analytics', () => {
6980
before(async () => {
7081
await esArchiver.loadIfNeeded('ml/bm_classification');
@@ -81,7 +92,7 @@ export default ({ getService }: FtrProviderContext) => {
8192
const analyticsId = `${jobId}_0`;
8293

8394
const requestBody = {
84-
description: 'Edited description',
95+
description: editedDescription,
8596
model_memory_limit: '61mb',
8697
allow_lazy_start: true,
8798
max_num_threads: 2,
@@ -94,10 +105,14 @@ export default ({ getService }: FtrProviderContext) => {
94105
.send(requestBody)
95106
.expect(200);
96107

97-
expect(body.description).to.eql(requestBody.description);
98-
expect(body.allow_lazy_start).to.eql(requestBody.allow_lazy_start);
99-
expect(body.model_memory_limit).to.eql(requestBody.model_memory_limit);
100-
expect(body.max_num_threads).to.eql(requestBody.max_num_threads);
108+
expect(body).not.to.be(undefined);
109+
110+
const fetchedJob = await getDFAJob(analyticsId);
111+
112+
expect(fetchedJob.description).to.eql(requestBody.description);
113+
expect(fetchedJob.allow_lazy_start).to.eql(requestBody.allow_lazy_start);
114+
expect(fetchedJob.model_memory_limit).to.eql(requestBody.model_memory_limit);
115+
expect(fetchedJob.max_num_threads).to.eql(requestBody.max_num_threads);
101116
});
102117

103118
it('should only update description field of analytics job when description is sent in request', async () => {
@@ -114,10 +129,14 @@ export default ({ getService }: FtrProviderContext) => {
114129
.send(requestBody)
115130
.expect(200);
116131

117-
expect(body.description).to.eql(requestBody.description);
118-
expect(body.allow_lazy_start).to.eql(commonJobConfig.allow_lazy_start);
119-
expect(body.model_memory_limit).to.eql(commonJobConfig.model_memory_limit);
120-
expect(body.max_num_threads).to.eql(commonJobConfig.max_num_threads);
132+
expect(body).not.to.be(undefined);
133+
134+
const fetchedJob = await getDFAJob(analyticsId);
135+
136+
expect(fetchedJob.description).to.eql(requestBody.description);
137+
expect(fetchedJob.allow_lazy_start).to.eql(commonJobConfig.allow_lazy_start);
138+
expect(fetchedJob.model_memory_limit).to.eql(commonJobConfig.model_memory_limit);
139+
expect(fetchedJob.max_num_threads).to.eql(commonJobConfig.max_num_threads);
121140
});
122141

123142
it('should only update allow_lazy_start field of analytics job when allow_lazy_start is sent in request', async () => {
@@ -134,10 +153,14 @@ export default ({ getService }: FtrProviderContext) => {
134153
.send(requestBody)
135154
.expect(200);
136155

137-
expect(body.allow_lazy_start).to.eql(requestBody.allow_lazy_start);
138-
expect(body.description).to.eql(testJobConfigs[2].description);
139-
expect(body.model_memory_limit).to.eql(commonJobConfig.model_memory_limit);
140-
expect(body.max_num_threads).to.eql(commonJobConfig.max_num_threads);
156+
expect(body).not.to.be(undefined);
157+
158+
const fetchedJob = await getDFAJob(analyticsId);
159+
160+
expect(fetchedJob.allow_lazy_start).to.eql(requestBody.allow_lazy_start);
161+
expect(fetchedJob.description).to.eql(testJobConfigs[2].description);
162+
expect(fetchedJob.model_memory_limit).to.eql(commonJobConfig.model_memory_limit);
163+
expect(fetchedJob.max_num_threads).to.eql(commonJobConfig.max_num_threads);
141164
});
142165

143166
it('should only update model_memory_limit field of analytics job when model_memory_limit is sent in request', async () => {
@@ -154,10 +177,14 @@ export default ({ getService }: FtrProviderContext) => {
154177
.send(requestBody)
155178
.expect(200);
156179

157-
expect(body.model_memory_limit).to.eql(requestBody.model_memory_limit);
158-
expect(body.allow_lazy_start).to.eql(commonJobConfig.allow_lazy_start);
159-
expect(body.description).to.eql(testJobConfigs[3].description);
160-
expect(body.max_num_threads).to.eql(commonJobConfig.max_num_threads);
180+
expect(body).not.to.be(undefined);
181+
182+
const fetchedJob = await getDFAJob(analyticsId);
183+
184+
expect(fetchedJob.model_memory_limit).to.eql(requestBody.model_memory_limit);
185+
expect(fetchedJob.allow_lazy_start).to.eql(commonJobConfig.allow_lazy_start);
186+
expect(fetchedJob.description).to.eql(testJobConfigs[3].description);
187+
expect(fetchedJob.max_num_threads).to.eql(commonJobConfig.max_num_threads);
161188
});
162189

163190
it('should only update max_num_threads field of analytics job when max_num_threads is sent in request', async () => {
@@ -174,10 +201,14 @@ export default ({ getService }: FtrProviderContext) => {
174201
.send(requestBody)
175202
.expect(200);
176203

177-
expect(body.max_num_threads).to.eql(requestBody.max_num_threads);
178-
expect(body.model_memory_limit).to.eql(commonJobConfig.model_memory_limit);
179-
expect(body.allow_lazy_start).to.eql(commonJobConfig.allow_lazy_start);
180-
expect(body.description).to.eql(testJobConfigs[4].description);
204+
expect(body).not.to.be(undefined);
205+
206+
const fetchedJob = await getDFAJob(analyticsId);
207+
208+
expect(fetchedJob.max_num_threads).to.eql(requestBody.max_num_threads);
209+
expect(fetchedJob.model_memory_limit).to.eql(commonJobConfig.model_memory_limit);
210+
expect(fetchedJob.allow_lazy_start).to.eql(commonJobConfig.allow_lazy_start);
211+
expect(fetchedJob.description).to.eql(testJobConfigs[4].description);
181212
});
182213

183214
it('should not allow to update analytics job for unauthorized user', async () => {
@@ -195,6 +226,10 @@ export default ({ getService }: FtrProviderContext) => {
195226

196227
expect(body.error).to.eql('Not Found');
197228
expect(body.message).to.eql('Not Found');
229+
230+
const fetchedJob = await getDFAJob(analyticsId);
231+
// Description should not have changed
232+
expect(fetchedJob.description).to.eql(editedDescription);
198233
});
199234

200235
it('should not allow to update analytics job for the user with only view permission', async () => {
@@ -212,6 +247,10 @@ export default ({ getService }: FtrProviderContext) => {
212247

213248
expect(body.error).to.eql('Not Found');
214249
expect(body.message).to.eql('Not Found');
250+
251+
const fetchedJob = await getDFAJob(analyticsId);
252+
// Description should not have changed
253+
expect(fetchedJob.description).to.eql(editedDescription);
215254
});
216255

217256
it('should show 404 error if job does not exist', async () => {

0 commit comments

Comments
 (0)