import { config } from "dotenv" ; config ( ) ; import Client from "../client" ; import Environment from "../environment" ; import FakeServer from "../fakeServer" ; import RequestResponseLog from "../requestResponseLog" ; import RequestResponseLogEntry from "../requestResponseLogEntry" ; import Server , { IServerOptions } from "../server" ; import Logger from "../logger" ; const log = new Logger ( ) ; export const recordingModeActive = ( ) : boolean => { if ( process . argv . find ( ( element ) => element === "--record" ) ) { return true ; } return false ; } ; export const getNextcloudClient = async ( context ) : Promise < Client > => { const rrLog = RequestResponseLog . getInstance ( ) ; rrLog . baseDirectory = "src/test/recordings/" ; await rrLog . setContext ( context ) ; if ( recordingModeActive ( ) ) { const serverOptions = { url : Environment . getNextcloudUrl ( ) , basicAuth : { username : Environment . getUserName ( ) , password : Environment . getPassword ( ) , } , logRequestResponse : Environment . getRecordingActiveIndicator ( ) , } ; const ncserver = new Server ( serverOptions ) ; ncserver . logRequestResponse = true ; log . info ( "Test recording: " + rrLog . getFileName ( ) ) ; return new Client ( ncserver ) ; } else { let entries ; try { entries = await rrLog . getEntries ( ) ; } catch ( e ) { entries = [ ] ; } const fncserver = new FakeServer ( entries ) ; return new Client ( fncserver ) ; } } ;