Skip to content

Commit 5c33bc0

Browse files
committed
Fixes after code review for examples test
* use constants for user, password and uri * test custom auth with basic auth params
1 parent a463e74 commit 5c33bc0

File tree

1 file changed

+27
-37
lines changed

1 file changed

+27
-37
lines changed

test/v1/examples.test.js

Lines changed: 27 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,15 @@ describe('examples', () => {
3434
let testResultPromise;
3535
let resolveTestResultPromise;
3636

37+
const user = 'neo4j';
38+
const password = 'neo4j';
39+
const uri = 'bolt://localhost:7687';
40+
3741
beforeAll(() => {
3842
originalTimeout = jasmine.DEFAULT_TIMEOUT_INTERVAL;
3943
jasmine.DEFAULT_TIMEOUT_INTERVAL = 10000;
4044

41-
driverGlobal = neo4j.driver('bolt://localhost:7687', neo4j.auth.basic('neo4j', 'neo4j'));
45+
driverGlobal = neo4j.driver(uri, neo4j.auth.basic('neo4j', 'neo4j'));
4246
});
4347

4448
beforeEach(done => {
@@ -89,11 +93,8 @@ describe('examples', () => {
8993
});
9094

9195
it('basic auth example', done => {
92-
const user = 'neo4j';
93-
const password = 'neo4j';
94-
9596
// tag::basic-auth[]
96-
const driver = neo4j.driver('bolt://localhost:7687', neo4j.auth.basic(user, password));
97+
const driver = neo4j.driver(uri, neo4j.auth.basic(user, password));
9798
// end::basic-auth[]
9899

99100
driver.onCompleted = () => {
@@ -107,12 +108,9 @@ describe('examples', () => {
107108
});
108109

109110
it('config max retry time example', done => {
110-
const user = 'neo4j';
111-
const password = 'neo4j';
112-
113111
// tag::config-max-retry-time[]
114112
const maxRetryTimeMs = 15 * 1000; // 15 seconds
115-
const driver = neo4j.driver('bolt://localhost:7687', neo4j.auth.basic(user, password),
113+
const driver = neo4j.driver(uri, neo4j.auth.basic(user, password),
116114
{
117115
maxTransactionRetryTime: maxRetryTimeMs
118116
}
@@ -130,11 +128,8 @@ describe('examples', () => {
130128
});
131129

132130
it('config trust example', done => {
133-
const user = 'neo4j';
134-
const password = 'neo4j';
135-
136131
// tag::config-trust[]
137-
const driver = neo4j.driver('bolt://localhost:7687', neo4j.auth.basic(user, password),
132+
const driver = neo4j.driver(uri, neo4j.auth.basic(user, password),
138133
{
139134
encrypted: 'ENCRYPTION_ON',
140135
trust: 'TRUST_ALL_CERTIFICATES'
@@ -158,11 +153,8 @@ describe('examples', () => {
158153
});
159154

160155
it('config unencrypted example', done => {
161-
const user = 'neo4j';
162-
const password = 'neo4j';
163-
164156
// tag::config-unencrypted[]
165-
const driver = neo4j.driver('bolt://localhost:7687', neo4j.auth.basic(user, password),
157+
const driver = neo4j.driver(uri, neo4j.auth.basic(user, password),
166158
{
167159
encrypted: 'ENCRYPTION_OFF'
168160
}
@@ -179,21 +171,25 @@ describe('examples', () => {
179171
});
180172
});
181173

182-
it('custom auth example', () => {
183-
const principal = 'principal';
184-
const credentials = 'credentials';
185-
const realm = 'realm';
186-
const scheme = 'scheme';
174+
it('custom auth example', done => {
175+
const principal = user;
176+
const credentials = password;
177+
const realm = undefined;
178+
const scheme = 'basic';
187179
const parameters = {};
188180

189181
// tag::custom-auth[]
190-
const driver = neo4j.driver(
191-
'bolt://localhost:7687',
192-
neo4j.auth.custom(principal, credentials, realm, scheme, parameters)
193-
);
182+
const driver = neo4j.driver(uri, neo4j.auth.custom(principal, credentials, realm, scheme, parameters));
194183
// end::custom-auth[]
195184

196-
expect(driver).toBeDefined();
185+
driver.onCompleted = () => {
186+
done();
187+
};
188+
189+
const session = driver.session();
190+
session.run('RETURN 1').then(() => {
191+
session.close();
192+
});
197193
});
198194

199195
it('cypher error example', done => {
@@ -221,11 +217,8 @@ describe('examples', () => {
221217
});
222218

223219
it('driver lifecycle example', done => {
224-
const user = 'neo4j';
225-
const password = 'neo4j';
226-
227220
// tag::driver-lifecycle[]
228-
const driver = neo4j.driver('bolt://localhost:7687', neo4j.auth.basic(user, password));
221+
const driver = neo4j.driver(uri, neo4j.auth.basic(user, password));
229222

230223
driver.onCompleted = metadata => {
231224
console.log('Driver created');
@@ -251,11 +244,8 @@ describe('examples', () => {
251244
});
252245

253246
it('hello world example', done => {
254-
const user = 'neo4j';
255-
const password = 'neo4j';
256-
257247
// tag::hello-world[]
258-
const driver = neo4j.driver('bolt://localhost:7687', neo4j.auth.basic(user, password));
248+
const driver = neo4j.driver(uri, neo4j.auth.basic(user, password));
259249
const session = driver.session();
260250

261251
const resultPromise = session.writeTransaction(tx => tx.run(
@@ -395,11 +385,11 @@ describe('examples', () => {
395385
});
396386

397387
it('service unavailable example', done => {
398-
const user = 'neo4j';
388+
const uri = 'bolt://localhost:7688'; // wrong port
399389
const password = 'wrongPassword';
400390

401391
// tag::service-unavailable[]
402-
const driver = neo4j.driver('bolt://localhost:7688', neo4j.auth.basic(user, password), {maxTransactionRetryTime: 3000});
392+
const driver = neo4j.driver(uri, neo4j.auth.basic(user, password), {maxTransactionRetryTime: 3000});
403393
const session = driver.session();
404394

405395
const writeTxPromise = session.writeTransaction(tx => tx.run('CREATE (a:Item)'));

0 commit comments

Comments
 (0)