-
Notifications
You must be signed in to change notification settings - Fork 8.3k
/
_xjson.ts
121 lines (105 loc) · 5.13 KB
/
_xjson.ts
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
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the "Elastic License
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side
* Public License v 1"; you may not use this file except in compliance with, at
* your election, the "Elastic License 2.0", the "GNU Affero General Public
* License v3.0 only", or the "Server Side Public License, v 1".
*/
import expect from '@kbn/expect';
import { FtrProviderContext } from '../../ftr_provider_context';
export default ({ getService, getPageObjects }: FtrProviderContext) => {
const retry = getService('retry');
const PageObjects = getPageObjects(['common', 'console', 'header']);
describe('XJSON', function testXjson() {
this.tags('includeFirefox');
before(async () => {
await PageObjects.common.navigateToApp('console');
await PageObjects.console.skipTourIfExists();
});
beforeEach(async () => {
await PageObjects.console.clearEditorText();
});
const executeRequest = async (request = '\n GET _search') => {
await PageObjects.console.enterText(request);
await PageObjects.console.clickPlay();
await PageObjects.header.waitUntilLoadingHasFinished();
};
describe('inline http request', () => {
it('should not have validation errors', async () => {
await PageObjects.console.enterText('\n GET foo/bar');
expect(await PageObjects.console.hasInvalidSyntax()).to.be(false);
});
it('should have validation error for invalid method', async () => {
await PageObjects.console.enterText('\n FOO foo/bar');
// Retry because the error marker is not always immediately visible.
await retry.try(async () => {
expect(await PageObjects.console.hasInvalidSyntax()).to.be(true);
});
});
it('should have validation error for invalid path', async () => {
await PageObjects.console.enterText('\n GET');
// Retry because the error marker is not always immediately visible.
await retry.try(async () => {
expect(await PageObjects.console.hasInvalidSyntax()).to.be(true);
});
});
it('should have validation error for invalid body', async () => {
await PageObjects.console.enterText('\n POST foo/bar\n {"foo": "bar"');
// Retry because the error marker is not always immediately visible.
await retry.try(async () => {
expect(await PageObjects.console.hasInvalidSyntax()).to.be(true);
});
});
it('should not trigger error for multiple bodies for _msearch requests', async () => {
await PageObjects.console.enterText(
'\nGET foo/_msearch \n{}\n{"query": {"match_all": {}}}\n{"index": "bar"}\n{"query": {"match_all": {}}}'
);
// Retry until typing is finished.
await retry.try(async () => {
expect(await PageObjects.console.hasInvalidSyntax()).to.be(false);
});
});
it('should not trigger validation errors for multiple JSON blocks', async () => {
await PageObjects.console.enterText('\nPOST test/doc/1 \n{\n "foo": "bar"\n}');
await PageObjects.console.enterText('\nPOST test/doc/2 \n{\n "foo": "baz"\n}');
await PageObjects.console.enterText('\nPOST test/doc/3 \n{\n "foo": "qux"\n}');
// Retry until typing is finished.
await retry.try(async () => {
expect(await PageObjects.console.hasInvalidSyntax()).to.be(false);
});
});
it('should allow escaping quotation mark by wrapping it in triple quotes', async () => {
await PageObjects.console.enterText(
'\nPOST test/_doc/1 \n{\n "foo": """look "escaped" quotes"""\n}'
);
// Retry until typing is finished and validation errors are gone.
await retry.try(async () => {
expect(await PageObjects.console.hasInvalidSyntax()).to.be(false);
});
});
// Status badge not yet implemented in phase 2
it.skip('should allow inline comments in request url row', async () => {
await executeRequest('\n GET _search // inline comment');
expect(await PageObjects.console.hasInvalidSyntax()).to.be(false);
expect(await PageObjects.console.getResponseStatus()).to.eql(200);
});
// Status badge not yet implemented in phase 2
it.skip('should allow inline comments in request body', async () => {
await executeRequest(
'\n GET _search \n{\n "query": {\n "match_all": {} // inline comment\n}\n}'
);
expect(await PageObjects.console.hasInvalidSyntax()).to.be(false);
expect(await PageObjects.console.getResponseStatus()).to.eql(200);
});
it('should print warning for deprecated request', async () => {
await executeRequest('\nGET .kibana');
expect(await PageObjects.console.responseHasDeprecationWarning()).to.be(true);
});
it('should not print warning for non-deprecated request', async () => {
await executeRequest('\n GET _search');
expect(await PageObjects.console.responseHasDeprecationWarning()).to.be(false);
});
});
});
};