Skip to content

Commit

Permalink
Add and make tests for ebay
Browse files Browse the repository at this point in the history
  • Loading branch information
Claudio-Emmolo committed Aug 30, 2023
1 parent fd20ce1 commit 4e594d6
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/ReferralRewriterTag.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public function rewrite(string $link, ?string $tag, ?string $subtag, ?string $ad
return match ($this->retrieveTheDomainType()) {
'amazon' => $this->rewriteAmazonLink(),
'instant-gaming' => $this->rewriteInstantGamingLink(),
'ebay' => $this->rewriteEbayLink(),
default => $this->link,
};
}
Expand All @@ -43,6 +44,15 @@ public function rewriteInstantGamingLink() : string
return $this->rewriteLink(tagKey: 'igr', subTagKey: 'igr_extra');
}

/**
* Rewrite ebay link with tag and subtag
*/
public function rewriteEbayLink() : string
{
return $this->rewriteLink(tagKey: 'campid', subTagKey: 'customid');
}


/**
* Retrieve the domain type
*/
Expand Down
71 changes: 71 additions & 0 deletions tests/EbayRewriterTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?php

use The3LabsTeam\ReferralRewriterTag\Facades\ReferralRewriterTag;

it('can write ebay link with tag', function () {
$link = 'https://www.ebay.it/itm/172031349215';
$tag = 'mytag-20';

$rewrittenLink = ReferralRewriterTag::rewrite($link, $tag, null);
expect($rewrittenLink)->toBe('https://www.ebay.it/itm/172031349215?campid=mytag-20');
});

it('can write ebay link with tag and subtag', function () {
$link = 'https://www.ebay.it/itm/172031349215';
$tag = 'mytag-20';
$subtag = 'customsub';

$rewrittenLink = ReferralRewriterTag::rewrite($link, $tag, $subtag);
expect($rewrittenLink)->toBe('https://www.ebay.it/itm/172031349215?campid=mytag-20&customid=customsub');
});

it('can write ebay link with tag, subtag and additional query', function () {
$link = 'https://www.ebay.it/itm/172031349215';
$tag = 'mytag-20';
$subtag = 'customsub';
$additionalQuery = '&addquery=myogi';

$rewrittenLink = ReferralRewriterTag::rewrite($link, $tag, $subtag, $additionalQuery);
expect($rewrittenLink)->toBe('https://www.ebay.it/itm/172031349215?campid=mytag-20&customid=customsub&addquery=myogi');
});

it('can rewrite ebay link with tag', function () {
$link = 'https://www.ebay.it/itm/172031349215?campid=5337692837&customid=11994';
$tag = 'mytag-20';

$rewrittenLink = ReferralRewriterTag::rewrite($link, $tag, null);
expect($rewrittenLink)->toBe('https://www.ebay.it/itm/172031349215?campid=mytag-20&customid=11994');
});

it('can rewrite ebay link with subtag', function () {
$link = 'https://www.ebay.it/itm/172031349215?campid=5337692837&customid=11994';
$subtag = 'customsub';

$rewrittenLink = ReferralRewriterTag::rewrite($link, null, $subtag);
expect($rewrittenLink)->toBe('https://www.ebay.it/itm/172031349215?campid=5337692837&customid=customsub');
});

it('can rewrite ebay link with tag and subtag', function () {
$link = 'https://www.ebay.it/itm/172031349215?campid=5337692837&customid=11994';
$tag = 'mytag-20';
$subtag = 'customsub';

$rewrittenLink = ReferralRewriterTag::rewrite($link, $tag, $subtag);
expect($rewrittenLink)->toBe('https://www.ebay.it/itm/172031349215?campid=mytag-20&customid=customsub');
});

it('can rewrite full ebay link with tag ans subtag', function () {
$link = 'https://www.ebay.it/itm/172031349215?mkevt=1&mkcid=1&mkrid=724-53478-19255-0&campid=5337692837&customid=11994&toolid=10050';
$tag = 'mytag-20';
$subtag = 'customsub';

$rewrittenLink = ReferralRewriterTag::rewrite($link, $tag, $subtag);
expect($rewrittenLink)->toBe('https://www.ebay.it/itm/172031349215?mkevt=1&mkcid=1&mkrid=724-53478-19255-0&campid=mytag-20&customid=customsub&toolid=10050');
});

it('can rewrite ebay link without tag and subtag', function () {
$link = 'https://www.ebay.it/itm/172031349215?campid=5337692837&customid=11994';

$rewrittenLink = ReferralRewriterTag::rewrite($link, null, null);
expect($rewrittenLink)->toBe('https://www.ebay.it/itm/172031349215?campid=5337692837&customid=11994');
});

0 comments on commit 4e594d6

Please sign in to comment.