1
+ const { default : waitForExpect } = require ( 'wait-for-expect' ) ;
1
2
const ksqljs = require ( '../ksqljs/ksqlJS.js' ) ;
2
-
3
3
// Pre-requisite: start a docker container
4
4
/* To add to README: Prior to running test with 'npm test', please start the ksqlDB
5
- server using the command 'docker compose-up'. This will spin up a ksqlDB server on
6
- 'http://localhost:8088'
5
+ server using the command 'docker-compose up'. This will spin up a ksqlDB server on
6
+ 'http://localhost:8088'. If the command was run before, the created container might
7
+ need to be removed first.
7
8
*/
8
9
9
- describe ( '--Integration Tests--' , ( ) => {
10
+ // ** INTEGRATION TEST INSTRUCTIONS **
10
11
12
+ // Prior to running the test files, please ensure an instance of the ksqldb server is running
13
+ // Steps to starting the ksqldb server can be found here: (https://ksqldb.io/quickstart.html)
14
+ // Once the ksqlDB server is running, tests can be run with terminal line: (npm test)
15
+
16
+ describe ( '--Integration Tests--' , ( ) => {
11
17
describe ( '--Method Tests--' , ( ) => {
12
18
beforeAll ( ( done ) => {
13
19
client = new ksqljs ( { ksqldbURL : 'http://localhost:8088' } ) ;
@@ -31,8 +37,8 @@ describe('--Integration Tests--', () => {
31
37
}
32
38
expect ( streamExists ) . toEqual ( true ) ;
33
39
} )
34
-
35
- it ( '.push properly creates a push query' , async ( ) => {
40
+
41
+ it ( '.push properly creates a push query' , ( ) => {
36
42
let pushActive = false ;
37
43
await client . push ( 'SELECT * FROM TESTJESTSTREAM EMIT CHANGES LIMIT 1;' , async ( data ) => {
38
44
if ( JSON . parse ( data ) . queryId ) {
@@ -41,11 +47,10 @@ describe('--Integration Tests--', () => {
41
47
expect ( pushActive ) . toEqual ( true )
42
48
} ) ;
43
49
} )
44
-
45
- it ( '.terminate properly terminates a push query' , async ( ) => {
46
- let terminateRes ;
47
- await client . push ( 'SELECT * FROM TESTJESTSTREAM EMIT CHANGES LIMIT 3;' , async ( data ) => {
48
- terminateRes = await client . terminate ( JSON . parse ( data ) . queryId ) ;
50
+
51
+ it ( '.terminate properly terminates a push query' , ( ) => {
52
+ client . push ( 'SELECT * FROM TESTJESTSTREAM EMIT CHANGES LIMIT 3;' , async ( data ) => {
53
+ const terminateRes = await client . terminate ( JSON . parse ( data ) . queryId ) ;
49
54
expect ( terminateRes . wasTerminated ) . toEqual ( true ) ;
50
55
} )
51
56
// console.log("this is terminate", terminateRes);
@@ -55,7 +60,7 @@ describe('--Integration Tests--', () => {
55
60
// const response = await client.terminate(queryIdDelete);
56
61
// console.log(response);
57
62
} )
58
-
63
+
59
64
it ( '.insertStream properly inserts a row into a stream' , async ( ) => {
60
65
const response = await client . insertStream ( 'TESTJESTSTREAM' , [
61
66
{ "name" : "stab-rabbit" , "email" : "123@mail.com" , "age" : 100 }
@@ -69,7 +74,7 @@ describe('--Integration Tests--', () => {
69
74
}
70
75
} ) ;
71
76
} )
72
-
77
+
73
78
it ( '.pull receives the correct data from a pull query' , async ( ) => {
74
79
const pullData = await client . pull ( "SELECT * FROM TESTJESTSTREAM;" ) ;
75
80
expect ( pullData [ 1 ] ) . toEqual ( [ "stab-rabbit" , "123@mail.com" , 100 ] ) ;
@@ -84,12 +89,53 @@ describe('--Integration Tests--', () => {
84
89
} )
85
90
} )
86
91
92
+ // describe('--Materialized Views Test--', () => {
93
+ // beforeAll( async () => {
94
+ // client = new ksqljs({ ksqldbURL: 'http://localhost:8088'});
95
+ // const waitForExpect = require('wait-for-expect');
96
+ // await client.ksql('CREATE STREAM NEWTESTSTREAM (NAME VARCHAR, AGE INTEGER, LOCATION VARCHAR, WEIGHT INTEGER) WITH (kafka_topic= \'testJestTopic2\', value_format=\'json\', partitions=1);')
97
+ // });
98
+ // afterAll(async () => {
99
+ // await client.ksql('DROP TABLE IF EXISTS TABLEOFSTREAM DELETE TOPIC;')
100
+ // await client.ksql('DROP STREAM IF EXISTS NEWTESTSTREAM DELETE TOPIC;')
101
+ // })
102
+ // it('creates a materialized table view of a stream', async () => {
103
+ // await client.createTableAs('TABLEOFSTREAM', 'NEWTESTSTREAM', ['name', 'LATEST_BY_OFFSET(age) AS recentAge', 'LATEST_BY_OFFSET(weight) AS recentweight'], {topic:'newTopic'},{WHERE: 'age >= 21', GROUP_BY: 'name'});
104
+ // const tables = await client.ksql('LIST TABLES;');
105
+ // const allTables = tables.tables;
106
+ // let tableCheck = false;
107
+ // for (let i = 0; i < allTables.length; i++){
108
+ // if (allTables[i].name === 'TABLEOFSTREAM') {
109
+ // tableCheck = true;
110
+ // break;
111
+ // }
112
+ // }
113
+ // expect(tableCheck).toEqual(true);
114
+
115
+ // })
116
+ // it('materialized table view updates with source stream', async () => {
117
+ // let rowCheck = false;
118
+ // // push query for the table
119
+ // // console.log('testing materialized view')
120
+ // await client.push('SELECT * FROM TABLEOFSTREAM EMIT CHANGES LIMIT 1;', async (data) => {
121
+ // console.log('QUERY INFO',data)
122
+ // if (Array.isArray(JSON.parse(data))){
123
+ // if (JSON.parse(data)[0] === "firstTester" && JSON.parse(data)[1] === 25 && JSON.parse(data)[2] === 130){
124
+ // rowCheck = true;
125
+ // }
126
+ // }
127
+ // })
128
+ // await client.insertStream('NEWTESTSTREAM', [{"NAME":"firstTester", "AGE":25, "LOCATION": "Seattle", "WEIGHT": 130}]);
129
+ // await waitForExpect(() => expect(rowCheck).toEqual(true))
130
+ // })
131
+ // })
132
+
87
133
describe ( '--Health Tests--' , ( ) => {
88
134
beforeAll ( ( done ) => {
89
135
client = new ksqljs ( { ksqldbURL : 'http://localhost:8088' } ) ;
90
136
done ( ) ;
91
137
} ) ;
92
-
138
+
93
139
afterAll ( async ( ) => {
94
140
await client . ksql ( 'DROP STREAM IF EXISTS TESTSTREAM2;' ) ;
95
141
} )
@@ -114,7 +160,7 @@ describe('--Integration Tests--', () => {
114
160
queryId : null
115
161
} ) ) ;
116
162
} )
117
-
163
+
118
164
it ( '.inspectServerInfo returns the server info and status' , async ( ) => {
119
165
const status = await client . inspectServerInfo ( ) ;
120
166
// should return something like: {
@@ -133,7 +179,7 @@ describe('--Integration Tests--', () => {
133
179
} )
134
180
} ) ) ;
135
181
} )
136
-
182
+
137
183
it ( '.inspectServerHealth returns the server health' , async ( ) => {
138
184
const status = await client . inspectServerHealth ( ) ;
139
185
// should return something like: {
@@ -154,7 +200,7 @@ describe('--Integration Tests--', () => {
154
200
} )
155
201
) ;
156
202
} )
157
-
203
+
158
204
it ( '.inspectClusterStatus returns the cluster status' , async ( ) => {
159
205
const status = await client . inspectClusterStatus ( ) ;
160
206
// should return something like: {
@@ -171,13 +217,13 @@ describe('--Integration Tests--', () => {
171
217
} )
172
218
) ;
173
219
} )
174
-
220
+
175
221
it ( '.isValidProperty returns true if a server configuration property is not prohibited from setting' , async ( ) => {
176
222
const status = await client . isValidProperty ( 'test' ) ;
177
223
// should return true
178
224
expect ( status . data ) . toEqual ( true ) ;
179
225
} )
180
-
226
+
181
227
// it('isValidProperty returns an error if the server property is prohibited from setting', async () => {
182
228
// const status = await client.isValidProperty('ksql.connect.url');
183
229
// // should return something like
@@ -193,4 +239,4 @@ describe('--Integration Tests--', () => {
193
239
// }));
194
240
// })
195
241
} )
196
- } )
242
+ } )
0 commit comments