<?php

namespace AuthStack\Driver\System\tests\units;

use mageekguy\atoum;
use AuthStack\Driver\System\User;
use AuthStack\Driver\Collection\TwoFactorKeys;
use AuthStack\Driver\System\Driver as SystemDriver;

class Driver extends atoum
{
    public function testAuthentication()
    {
        $this
            ->given($conn = SystemDriver::initialize('', 1))
            ->then
                ->object($conn)->isInstanceOf(SystemDriver::class)
                ->boolean($conn->connect())->isTrue()
                ->boolean($conn->authenticate(['username' => 'nikola@buckhill.co.uk', 'password' => 'Letmein123!']))->isTrue()
                ->object($conn->getUser())->isInstanceOf(User::class)
                ->integer($conn->getUser()->getAuthstackID())->isEqualTo(1)
                ->object($conn->getUser()->getKeyCollection())->isInstanceOf(TwoFactorKeys::class)
                ->integer($conn->getUser()->getKeyCollection()->size())->isEqualTo(1)
                ->array($conn->getUser()->getKeyCollection()->getU2FKeyIds())->hasSize(1)
        ;
    }

    public function testGetById()
    {
        $this
            ->given($conn = SystemDriver::initialize('', 1))
            ->then
            ->object($conn)->isInstanceOf(SystemDriver::class)
            ->boolean($conn->connect())->isTrue()
            ->object($conn->getUserByPrimaryKey(1))->isInstanceOf(User::class)
        ;
    }

    public function testGetByUsername()
    {
        $this
            ->given($conn = SystemDriver::initialize('', 1))
            ->then
            ->object($conn)->isInstanceOf(SystemDriver::class)
            ->boolean($conn->connect())->isTrue()
            ->object($conn->getUserByUsername('nikola@buckhill.co.uk'))->isInstanceOf(User::class)
        ;
    }
}