Skip to content

Commit

Permalink
Add additional service tests for packagist-dependency-version.tester.js
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulaBarszcz committed Sep 2, 2022
1 parent 55f50ce commit 623b442
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 5 deletions.
4 changes: 2 additions & 2 deletions services/packagist/packagist-dependency-version.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,9 @@ export default class PackagistDependencyVersion extends BasePackagistService {
const depRepoLowercase = dependencyRepo?.toLowerCase()

if (dependencyRepo || dependencyVendor) {
if (dependencyRepo & !dependencyVendor) {
if (!!dependencyRepo & !dependencyVendor) {
dependencyIdentifier = depRepoLowercase
} else if (!dependencyRepo & dependencyVendor) {
} else if (!dependencyRepo & !!dependencyVendor) {
dependencyIdentifier = depVendLowercase
} else {
dependencyIdentifier = `${depVendLowercase}/${depRepoLowercase}`
Expand Down
61 changes: 59 additions & 2 deletions services/packagist/packagist-dependency-version.tester.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,71 @@ import { isComposerVersion } from '../test-validators.js'
import { createServiceTester } from '../tester.js'
export const t = await createServiceTester()

t.create('gets the package version of symfony')
t.create('gets the package version of symfony 5.2.3 - without query params')
.get('/symfony/symfony/v5.2.3.json')
.expectBadge({
label: 'dependency version',
message: 'dependency vendor or repo not specified',
})

t.create(
'gets the package version of symfony - with correct dependencyVendor and dependencyRepo'
)
.get('/symfony/symfony.json?dependencyVendor=twig&dependencyRepo=twig')
.expectBadge({ label: 'twig/twig', message: isComposerVersion })

t.create('gets the package version of symfony 5.2.3')
t.create(
'gets the package version of symfony 5.2.3 - with correct dependencyVendor and dependencyRepo'
)
.get('/symfony/symfony/v5.2.3.json?dependencyVendor=twig&dependencyRepo=twig')
.expectBadge({ label: 'twig/twig', message: isComposerVersion })

t.create(
'gets the package version of symfony 5.2.3 - with incorrect dependencyVendor'
)
.get(
'/symfony/symfony/v5.2.3.json?dependencyVendor=twiiiiiiiiiig&dependencyRepo=twig'
)
.expectBadge({
label: 'dependency version',
message: 'version requirement not found',
})

t.create(
'gets the package version of symfony 5.2.3 - name of the dependencyVendor contains hyphen'
)
.get('/symfony/symfony/v5.2.3.json?dependencyVendor=ext-xml')
.expectBadge({ label: 'ext-xml', message: isComposerVersion })

t.create(
'gets the package version of symfony 5.2.3 - incorrectly with missing dependencyVendor (twig/twig needs both dependencyVendor and dependencyRepo)'
)
.get('/symfony/symfony/v5.2.3.json?dependencyRepo=twig')
.expectBadge({
label: 'dependency version',
message: 'version requirement not found',
})

t.create(
'gets the package version of symfony 5.2.3 - correctly with missing dependencyVendor (php needs only dependencyVendor or dependencyRepo)'
)
.get('/symfony/symfony/v5.2.3.json?dependencyRepo=php')
.expectBadge({ label: 'php', message: isComposerVersion })

t.create(
'gets the package version of symfony 5.2.3 - correctly when the dependencyVendor is the same as the name of the package'
)
.get(
'/symfony/symfony/v5.2.3.json?dependencyVendor=symfony&dependencyRepo=contracts'
)
.expectBadge({ label: 'symfony/contracts', message: isComposerVersion })

t.create(
'gets the package version of symfony 5.2.3 - correctly with missing dependencyRepo (php needs only dependencyVendor or dependencyRepo)'
)
.get('/symfony/symfony/v5.2.3.json?dependencyVendor=php')
.expectBadge({ label: 'php', message: isComposerVersion })

t.create('package with no requirements')
.get('/bpampuch/pdfmake.json?dependencyVendor=twig&dependencyRepo=twig')
.expectBadge({
Expand Down
2 changes: 1 addition & 1 deletion services/test-validators.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const isVPlusDottedVersionNClausesWithOptionalSuffixAndEpoch = withRegex(
// https://getcomposer.org/doc/04-schema.md#package-links
// https://getcomposer.org/doc/04-schema.md#minimum-stability
const isComposerVersion = withRegex(
/^\s*(>=|>|<|<=|!=|\^|~)?\d+(\.(\*|(\d+(\.(\d+|\*))?)))?((\s*\|*)?\s*(>=|>|<|<=|!=|\^|~)?\d+(\.(\*|(\d+(\.(\d+|\*))?)))?)*\s*$/
/^\*|(\s*(>=|>|<|<=|!=|\^|~)?\d+(\.(\*|(\d+(\.(\d+|\*))?)))?((\s*\|*)?\s*(>=|>|<|<=|!=|\^|~)?\d+(\.(\*|(\d+(\.(\d+|\*))?)))?)*\s*)$/
)

// Regex for validate php-version.versionReduction()
Expand Down

0 comments on commit 623b442

Please sign in to comment.