Skip to content

Commit 2023ef2

Browse files
committed
Applying linter to packages/core/test
1 parent 00959be commit 2023ef2

12 files changed

+541
-514
lines changed

packages/core/test/auth.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import auth from '../src/auth'
2020

2121
describe('auth', () => {
22-
2322
test('.bearer()', () => {
2423
expect(auth.bearer('==Qyahiadakkda')).toEqual({ scheme: 'bearer', credentials: '==Qyahiadakkda' })
2524
})

packages/core/test/driver.test.ts

Lines changed: 29 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
* See the License for the specific language governing permissions and
1717
* limitations under the License.
1818
*/
19+
/* eslint-disable @typescript-eslint/promise-function-async */
1920
import { ConnectionProvider, newError, ServerInfo, Session } from '../src'
2021
import Driver, { READ } from '../src/driver'
2122
import { Bookmarks } from '../src/internal/bookmarks'
@@ -47,26 +48,24 @@ describe('Driver', () => {
4748
})
4849

4950
afterEach(async () => {
50-
if (driver) {
51+
if (driver != null) {
5152
await driver.close()
5253
driver = null
5354
}
5455
})
5556

56-
5757
describe('.session()', () => {
5858
it('should create the session with impersonated user', () => {
5959
const impersonatedUser = 'the impostor'
6060

61-
const session = driver!.session({ impersonatedUser })
61+
const session = driver?.session({ impersonatedUser })
6262

6363
expect(session).not.toBeUndefined()
6464
expect(createSession).toHaveBeenCalledWith(expectedSessionParams({ impersonatedUser }))
6565
})
6666

67-
6867
it('should create the session without impersonated user', () => {
69-
const session = driver!.session()
68+
const session = driver?.session()
7069

7170
expect(session).not.toBeUndefined()
7271
expect(createSession).toHaveBeenCalledWith(expectedSessionParams())
@@ -77,12 +76,12 @@ describe('Driver', () => {
7776
[null, Bookmarks.empty()],
7877
['bookmark', new Bookmarks('bookmark')],
7978
[['bookmark'], new Bookmarks(['bookmark'])],
80-
[['bookmark1', 'bookmark2'], new Bookmarks(['bookmark1', 'bookmark2'])],
79+
[['bookmark1', 'bookmark2'], new Bookmarks(['bookmark1', 'bookmark2'])]
8180
])('should create session using param bookmarks', (bookmarks, expectedBookmarks) => {
82-
// @ts-ignore
83-
const session = driver!.session({ bookmarks })
81+
// @ts-expect-error
82+
const session = driver?.session({ bookmarks })
8483

85-
expect(session.lastBookmarks()).toEqual(expectedBookmarks.values())
84+
expect(session?.lastBookmarks()).toEqual(expectedBookmarks.values())
8685
})
8786
})
8887

@@ -96,11 +95,11 @@ describe('Driver', () => {
9695
])('.supportsMultiDb() => %s', (_, expectedPromise) => {
9796
connectionProvider.supportsMultiDb = jest.fn(() => expectedPromise)
9897

99-
const promise: Promise<boolean> = driver!.supportsMultiDb()
98+
const promise: Promise<boolean> | undefined = driver?.supportsMultiDb()
10099

101100
expect(promise).toBe(expectedPromise)
102101

103-
promise.catch(_ => 'Do nothing').finally(() => {})
102+
promise?.catch(_ => 'Do nothing').finally(() => {})
104103
})
105104

106105
it.each([
@@ -115,11 +114,11 @@ describe('Driver', () => {
115114
() => expectedPromise
116115
)
117116

118-
const promise: Promise<boolean> = driver!.supportsTransactionConfig()
117+
const promise: Promise<boolean> | undefined = driver?.supportsTransactionConfig()
119118

120119
expect(promise).toBe(expectedPromise)
121120

122-
promise.catch(_ => 'Do nothing').finally(() => {})
121+
promise?.catch(_ => 'Do nothing').finally(() => {})
123122
})
124123

125124
it.each([
@@ -134,23 +133,23 @@ describe('Driver', () => {
134133
() => expectedPromise
135134
)
136135

137-
const promise: Promise<boolean> = driver!.supportsUserImpersonation()
136+
const promise: Promise<boolean> | undefined = driver?.supportsUserImpersonation()
138137

139138
expect(promise).toBe(expectedPromise)
140139

141-
promise.catch(_ => 'Do nothing').finally(() => {})
140+
promise?.catch(_ => 'Do nothing').finally(() => {})
142141
})
143142

144143
it.each([
145144
[{ encrypted: true }, true],
146145
[{ encrypted: false }, false],
147146
[{}, false],
148147
[{ encrypted: 'ENCRYPTION_ON' }, true],
149-
[{ encrypted: 'ENCRYPTION_OFF' }, false],
148+
[{ encrypted: 'ENCRYPTION_OFF' }, false]
150149
])('.isEncrypted()', (config, expectedValue) => {
151150
const connectionProvider = new ConnectionProvider()
152151
connectionProvider.close = jest.fn(() => Promise.resolve())
153-
// @ts-ignore
152+
// @ts-expect-error
154153
const driver = new Driver(META_INFO, config, mockCreateConnectonProvider(connectionProvider))
155154

156155
expect(driver.isEncrypted()).toEqual(expectedValue)
@@ -170,7 +169,7 @@ describe('Driver', () => {
170169
// No connection timeouts should be considered valid, since it means
171170
// the user doesn't case about the connection timeout at all.
172171
[{ connectionTimeout: 0, connectionAcquisitionTimeout: 2000 }, true],
173-
[{ connectionTimeout: -1, connectionAcquisitionTimeout: 2000 }, true],
172+
[{ connectionTimeout: -1, connectionAcquisitionTimeout: 2000 }, true]
174173
])('should emit warning if `connectionAcquisitionTimeout` and `connectionTimeout` are conflicting. [%o} ', async (config, valid) => {
175174
const logging = {
176175
level: 'warn' as LogLevel,
@@ -202,17 +201,17 @@ describe('Driver', () => {
202201
[{ database: undefined }, 'Promise.resolve(ServerInfo>)', Promise.resolve(new ServerInfo())],
203202
[{ database: undefined }, 'Promise.reject(Error)', Promise.reject(newError('something went wrong'))],
204203
[{ database: 'db' }, 'Promise.resolve(ServerInfo>)', Promise.resolve(new ServerInfo())],
205-
[{ database: 'db' }, 'Promise.reject(Error)', Promise.reject(newError('something went wrong'))],
204+
[{ database: 'db' }, 'Promise.reject(Error)', Promise.reject(newError('something went wrong'))]
206205
])('.verifyConnectivity(%o) => %s', (input: { database?: string } | undefined, _, expectedPromise) => {
207206
connectionProvider.verifyConnectivityAndGetServerInfo = jest.fn(() => expectedPromise)
208207

209-
const promise: Promise<ServerInfo> = driver!.verifyConnectivity(input)
208+
const promise: Promise<ServerInfo> | undefined = driver?.verifyConnectivity(input)
210209

211210
expect(promise).toBe(expectedPromise)
212211
expect(connectionProvider.verifyConnectivityAndGetServerInfo)
213-
.toBeCalledWith({ database: input && input.database ? input.database : '', accessMode: READ })
212+
.toBeCalledWith({ database: input?.database ?? '', accessMode: READ })
214213

215-
promise.catch(_ => 'Do nothing').finally(() => { })
214+
promise?.catch(_ => 'Do nothing').finally(() => { })
216215
})
217216

218217
it.each([
@@ -223,20 +222,20 @@ describe('Driver', () => {
223222
[{ database: undefined }, 'Promise.resolve(ServerInfo>)', Promise.resolve(new ServerInfo())],
224223
[{ database: undefined }, 'Promise.reject(Error)', Promise.reject(newError('something went wrong'))],
225224
[{ database: 'db' }, 'Promise.resolve(ServerInfo>)', Promise.resolve(new ServerInfo())],
226-
[{ database: 'db' }, 'Promise.reject(Error)', Promise.reject(newError('something went wrong'))],
225+
[{ database: 'db' }, 'Promise.reject(Error)', Promise.reject(newError('something went wrong'))]
227226
])('.getServerInfo(%o) => %s', (input: { database?: string } | undefined, _, expectedPromise) => {
228227
connectionProvider.verifyConnectivityAndGetServerInfo = jest.fn(() => expectedPromise)
229228

230-
const promise: Promise<ServerInfo> = driver!.getServerInfo(input)
229+
const promise: Promise<ServerInfo> | undefined = driver?.getServerInfo(input)
231230

232231
expect(promise).toBe(expectedPromise)
233232
expect(connectionProvider.verifyConnectivityAndGetServerInfo)
234-
.toBeCalledWith({ database: input && input.database ? input.database : '', accessMode: READ })
233+
.toBeCalledWith({ database: input?.database ?? '', accessMode: READ })
235234

236-
promise.catch(_ => 'Do nothing').finally(() => { })
235+
promise?.catch(_ => 'Do nothing').finally(() => { })
237236
})
238237

239-
function mockCreateConnectonProvider(connectionProvider: ConnectionProvider) {
238+
function mockCreateConnectonProvider (connectionProvider: ConnectionProvider) {
240239
return (
241240
id: number,
242241
config: Object,
@@ -245,20 +244,20 @@ describe('Driver', () => {
245244
) => connectionProvider
246245
}
247246

248-
function expectedSessionParams(extra: any = {}) {
247+
function expectedSessionParams (extra: any = {}): any {
249248
return {
250249
bookmarks: Bookmarks.empty(),
251250
config: {
252251
connectionAcquisitionTimeout: 60000,
253252
fetchSize: 1000,
254253
maxConnectionLifetime: 3600000,
255254
maxConnectionPoolSize: 100,
256-
connectionTimeout: 30000,
255+
connectionTimeout: 30000
257256
},
258257
connectionProvider,
259258
database: '',
260259
fetchSize: 1000,
261-
mode: "WRITE",
260+
mode: 'WRITE',
262261
reactive: false,
263262
impersonatedUser: undefined,
264263
...extra

packages/core/test/error.test.ts

Lines changed: 25 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,13 @@ describe('newError', () => {
4646
})
4747

4848
describe('isRetriableError()', () => {
49-
it.each(getRetriableErrorsFixture())
50-
('should return true for error with code %s', error => {
51-
expect(isRetriableError(error)).toBe(true)
52-
})
49+
it.each(getRetriableErrorsFixture())('should return true for error with code %s', error => {
50+
expect(isRetriableError(error)).toBe(true)
51+
})
5352

54-
it.each(getNonRetriableErrorsFixture())
55-
('should return false for error with code %s', error => {
56-
expect(isRetriableError(error)).toBe(false)
57-
})
53+
it.each(getNonRetriableErrorsFixture())('should return false for error with code %s', error => {
54+
expect(isRetriableError(error)).toBe(false)
55+
})
5856
})
5957

6058
describe('Neo4jError', () => {
@@ -90,38 +88,34 @@ describe('Neo4jError', () => {
9088
expect(error.constructor).toEqual(Neo4jError)
9189
})
9290

93-
test.each(getRetriableCodes())
94-
('should define retriable as true for error with code %s', code => {
95-
const error = new Neo4jError('message', code)
91+
test.each(getRetriableCodes())('should define retriable as true for error with code %s', code => {
92+
const error = new Neo4jError('message', code)
9693

97-
expect(error.retriable).toBe(true)
98-
})
94+
expect(error.retriable).toBe(true)
95+
})
9996

100-
test.each(getNonRetriableCodes())
101-
('should define retriable as false for error with code %s', code => {
102-
const error = new Neo4jError('message', code)
97+
test.each(getNonRetriableCodes())('should define retriable as false for error with code %s', code => {
98+
const error = new Neo4jError('message', code)
10399

104-
expect(error.retriable).toBe(false)
105-
})
100+
expect(error.retriable).toBe(false)
101+
})
106102

107103
describe('.isRetriable()', () => {
108-
it.each(getRetriableErrorsFixture())
109-
('should return true for error with code %s', error => {
110-
expect(Neo4jError.isRetriable(error)).toBe(true)
111-
})
112-
113-
it.each(getNonRetriableErrorsFixture())
114-
('should return false for error with code %s', error => {
115-
expect(Neo4jError.isRetriable(error)).toBe(false)
116-
})
104+
it.each(getRetriableErrorsFixture())('should return true for error with code %s', error => {
105+
expect(Neo4jError.isRetriable(error)).toBe(true)
106+
})
107+
108+
it.each(getNonRetriableErrorsFixture())('should return false for error with code %s', error => {
109+
expect(Neo4jError.isRetriable(error)).toBe(false)
110+
})
117111
})
118112
})
119113

120-
function getRetriableErrorsFixture () {
114+
function getRetriableErrorsFixture (): Array<[Neo4jError]> {
121115
return getRetriableCodes().map(code => [newError('message', code)])
122116
}
123117

124-
function getNonRetriableErrorsFixture () {
118+
function getNonRetriableErrorsFixture (): any[] {
125119
return [
126120
null,
127121
undefined,
@@ -132,7 +126,7 @@ function getNonRetriableErrorsFixture () {
132126
]
133127
}
134128

135-
function getRetriableCodes () {
129+
function getRetriableCodes (): string[] {
136130
return [
137131
SERVICE_UNAVAILABLE,
138132
SESSION_EXPIRED,
@@ -142,7 +136,7 @@ function getRetriableCodes () {
142136
]
143137
}
144138

145-
function getNonRetriableCodes () {
139+
function getNonRetriableCodes (): string[] {
146140
return [
147141
'Neo.TransientError.Transaction.Terminated',
148142
'Neo.DatabaseError.General.UnknownError',

0 commit comments

Comments
 (0)