Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 54 additions & 35 deletions packages/neo4j-driver-deno/test/neo4j.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,58 +27,77 @@ const scheme = env.TEST_NEO4J_SCHEME || 'bolt'
const boltPort = env.TEST_NEO4J_BOLT_PORT || 7687
const uri = `${scheme}://${hostname}:${boltPort}`
const authToken = neo4j.auth.basic(username, password)
const testContainersDisabled = env.TEST_CONTAINERS_DISABLED !== undefined
? env.TEST_CONTAINERS_DISABLED.toUpperCase() === 'TRUE'
: false

// Deno will fail with resource leaks
Deno.test('neo4j.driver should be able to use explicity resource management', async () => {
await using driver = neo4j.driver(uri, authToken)
Deno.test({
name: 'neo4j.driver should be able to use explicity resource management',
ignore: !testContainersDisabled,
async fn() {
await using driver = neo4j.driver(uri, authToken)

await driver.executeQuery('RETURN 1')
})

// Deno will fail with resource leaks
Deno.test('driver.session should be able to use explicity resource management', async () => {
await using driver = neo4j.driver(uri, authToken)
await using session = driver.session()

await session.executeRead(tx => "RETURN 1")
await driver.executeQuery('RETURN 1')
}
})


// Deno will fail with resource leaks
Deno.test('session.beginTransaction should rollback the transaction if not committed', async () => {
await using driver = neo4j.driver(uri, authToken)
await using session = driver.session()
const name = "Must Be Conor"
Deno.test({
name: 'driver.session should be able to use explicity resource management',
ignore: !testContainersDisabled,
async fn() {
await using driver = neo4j.driver(uri, authToken)
await using session = driver.session()

await session.executeRead(tx => "RETURN 1")

{
await using tx = session.beginTransaction()
await tx.run('CREATE (p:Person { name:$name }) RETURN p', { name }).summary()
}

const { records } = await driver.executeQuery('MATCH (p:Person { name:$name }) RETURN p', { name })
assertEquals(records.length, 0)
})


// Deno will fail with resource leaks
Deno.test('session.beginTransaction should noop if resource committed', async () => {
await using driver = neo4j.driver(uri, authToken)
const name = "Must Be Conor"

try {
Deno.test({
name: 'session.beginTransaction should rollback the transaction if not committed',
ignore: !testContainersDisabled,
async fn() {
await using driver = neo4j.driver(uri, authToken)
await using session = driver.session()

const name = "Must Be Conor"

{
await using tx = session.beginTransaction()
await tx.run('CREATE (p:Person { name:$name }) RETURN p', { name }).summary()
await tx.commit()
}

const { records } = await driver.executeQuery('MATCH (p:Person { name:$name }) RETURN p', { name })
assertEquals(records.length, 1)
} finally {
// cleaning up
await driver.executeQuery('MATCH (p:Person { name:$name }) DELETE(p)', { name })
assertEquals(records.length, 0)
}
})


// Deno will fail with resource leaks
Deno.test({
name: 'session.beginTransaction should noop if resource committed',
ignore: !testContainersDisabled,
async fn() {
await using driver = neo4j.driver(uri, authToken)
const name = "Must Be Conor"

try {
await using session = driver.session()

{
await using tx = session.beginTransaction()
await tx.run('CREATE (p:Person { name:$name }) RETURN p', { name }).summary()
await tx.commit()
}

const { records } = await driver.executeQuery('MATCH (p:Person { name:$name }) RETURN p', { name })
assertEquals(records.length, 1)
} finally {
// cleaning up
await driver.executeQuery('MATCH (p:Person { name:$name }) DELETE(p)', { name })
}

}
})