Skip to content

Commit 1ea03db

Browse files
committed
add functional test
1 parent 5df4b77 commit 1ea03db

File tree

1 file changed

+17
-16
lines changed

1 file changed

+17
-16
lines changed

x-pack/test/api_integration/apis/telemetry/telemetry.ts

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -201,24 +201,25 @@ export default function ({ getService }: FtrProviderContext) {
201201
cacheLastUpdated = getCacheDetails(body).map(({ updatedAt }) => updatedAt);
202202
});
203203
after(() => esArchiver.unload(archive));
204+
});
204205

205-
it('returns cached results by default', async () => {
206-
const now = Date.now();
207-
const { body }: { body: UnencryptedTelemetryPayload } = await supertest
208-
.post('/api/telemetry/v2/clusters/_stats')
209-
.set('kbn-xsrf', 'xxx')
210-
.send({ unencrypted: true })
211-
.expect(200);
206+
it('returns non-cached results when unencrypted', async () => {
207+
const now = Date.now();
208+
const { body }: { body: UnencryptedTelemetryPayload } = await supertest
209+
.post('/api/telemetry/v2/clusters/_stats')
210+
.set('kbn-xsrf', 'xxx')
211+
.send({ unencrypted: true })
212+
.expect(200);
212213

213-
expect(body).length(2);
214+
expect(body).length(1);
214215

215-
const cacheDetails = getCacheDetails(body);
216-
// Check that the fetched payload is actually cached by comparing cache and updatedAt timestamps
217-
expect(cacheDetails.map(({ updatedAt }) => updatedAt)).to.eql(cacheLastUpdated);
218-
// Check that the fetchedAt timestamp is updated when the data is fethed
219-
cacheDetails.forEach(({ fetchedAt }) => {
220-
expect(new Date(fetchedAt).getTime()).to.be.greaterThan(now);
221-
});
216+
const cacheDetails = getCacheDetails(body);
217+
cacheDetails.forEach(({ fetchedAt, updatedAt }) => {
218+
// Check that the cache is fresh by comparing updatedAt timestamp with
219+
// the timestamp the data was fetched.
220+
expect(new Date(updatedAt).getTime()).to.be.greaterThan(now);
221+
// Check that the fetchedAt timestamp is updated when the data is fetched
222+
expect(new Date(fetchedAt).getTime()).to.be.greaterThan(now);
222223
});
223224
});
224225

@@ -235,7 +236,7 @@ export default function ({ getService }: FtrProviderContext) {
235236
// Check that the cache is fresh by comparing updatedAt timestamp with
236237
// the timestamp the data was fetched.
237238
expect(new Date(updatedAt).getTime()).to.be.greaterThan(now);
238-
// Check that the fetchedAt timestamp is updated when the data is fethed
239+
// Check that the fetchedAt timestamp is updated when the data is fetched
239240
expect(new Date(fetchedAt).getTime()).to.be.greaterThan(now);
240241
});
241242
});

0 commit comments

Comments
 (0)