import { RequestDecorator , RequestOptions , TestHelper } from '@libstack/tester' ; import server from './mock.server' ; export const testHelper = new TestHelper ( server ) ; class AuthenticationDecorator implements RequestDecorator { private token : string ; constructor ( private user , private pass ) { } private async performLogin ( ) { return `${ this . user }-${ this . pass }` ; } /**
     * This function will be called on every request
     */ async decorateRequest ( request ) { if ( ! this . token ) { this . token = await this . performLogin ( ) ; } request . headers . Authorization = 'Bearer ' + this . token ; return request ; } } export const admin = new AuthenticationDecorator ( 'admin' , '123456' ) ; export const user = new AuthenticationDecorator ( 'user' , '123456' ) ;