Skip to content

Commit

Permalink
UHF-10581: test errors
Browse files Browse the repository at this point in the history
  • Loading branch information
rpnykanen committed Oct 7, 2024
1 parent e6fe136 commit 2f0d1d9
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,14 @@

use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Routing\UrlGeneratorInterface;
use Drupal\helfi_google_api\GoogleApi;
use Drupal\helfi_google_api\JobIndexingService;
use Drupal\helfi_google_api\Response;
use Drupal\path_alias\AliasManagerInterface;
use Drupal\redirect\Entity\Redirect;
use Drupal\Tests\helfi_api_base\Functional\ExistingSiteTestBase;
use Google\Service\Indexing;
use Prophecy\Argument;
use Prophecy\PhpUnit\ProphecyTrait;

/**
Expand Down Expand Up @@ -57,6 +61,29 @@ public function testIndexingJoblisting(): void {
$this->assertTrue(str_contains($indexed_url, $expected));
}

public function testIndexingErrors() {
$random = rand(1000, 9999);
$recruitmentId = "TESTI-1234-56-$random";
$timestamp = time() - 1;

$node = $this->createNode([
'type' => 'job_listing',
'langcode' => 'sv',
'title' => 'en jobb',
'field_recruitment_id' => $recruitmentId,
'publish_on' => $timestamp,
]);

/** @var \Drupal\helfi_google_api\JobIndexingService $indexingService */
$indexingService = $this->getSut('errors');

/** @var \Drupal\helfi_google_api\Response $response */
$response = $indexingService->indexEntity($node);

$this->assertCount(1, $response->getErrors());
$this->assertCount(1, $response->getUrls());
}

/**
* Test deindexing.
*/
Expand Down Expand Up @@ -109,8 +136,27 @@ public function testDeindexing(): void {
* @return \Drupal\helfi_google_api\JobIndexingService
* The job indexing service.
*/
private function getSut(): JobIndexingService {
$googleApi = $this->container->get('Drupal\helfi_google_api\GoogleApi');
private function getSut($errors = ''): JobIndexingService {
if ($errors === 'errors') {
$googleApi = $this->prophesize(GoogleApi::class);
$googleApi->isDryRun()
->willReturn(TRUE);

$response = new Response(
['https://test.fi/url'],
['Unable to verify url ownership'],
TRUE
);
$googleApi->indexBatch(Argument::any(), Argument::any())
->willReturn($response);
$googleApi = $googleApi->reveal();
}
else {
$googleApi = new GoogleApi(
$this->container->get('config.factory'),
$this->prophesize(Indexing::class)->reveal()
);
}
$entityTypeManager = $this->container->get(EntityTypeManagerInterface::class);
$aliasManager = $this->container->get(AliasManagerInterface::class);
$urlGenerator = $this->container->get(UrlGeneratorInterface::class);
Expand Down
Empty file.

0 comments on commit 2f0d1d9

Please sign in to comment.