Skip to content

Commit b0f7aa3

Browse files
committed
browser bolt agent test
1 parent 9d6c614 commit b0f7aa3

File tree

4 files changed

+46
-3
lines changed

4 files changed

+46
-3
lines changed

packages/core/src/internal/bolt-agent/browser/bolt-agent.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,10 @@
1717
* limitations under the License.
1818
*/
1919
/* eslint-disable */
20-
export function fromVersion (version: string): string {
20+
// @ts-ignore: browser code so must be skipped by ts
21+
export function fromVersion (version: string, windowProvider = () => window): string {
2122
// @ts-ignore: browser code so must be skipped by ts
22-
const APP_VERSION = window.navigator.appVersion
23+
const APP_VERSION = windowProvider().navigator.appVersion
2324

2425
//APP_VERSION looks like 5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Safari/537.36
2526
const OS = APP_VERSION.split("(")[1].split(")")[0];

packages/core/src/internal/bolt-agent/deno/bolt-agent.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,13 @@
1919

2020
/* eslint-disable */
2121
export function fromVersion (version: string): string {
22+
//@ts-ignore
2223
const HOST_ARCH = Deno.build.arch
24+
//@ts-ignore
2325
const DENO_VERSION = `Deno/${Deno.version.deno}`
26+
//@ts-ignore
2427
const NODE_V8_VERSION = Deno.version.v8
28+
//@ts-ignore
2529
const OS_NAME_VERSION = `${Deno.build.os} ${Deno.osRelease}`
2630

2731
return `neo4j-javascript/${version} (${OS_NAME_VERSION}; ${HOST_ARCH}) ${DENO_VERSION} (v8 ${NODE_V8_VERSION})`
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/**
2+
* Copyright (c) "Neo4j"
3+
* Neo4j Sweden AB [http://neo4j.com]
4+
*
5+
* This file is part of Neo4j.
6+
*
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
*/
19+
import { fromVersion } from '../../../../src/internal/bolt-agent/browser'
20+
21+
describe('#unit boltAgent', () => {
22+
// This test is very fragile but the exact look of this string should not change without PM approval
23+
it('should return the correct bolt agent for specified version', () => {
24+
const version = '5.3'
25+
const windowProvider = (): any => {
26+
return {
27+
navigator: {
28+
appVersion: '5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Safari/537.36'
29+
}
30+
}
31+
}
32+
33+
const boltAgent = fromVersion(version, windowProvider)
34+
35+
expect(boltAgent.length === 0).toBeFalsy()
36+
expect(boltAgent).toEqual(`neo4j-javascript/${version} (Macintosh; Intel Mac OS X 10_15_7)`)
37+
})
38+
})

packages/core/test/internal/bolt-agent/node/bolt-agent.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ describe('#unit boltAgent', () => {
2929
const NODE_VERSION = 'Node/' + process.versions.node
3030
const NODE_V8_VERSION = process.versions.v8
3131

32-
const osName = BoltAgent.mapOs(os.platform())
32+
const osName = os.platform()
3333

3434
expect(boltAgent.length === 0).toBeFalsy()
3535
expect(boltAgent).toContain(`neo4j-javascript/${version}`)

0 commit comments

Comments
 (0)