import { GenericContainer , Wait } from "../.." ; import { StartedTestContainer } from "../../test-container" ; import { Port } from "../../port" ; import { RandomUuid } from "../../uuid" ; import { AbstractStartedContainer } from "../abstract-started-container" ; const BOLT_PORT = 7687 ; const HTTP_PORT = 7474 ; const USERNAME = "neo4j" ; export class Neo4jContainer extends GenericContainer { private password = new RandomUuid ( ) . nextUuid ( ) ; private apoc = false ; private ttl ? : number ; constructor ( image = "neo4j:4.3.2" ) { super ( image ) ; } public withPassword ( password ) { this . password = password ; return this ; } public withApoc ( ) { this . apoc = true ; return this ; } public withTtl ( schedule = 5 ) { this . ttl = schedule ; return this ; } public async start ( ) { this . withExposedPorts ( BOLT_PORT , HTTP_PORT ) . withWaitStrategy ( Wait . forLogMessage ( "Started." ) ) . withEnv ( "NEO4J_AUTH" , `${ USERNAME }/${ this . password }` ) . withStartupTimeout ( 120000 ) ; if ( this . apoc ) { this . withEnv ( "NEO4JLABS_PLUGINS" , '["apoc"]' ) . withEnv ( "NEO4J_dbms_security_procedures_unrestricted" , "apoc.*" ) ; } if ( this . ttl ) { this . withEnv ( "NEO4J_apoc_ttl_enabled" , "true" ) . withEnv ( "NEO4J_apoc_ttl_schedule" , this . ttl . toString ( ) ) ; } return new StartedNeo4jContainer ( await super . start ( ) , this . password ) ; } } export class StartedNeo4jContainer extends AbstractStartedContainer { private readonly boltPort : Port ; private readonly httpPort : Port ; constructor ( startedTestContainer , private readonly password ) { super ( startedTestContainer ) ; this . boltPort = this . startedTestContainer . getMappedPort ( BOLT_PORT ) ; this . httpPort = this . startedTestContainer . getMappedPort ( HTTP_PORT ) ; } public getBoltUri ( ) { return `bolt://${ this . getHost ( ) }:${ this . boltPort }/` ; } public getHttpUri ( ) { return `http://${ this . getHost ( ) }:${ this . httpPort }/` ; } public getPassword ( ) { return this . password ; } public getUsername ( ) { return USERNAME ; } }