withoutMiddleware( ThrottleRequests::class ); $this->withoutExceptionHandling(); $this->makeTestData(); } public function testCorrectRuleInit() { $settings = CompanySettings::defaults(); $settings->country_id = '276'; // germany $company = Company::factory()->create([ 'account_id' => $this->account->id, 'settings' => $settings ]); $client = Client::factory()->create([ 'user_id' => $this->user->id, 'company_id' => $company->id, 'country_id' => 276, 'shipping_country_id' => 276, ]); $process = new ProcessRule($company, $client); $process->run(); $this->assertEquals('de', $process->getVendorCountryCode()); $this->assertEquals('de', $process->getClientCountryCode()); $this->assertFalse($process->hasValidVatNumber()); $this->assertInstanceOf(Rule::class, $process->rule); $this->assertEquals(19, $process->getVatRate()); $this->assertEquals(7, $process->getVatReducedRate()); } public function testEuCorrectRuleInit() { $settings = CompanySettings::defaults(); $settings->country_id = '276'; // germany $company = Company::factory()->create([ 'account_id' => $this->account->id, 'settings' => $settings ]); $client = Client::factory()->create([ 'user_id' => $this->user->id, 'company_id' => $company->id, 'country_id' => 56, 'shipping_country_id' => 56, ]); $process = new ProcessRule($company, $client); $process->run(); $this->assertEquals('de', $process->getVendorCountryCode()); $this->assertEquals('be', $process->getClientCountryCode()); $this->assertFalse($process->hasValidVatNumber()); $this->assertInstanceOf(Rule::class, $process->rule); $this->assertEquals(21, $process->getVatRate()); $this->assertEquals(7, $process->getVatReducedRate()); } public function testForeignCorrectRuleInit() { $settings = CompanySettings::defaults(); $settings->country_id = '276'; // germany $company = Company::factory()->create([ 'account_id' => $this->account->id, 'settings' => $settings ]); $client = Client::factory()->create([ 'user_id' => $this->user->id, 'company_id' => $company->id, 'country_id' => 840, 'shipping_country_id' => 840, ]); $process = new ProcessRule($company, $client); $process->run(); $this->assertEquals('de', $process->getVendorCountryCode()); $this->assertEquals('us', $process->getClientCountryCode()); $this->assertFalse($process->hasValidVatNumber()); $this->assertInstanceOf(Rule::class, $process->rule); $this->assertEquals(0, $process->getVatRate()); $this->assertEquals(0, $process->getVatReducedRate()); } }