<?php

namespace Tests\Feature;

use App\MemberInfo;
use Mtc\Modules\Members\Models\Member;


class SiteOfOriginTest extends \Tests\TestCase
{

    public function testMemberSiteOfOriginRegistersOnceAndReturnsAppName()
    {
        $test_member = new Member();
        $test_member->save();

        MemberInfo::registerSiteOfOrigin($test_member, 1);

        $record_count = MemberInfo::query()
            ->where('member_id', $test_member->id)
            ->count()
        ;
        $this->assertSame(1, $record_count);

        // Re-registering should not create a duplicate
        MemberInfo::registerSiteOfOrigin($test_member, 1);

        $record_count = MemberInfo::query()
            ->where('member_id', $test_member->id)
            ->count()
        ;
        $this->assertSame(1, $record_count);

        $this->assertSame(config('app.name'), MemberInfo::getSiteOfOrigin($test_member));

        $test_member->delete();
    }

}
