/**
 * Copyright (C) Oranda - All Rights Reserved (January 2019 - January 2021)
 */ import { HaliaPlugin , Program , HaliaProgramAPI , HaliaProgram } from "../src/core-plugin" ; import { HaliaStack } from "../src/halia" ; import { expect } from "chai" ; describe ( "Halia" , ( ) => { let haliaStack ; before ( async ( ) => { interface PIImports { haliaProgram : HaliaProgramAPI ; } class PIAPI { public messages : string [ ] = [ ] ; public addMessage = ( message ) => { this . messages . push ( message + ":PI" ) ; } ; } const PI = { id : "pI" , name : "PI" , description : "Plugin I:  Export a function to add messages which will be returned by the Halia Program." , dependencies : [ HaliaProgram . id ] , install : ( { haliaProgram } ) => { const pIAPI = new PIAPI ( ) ; haliaProgram . registerCode ( ( ) => { return pIAPI . messages ; } ) ; return pIAPI ; } } ; haliaStack = new HaliaStack ( ) ; haliaStack . register ( HaliaProgram ) ; haliaStack . register ( PI ) ; class PIIImports { pI : PIAPI ; } class PIIAPI { constructor ( private pI ) { } public messages : string [ ] = [ ] ; public addMessage = ( message ) => { this . pI . addMessage ( message + ":PII" ) ; } ; } const PII = { id : "pII" , name : "PII" , description : "Plugin II:  Build a function to wrap the PI 'addMessage' function.  It adds ':II' to the message" , dependencies : [ PI . id ] , install : ( { pI } ) => { const pIIAPI = new PIIAPI ( pI ) ; return pIIAPI ; } } ; haliaStack . register ( PII ) ; interface PIIIImports { pII : PIIAPI ; } const PIII = { name : "Plugin III" , id : "pIII" , description : "Plugin III:  Actually add the message using the P2 API." , dependencies : [ PII . id ] , install : ( { pII } ) => { pII . addMessage ( "PIII" ) ; } } ; haliaStack . register ( PIII ) ; } ) ; it ( "should successfully start the program" , async ( ) => { await haliaStack . build ( ) ; const progAPI = haliaStack . getExports ( HaliaProgram . id ) ; const res = await progAPI . run ( ) ; expect ( JSON . stringify ( res [ 0 ] ) ) . equals ( JSON . stringify ( [ "PIII:PII:PI" ] ) ) ; } ) ; } ) ;