import { wrapToughCookie } from '@skolplattformen/api' ; import { CookieJar } from 'tough-cookie' ; import { ApiHjarntorget } from './apiHjarntorget' ; const setupSuccessfullLoginInitiation = ( fetcherMock ) => { fetcherMock . mockReturnValueOnce ( Promise . resolve ( { url : 'some url with url encoded at the end?return=hello' , } ) ) ; fetcherMock . mockReturnValueOnce ( Promise . resolve ( { url : 'some url with url encoded at the end?Target=hello' , } ) ) ; fetcherMock . mockReturnValueOnce ( Promise . resolve ( { text : jest . fn ( ) . mockReturnValue ( Promise . resolve ( `
        <html>
        <body>
        <input name="RelayState" value="aUUID"></input>
        <input name="SAMLRequest" value="somebase64value"></input>
        </body>
        </html>` ) ) , } ) ) ; fetcherMock . mockReturnValueOnce ( Promise . resolve ( { url : 'some url to a mvghost' , } ) ) ; fetcherMock . mockReturnValueOnce ( Promise . resolve ( { url : 'some base url to a mvghost to use when polling status' , } ) ) ; } ; const setupSuccessfullBankIdLogin = ( fetcherMock ) => { fetcherMock . mockReturnValueOnce ( Promise . resolve ( { json : jest . fn ( ) . mockReturnValue ( Promise . resolve ( { infotext : '' , location : 'an url to go to confirm the login' , } ) ) , } ) ) ; fetcherMock . mockReturnValueOnce ( Promise . resolve ( { text : jest . fn ( ) . mockReturnValue ( Promise . resolve ( `
        <html>
        <body>
        <textarea name="RelayState">relay state probably same uuid as before</textarea>
        <textarea name="SAMLResponse">base64 encoded saml response</textarea>
        </body>
        </html>` ) ) , } ) ) ; fetcherMock . mockReturnValueOnce ( Promise . resolve ( { text : jest . fn ( ) . mockReturnValue ( Promise . resolve ( `
        <html>
        <body>
        <input name="RelayState" value="aUUID"></input>
        <input name="SAMLResponse" value="somebase64value"></input>
        </body>
        </html>` ) ) , } ) ) ; fetcherMock . mockReturnValueOnce ( Promise . resolve ( { status : 200 } ) ) ; } ; describe ( 'api' , ( ) => { let fetcherMock ; let api ; beforeEach ( ( ) => { const fetcher = jest . fn ( ) ; fetcherMock = fetcher as jest . Mock ; const cookieManager = wrapToughCookie ( new CookieJar ( ) ) ; cookieManager . clearAll ( ) ; api = new ApiHjarntorget ( jest . fn ( ) , cookieManager ) ; api . replaceFetcher ( fetcher ) ; } ) ; it ( 'works' , ( ) => { expect ( 1 + 1 ) . toBe ( 2 ) ; } ) ; } ) ;